From a1787d70fd29832616c70fd281e122e30ef96248 Mon Sep 17 00:00:00 2001 From: marmor7 Date: Thu, 20 Nov 2025 17:11:02 +0200 Subject: [PATCH 1/3] Update Google GLA file docs + example code - Added example code for file uploads and inline usage with Gemini GLA. - Clarified Google GLA file upload option --- docs/input.md | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/docs/input.md b/docs/input.md index e662c35832..5c2e634e66 100644 --- a/docs/input.md +++ b/docs/input.md @@ -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) (by prefix matching on `https://generativelanguage.googleapis.com/v1beta/files`) + - [`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: @@ -120,4 +124,28 @@ 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 + +Upload a file via Files API: + +```py {title="file_upload.py" test="skip" lint="skip"} +from google import genai +from pydantic_ai.messages import BinaryContent, DocumentUrl +from io import BytesIO + +client = genai.Client(api_key=API_KEY) +uploaded_file = client.files.upload(file=BytesIO(file_bytes), config={"mime_type": mimetype}) +user_prompt = ["Show me the money!", DocumentUrl(url=uploaded_file.uri, media_type=mimetype)] +await agent.run(user_prompt) +``` + +Inline a file as a text part: + +```py {title="file_inline.py" test="skip" lint="skip"} +from google import genai +from pydantic_ai.messages import BinaryContent, DocumentUrl + +client = genai.Client(api_key=API_KEY) +user_prompt = ["This seemed important at 3am", BinaryContent(data=file_bytes, media_type=mimetype)] +await agent.run(user_prompt) +``` From fd2d525b393446b23c3d1d815e8b2256f34c73c7 Mon Sep 17 00:00:00 2001 From: Mor Gazith Date: Sun, 23 Nov 2025 11:55:30 +0200 Subject: [PATCH 2/3] make the two code samples complete - they can be run as-is now --- docs/input.md | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/docs/input.md b/docs/input.md index 5c2e634e66..f73ea364ea 100644 --- a/docs/input.md +++ b/docs/input.md @@ -130,22 +130,26 @@ Upload a file via Files API: ```py {title="file_upload.py" test="skip" lint="skip"} from google import genai -from pydantic_ai.messages import BinaryContent, DocumentUrl -from io import BytesIO +from pydantic_ai import Agent, DocumentUrl + +client = genai.Client() +file = client.files.upload(file='path/to/document.pdf') -client = genai.Client(api_key=API_KEY) -uploaded_file = client.files.upload(file=BytesIO(file_bytes), config={"mime_type": mimetype}) -user_prompt = ["Show me the money!", DocumentUrl(url=uploaded_file.uri, media_type=mimetype)] -await agent.run(user_prompt) +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 google import genai -from pydantic_ai.messages import BinaryContent, DocumentUrl +from pydantic_ai import Agent +from pydantic_ai.messages import BinaryContent + +file_bytes = b'PDF content here...' +mimetype = 'application/pdf' -client = genai.Client(api_key=API_KEY) -user_prompt = ["This seemed important at 3am", BinaryContent(data=file_bytes, media_type=mimetype)] -await agent.run(user_prompt) +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) ``` From cac50574c248f867045ec8319fb8616b2d0fbf73 Mon Sep 17 00:00:00 2001 From: Mor Gazith Date: Sun, 23 Nov 2025 12:00:50 +0200 Subject: [PATCH 3/3] made file_bytes self-explanatory --- docs/input.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/input.md b/docs/input.md index f73ea364ea..2e658bd176 100644 --- a/docs/input.md +++ b/docs/input.md @@ -146,7 +146,7 @@ Inline a file as a text part: from pydantic_ai import Agent from pydantic_ai.messages import BinaryContent -file_bytes = b'PDF content here...' +file_bytes = Path('path/to/document.pdf').read_bytes() mimetype = 'application/pdf' agent = Agent(model='google-gla:gemini-2.5-flash')