Skip to content

Add OpenAI gpt-image-2 image generation support - #114

Merged
adambalogh merged 1 commit into
mainfrom
claude/openai-gpt-image-2-studio-sos6yq
Jun 30, 2026
Merged

adambalogh merged 1 commit into
mainfrom
claude/openai-gpt-image-2-studio-sos6yq

Conversation

@adambalogh

Copy link
Copy Markdown
Contributor

Summary

Adds support for OpenAI's gpt-image-2 model for image generation via the /images/generations endpoint, alongside existing providers (xAI, ByteDance, Z.ai).

Changes

  • model_registry.py: Register GPT_IMAGE_2 model config with:

    • Flat per-image pricing at $0.05 (token prices unused)
    • Pinned size (1024x1024) and quality (medium) for predictable billing
    • response_format omitted (gpt-image always returns base64)
    • Routed through OpenAI's shared HTTP client (base_url ends in /v1)
  • image_generation.py:

    • Add "openai": "openai_http_client" to _IMAGE_CLIENT_ATTRS mapping
    • Update module docstring to include OpenAI as an image generation provider
  • test_image_generation.py:

    • Add GPT_IMAGE = "gpt-image-2" constant
    • Add test_openai_gpt_image_omits_response_format_and_pins_size_quality() test verifying:
      • response_format field is omitted from request payload
      • Size and quality are pinned as configured
      • Base64 response (b64_json) is correctly converted to inline data: URI
      • Shared OpenAI HTTP client is reused
    • Include GPT_IMAGE in billing test coverage
  • CLAUDE.md: Update documentation to list gpt-image-2 under OpenAI's supported models and note it uses the /images/generations endpoint flow

Implementation Details

The gpt-image model integrates seamlessly with the existing endpoint-based image generation flow. Unlike DALL·E (which uses the chat path), gpt-image is served through a dedicated /images/generations endpoint and always returns base64-encoded images, rejecting the response_format parameter. The implementation pins size and quality to ensure predictable per-image billing costs.

https://claude.ai/code/session_01Soor3BDk2mqheoiWFssi9N

Expose OpenAI's gpt-image-2 model through the endpoint-based image
generation flow so it can be surfaced in the image studio.

- Register GPT_IMAGE_2 in model_registry with image_generation=True and a
  flat per-image price. gpt-image models always return base64 and reject
  the response_format field, so it's omitted; size/quality are pinned for
  predictable billing. Image-to-image editing uses a separate OpenAI
  endpoint, so reference images aren't forwarded (text-to-image only).
- Map the "openai" provider to the existing openai_http_client in
  image_generation, reusing the chat client (base URL ends in /v1, so the
  request lands on OpenAI's /v1/images/generations).
- Add tests for the OpenAI payload shape and per-image billing.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Soor3BDk2mqheoiWFssi9N
@adambalogh
adambalogh marked this pull request as ready for review June 30, 2026 15:52
@adambalogh
adambalogh merged commit 7b053ff into main Jun 30, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants