feat(openai): support gpt-image-2 options

Merged
BA
25d ago
+176-20

Context

Issue #5190 asks for gpt-image-2 support. A maintainer noted that using Agent('openai:gpt-image-2') routes through the LLM/completions path, which is incompatible with image-only models and would need a separate adapter/profile for the image generation endpoint.

Issue #3898 covers the broader question of direct image/video generation model support. The maintainer guidance there is not to shoehorn non-LLM media models into Agent/Model; direct media generation likely wants dedicated types.

This PR therefore keeps the scope narrow: it does not make Agent('openai:gpt-image-2') a direct image model. Instead, it completes the existing OpenAI Responses ImageGenerationTool surface so an OpenAI Responses conversational model can invoke an image generation model via the built-in image_generation tool.

ImageGenerationTool.model now exposes known OpenAI image generation model names (gpt-image-2, gpt-image-1.5, gpt-image-1, and gpt-image-1-mini) while preserving a str escape hatch for future OpenAI image model IDs. The gpt-image-2 entry in _IMAGE_ONLY_MODELS is only used to reject image-only models as fallback_model values with a clearer suggestion; it is separate from the tool's model field.

Summary

  • Add action and model options to ImageGenerationTool for OpenAI Responses image generation.
  • Type ImageGenerationTool.model and ImageGeneration.model with known OpenAI image generation model names while still accepting arbitrary string model IDs.
  • Forward those options when building the OpenAI Responses image_generation tool payload.
  • Mirror the new options through the provider-adaptive ImageGeneration capability.
  • Update docs, provider support tables, schema snapshots, and serialization snapshots.

Test plan

  • uv run pytest tests/test_capabilities.py
  • uv run pytest tests/models/test_google.py tests/models/test_model_request_parameters.py -k image_generation
  • uv run pytest tests/models/test_openai_responses.py -k image_generation
  • uv run pytest tests/models/test_model_request_parameters.py::test_model_request_parameters_are_serializable
  • uv run pytest tests/test_capabilities.py::test_model_json_schema_with_capabilities tests/models/test_model_request_parameters.py::test_model_request_parameters_are_serializable tests/models/test_openai_responses.py::test_openai_responses_image_generation_tool_options
  • uv run pytest tests/models/test_model_request_parameters.py tests/test_capabilities.py tests/models/test_openai_responses.py -k 'model_request_parameters_are_serializable or image_generation'
  • uv run ruff check pydantic_ai_slim/pydantic_ai/builtin_tools/__init__.py pydantic_ai_slim/pydantic_ai/capabilities/image_generation.py pydantic_ai_slim/pydantic_ai/models/openai.py pydantic_ai_slim/pydantic_ai/common_tools/image_generation.py tests/models/test_openai_responses.py tests/test_capabilities.py tests/models/test_model_request_parameters.py
  • uv run ruff format --check pydantic_ai_slim/pydantic_ai/builtin_tools/__init__.py pydantic_ai_slim/pydantic_ai/capabilities/image_generation.py pydantic_ai_slim/pydantic_ai/models/openai.py pydantic_ai_slim/pydantic_ai/common_tools/image_generation.py tests/models/test_openai_responses.py tests/test_capabilities.py tests/models/test_model_request_parameters.py
  • git diff --check

Checklist

  • Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
  • No breaking changes in accordance with the version policy.
  • PR title is fit for the release changelog.