Skip to content
Merged
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion docs/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ The situation is different for certain models:

- [`AnthropicModel`][pydantic_ai.models.anthropic.AnthropicModel]: if you provide a PDF document via `DocumentUrl`, the URL is sent directly in the API request, so no download happens on the user side.

- [`GoogleModel`][pydantic_ai.models.google.GoogleModel] on GLA:
- YouTube video URLs are sent directly in the request to the model.
- Files uploaded to the [Files API](https://ai.google.dev/gemini-api/docs/files) can be passed by wrapping their url with DocumentUrl.

- [`GoogleModel`][pydantic_ai.models.google.GoogleModel] on Vertex AI: any URL provided using `ImageUrl`, `AudioUrl`, `VideoUrl`, or `DocumentUrl` is sent as-is in the API request and no data is downloaded beforehand.

See the [Gemini API docs for Vertex AI](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#filedata) to learn more about supported URLs, formats and limitations:
Expand All @@ -120,4 +124,38 @@ The situation is different for certain models:

However, because of crawling restrictions, it may happen that Gemini can't access certain URLs. In that case, you can instruct Pydantic AI to download the file content and send that instead of the URL by setting the boolean flag `force_download` to `True`. This attribute is available on all objects that inherit from [`FileUrl`][pydantic_ai.messages.FileUrl].

- [`GoogleModel`][pydantic_ai.models.google.GoogleModel] on GLA: YouTube video URLs are sent directly in the request to the model.
## Example code for Gemini GLA

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still needs updating the title to sth like "Uploaded files"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought you meant the header one line below which now reads "Use uploaded files" as you suggested.
for the header above "Example code for Gemini GLA", it doesn't make sense to change to "Uploaded files" as i'm providing two separate code examples, one for uploaded files and one for inlined files.

Use uploaded files:

```py {title="file_upload.py" test="skip" lint="skip"}
from pydantic_ai import Agent, DocumentUrl
from pydantic_ai.providers.google import GoogleProvider

provider = GoogleProvider(api_key=GEMINI_API_KEY)
file = provider.client.files.upload(file='path/to/document.pdf')
assert file.uri is not None

agent = Agent(model='google-gla:gemini-2.5-flash')
result = agent.run_sync(
[
'What does this document contain?',
DocumentUrl(url=file.uri, media_type=file.mime_type),
]
)
print(result.output)
```

Inline a file as a text part:

```py {title="file_inline.py" test="skip" lint="skip"}
from pathlib import Path
from pydantic_ai import Agent, BinaryContent

file_bytes = Path('path/to/document.pdf').read_bytes()
mimetype = 'application/pdf'

agent = Agent(model='google-gla:gemini-2.5-flash')
result = agent.run_sync(['What does this document contain?', BinaryContent(data=file_bytes, media_type=mimetype)])
print(result.output)
```