Image Input File Upload
Review the legacy uploaded-image recipe and run a current local-image alternative.
The source attempts to pass an uploaded file handle as image content. Use the local-image alternative below with current Agno.
Image(content=uploaded_file) requires bytes and cannot accept Anthropic file metadata. The source also uses a retired Opus 4 model. Run the current alternative below; it sends the local image by filepath and does not use the Files API.
"""
In this example, we upload a PDF file to Anthropic directly and then use it as an input to an agent.
"""
from pathlib import Path
from agno.agent import Agent
from agno.media import Image
from agno.models.anthropic import Claude
from agno.utils.media import download_file
from anthropic import Anthropic
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
img_path = Path(__file__).parent.joinpath("agno-intro.png")
# Download the file using the download_file function
download_file(
"https://agno-public.s3.us-east-1.amazonaws.com/images/agno-intro.png",
str(img_path),
)
# Initialize Anthropic client
client = Anthropic()
# Upload the file to Anthropic
uploaded_file = client.beta.files.upload(
file=Path(img_path),
)
if uploaded_file is not None:
agent = Agent(
model=Claude(
id="claude-opus-4-20250514",
betas=["files-api-2025-04-14"],
),
markdown=True,
)
agent.print_response(
"What does the attached image say.",
images=[Image(content=uploaded_file)],
)
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
passCurrent Alternative
from pathlib import Path
from agno.agent import Agent
from agno.media import Image
from agno.models.anthropic import Claude
from agno.utils.media import download_file
image_path = Path(__file__).parent / "agno-intro.png"
download_file(
"https://agno-public.s3.us-east-1.amazonaws.com/images/agno-intro.png",
str(image_path),
)
agent = Agent(model=Claude(id="claude-sonnet-4-6"), markdown=True)
agent.print_response("What does the attached image say?", images=[Image(filepath=image_path)])Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno anthropicExport your Anthropic API key
export ANTHROPIC_API_KEY="your_anthropic_api_key_here"Run the example
Save the current alternative as image_local_current.py, then run:
python image_local_current.pyFull source: cookbook/90_models/anthropic/image_input_file_upload.py