PDF Input File Upload

Attach a local PDF file to an OpenAI chat agent and ask it to suggest a recipe from the document.

Pass a local PDF as base64-inlined file input to an OpenAI Chat agent.

The source docstring incorrectly refers to Google GenAI. OpenAIChat base64-inlines the local file path; it does not upload a large file automatically.

pdf_input_file_upload.py
"""
In this example, we upload a PDF file to Google GenAI directly and then use it as an input to an agent.
"""

from pathlib import Path

from agno.agent import Agent
from agno.media import File
from agno.models.openai import OpenAIChat

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------

pdf_path = Path(__file__).parent.joinpath("ThaiRecipes.pdf")

# Pass the local PDF file path directly; the client will inline small files or upload large files automatically
agent = Agent(
    model=OpenAIChat(id="gpt-5.6-luna"),
    markdown=True,
    add_history_to_context=True,
)

agent.print_response(
    "Suggest me a recipe from the attached file.",
    files=[File(filepath=str(pdf_path))],
)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    pass

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno openai

Export your OpenAI API key

export OPENAI_API_KEY="your_openai_api_key_here"

Download the sample PDF

Download ThaiRecipes.pdf next to the saved script:

python -c "from urllib.request import urlretrieve; urlretrieve('https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf', 'ThaiRecipes.pdf')"

Run the example

Save the code above as pdf_input_file_upload.py, then run:

python pdf_input_file_upload.py

Full source: cookbook/90_models/openai/chat/pdf_input_file_upload.py