Skip to content

Commit 7d83efd

Browse files
committed
resolution -> size
1 parent 95aa687 commit 7d83efd

File tree

5 files changed

+14
-25
lines changed

5 files changed

+14
-25
lines changed

docs/builtin-tools.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,14 +353,14 @@ assert isinstance(result.output, BinaryImage)
353353

354354
_(This example is complete, it can be run "as is")_
355355

356-
To control the image resolution with Gemini 3 Pro Image models, use the `resolution` parameter:
356+
To control the image resolution with Gemini Image models starting with `gemini-3-pro-image-preview`, use the `size` parameter:
357357

358358
```py {title="image_generation_google_resolution.py"}
359359
from pydantic_ai import Agent, BinaryImage, ImageGenerationTool
360360

361361
agent = Agent(
362362
'google-gla:gemini-3-pro-image-preview',
363-
builtin_tools=[ImageGenerationTool(aspect_ratio='16:9', resolution='4K')],
363+
builtin_tools=[ImageGenerationTool(aspect_ratio='16:9', size='4K')],
364364
output_type=BinaryImage,
365365
)
366366

@@ -383,9 +383,8 @@ For more details, check the [API documentation][pydantic_ai.builtin_tools.ImageG
383383
| `output_format` |||
384384
| `partial_images` |||
385385
| `quality` |||
386-
| `size` |||
387-
| `aspect_ratio` | ✅ (1:1, 2:3, 3:2) ||
388-
| `resolution` || ✅ (1K, 2K, 4K) |
386+
| `size` | ✅ (1024x1024, 1024x1536, 1536x1024, auto) | ✅ (1K, 2K, 4K) |
387+
| `aspect_ratio` | ✅ (1:1, 2:3, 3:2) | ✅ (1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9) |
389388

390389
## Web Fetch Tool
391390

pydantic_ai_slim/pydantic_ai/builtin_tools.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,13 @@ class ImageGenerationTool(AbstractBuiltinTool):
311311
* OpenAI Responses
312312
"""
313313

314-
size: Literal['1024x1024', '1024x1536', '1536x1024', 'auto'] = 'auto'
314+
size: Literal['1024x1024', '1024x1536', '1536x1024', '1K', '2K', '4K', 'auto'] = 'auto'
315315
"""The size of the generated image.
316316
317317
Supported by:
318318
319-
* OpenAI Responses
319+
* OpenAI Responses: '1024x1024', '1024x1536', '1536x1024', 'auto'
320+
* Google (Gemini 3 Pro Image and later): '1K', '2K', '4K'
320321
"""
321322

322323
aspect_ratio: ImageAspectRatio | None = None
@@ -328,14 +329,6 @@ class ImageGenerationTool(AbstractBuiltinTool):
328329
* OpenAI Responses (maps '1:1', '2:3', and '3:2' to supported sizes)
329330
"""
330331

331-
resolution: str | None = None
332-
"""The resolution/size tier for generated images.
333-
334-
Supported by:
335-
336-
* Google: '1K', '2K', '4K' for Gemini 3 Pro Image and compatible models
337-
"""
338-
339332
kind: str = 'image_generation'
340333
"""The kind of tool."""
341334

pydantic_ai_slim/pydantic_ai/models/google.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -362,14 +362,12 @@ def _get_tools(
362362
raise UserError(
363363
"`ImageGenerationTool` is not supported by this model. Use a model with 'image' in the name instead."
364364
)
365-
# Build image_config from tool parameters, only including non-None values
366-
image_config_kwargs: dict[str, Any] = {}
365+
366+
image_config = ImageConfigDict()
367367
if tool.aspect_ratio is not None:
368-
image_config_kwargs['aspect_ratio'] = tool.aspect_ratio
369-
if tool.resolution is not None:
370-
image_config_kwargs['image_size'] = tool.resolution
371-
if image_config_kwargs:
372-
image_config = ImageConfigDict(**image_config_kwargs)
368+
image_config['aspect_ratio'] = tool.aspect_ratio
369+
if tool.size in ('1K', '2K', '4K'):
370+
image_config['image_size'] = tool.size
373371
else: # pragma: no cover
374372
raise UserError(
375373
f'`{tool.__class__.__name__}` is not supported by `GoogleModel`. If it should be, please file an issue.'

tests/models/test_google.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3655,7 +3655,7 @@ async def test_google_image_generation_tool_aspect_ratio(google_provider: Google
36553655
async def test_google_image_generation_resolution(google_provider: GoogleProvider) -> None:
36563656
"""Test that resolution parameter from ImageGenerationTool is added to image_config."""
36573657
model = GoogleModel('gemini-3-pro-image-preview', provider=google_provider)
3658-
params = ModelRequestParameters(builtin_tools=[ImageGenerationTool(resolution='2K')])
3658+
params = ModelRequestParameters(builtin_tools=[ImageGenerationTool(size='2K')])
36593659

36603660
tools, image_config = model._get_tools(params) # pyright: ignore[reportPrivateUsage]
36613661
assert tools is None
@@ -3665,7 +3665,7 @@ async def test_google_image_generation_resolution(google_provider: GoogleProvide
36653665
async def test_google_image_generation_resolution_with_aspect_ratio(google_provider: GoogleProvider) -> None:
36663666
"""Test that resolution and aspect_ratio from ImageGenerationTool work together."""
36673667
model = GoogleModel('gemini-3-pro-image-preview', provider=google_provider)
3668-
params = ModelRequestParameters(builtin_tools=[ImageGenerationTool(aspect_ratio='16:9', resolution='4K')])
3668+
params = ModelRequestParameters(builtin_tools=[ImageGenerationTool(aspect_ratio='16:9', size='4K')])
36693669

36703670
tools, image_config = model._get_tools(params) # pyright: ignore[reportPrivateUsage]
36713671
assert tools is None

tests/models/test_model_request_parameters.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ def test_model_request_parameters_are_serializable():
9999
'quality': 'auto',
100100
'size': '1024x1024',
101101
'aspect_ratio': None,
102-
'resolution': None,
103102
},
104103
{'kind': 'memory'},
105104
{

0 commit comments

Comments
 (0)