Repository navigation
feat(aiml): add openai/gpt-image-2 image model - #31323
5 commits merged into
Conversation
Adds aiml/openai/gpt-image-2 to the cost map and teaches AimlImageGenerationConfig to route OpenAI-style image models through the upstream OpenAI request schema instead of the AI/ML flux schema. Without this, size, n, and response_format would be remapped to image_size/num_images/output_format, which the gpt-image-2 endpoint on api.aimlapi.com does not accept. Co-authored-by: Mateo Wang <mateo-berri@users.noreply.github.com>
|
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Greptile SummaryAdds
Confidence Score: 5/5Safe to merge — the change is isolated to a single provider's transformation layer and adds a new model entry without modifying any shared infrastructure. The transformation refactor is backward-compatible: the flux-style remapping path is functionally identical to what it replaced, and the new OpenAI-style pass-through path is covered by both unit and integration-level mock tests. The cost map entries are consistent with the rest of the aiml image catalog and both JSON files are kept in sync. No shared or critical-path code is touched. No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/llms/aiml/image_generation/transformation.py | Adds OpenAI-style model branch to AimlImageGenerationConfig: new _is_openai_style_model prefix check routes openai/* models to pass-through serialization while flux-style models keep their existing remapping; logic is correct and backward-compatible. |
| model_prices_and_context_window.json | Adds aiml/openai/gpt-image-2 entry with mode: image_generation, output_cost_per_image: 0.054, and a notes field documenting the medium-quality flat-rate caveat; mirrors the backup file correctly. |
| litellm/model_prices_and_context_window_backup.json | Identical entry to model_prices_and_context_window.json — both files kept in sync as expected. |
| tests/test_litellm/llms/aiml/image_generation/test_aiml_image_generation_transformation.py | New unit test file covering OpenAI-style param surface, flux-style remapping, drop-params behavior, and per-image cost lookup; uses local cost map, no network calls. |
| tests/image_gen_tests/test_image_generation.py | Adds end-to-end mock test for aiml/openai/gpt-image-2 that patches HTTPHandler.post and verifies the upstream request body retains the OpenAI param shape and correct model name. |
Reviews (4): Last reviewed commit: "style(aiml): format transformation.py at..." | Re-trigger Greptile
…itellm_aiml-gpt-image-2-5b10
Documents in the cost-map notes that output_cost_per_image is AI/ML's published medium-quality rate, billed as a flat per-image price like the other aiml image entries. Reformats the touched files under the repo's ruff formatter (migrated from black in #31317).
|
Generated by Claude Code |
LiteLLM only implements an image generation transformer for AIML, so listing /v1/images/edits overclaimed support. Align with every other aiml image entry, which lists only /v1/images/generations.
|
Good catch on Generated by Claude Code |
The repo formats litellm/ with ruff at line-length 88 (Makefile/CI call sites), while ruff.toml's global 120 only governs E501/import sorting. Reformat the transformer to 88 so make format-check / CI lint pass, and restore the test files to their original layout since tests/ is not part of the auto-formatted tree.
|
Generated by Claude Code |
|
bugbot run Generated by Claude Code |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 1694f94. Configure here.
Relevant issues
Linear ticket
Resolves LIT-3777
Pre-Submission checklist
make test-unit(for the new + adjacent AIML image-gen suites)@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewType
New Feature
Changes
Adds the
aiml/openai/gpt-image-2model and fixes the AI/ML API image generation transformer so OpenAI-style image models go through the correct upstream schema.Two things were needed to make
aiml/openai/gpt-image-2work end to end:A cost-map entry (
aiml/openai/gpt-image-2) withmode=image_generationsoget_model_inforesolves the model under the AI/ML provider and the existingaiml_image_cost_calculatorfinds anoutput_cost_per_image. The flat per-image rate of $0.054 matches the price AI/ML quotes in the public docs example for the default medium-quality 1536x1024 generation (https://docs.aimlapi.com/api-references/image-models/openai/gpt-image-2)A model-aware request transformation in
AimlImageGenerationConfig. The existing transformer was written for the flux/Imagen request schema and unconditionally remapsn -> num_images,size -> image_size{width, height}, and (incorrectly)response_format -> output_format. Theopenai/gpt-image-2endpoint onapi.aimlapi.cominstead expects the OpenAI shape (n,size: "1024x1024", separateresponse_formatforurl/b64_jsonandoutput_formatforpng/jpeg/webp). Models whose name starts withopenai/now pass their OpenAI-shaped params through unchanged; everything else keeps the existing flux-style remappingTests:
tests/test_litellm/llms/aiml/image_generation/test_aiml_image_generation_transformation.pycovers both branches of the new routing (param surface, request body, drop-params behavior) and locks in the$0.054per-image cost foraiml/openai/gpt-image-2tests/image_gen_tests/test_image_generation.py::test_aiml_openai_gpt_image_2_request_uses_openai_param_shapeis an end-to-end check throughlitellm.aimage_generationthat confirms the upstream POST body keepssize/n/response_format(and never growsimage_size/num_images/output_format) and that the model identifier sent to AI/ML isopenai/gpt-image-2Screenshots / Proof of Fix
To reproduce against a live proxy:
LITELLM_LOCAL_MODEL_COST_MAP=Trueis required until this PR merges. By default litellm pulls the cost map frommainon GitHub, which does not carry theaiml/openai/gpt-image-2entry yet, so the spend logs as$0.00; forcing the bundled local map lets the new$0.054rate resolveThis returns a
data[0].urlpointing atcdn.aimlapi.com/..., the upstream POST body toapi.aimlapi.comstays OpenAI-shaped ({"model": "openai/gpt-image-2", "n": 1, "quality": "medium", "size": "1536x1024"}, never growingnum_images/image_size/output_format), andlitellm.logrecords a spend entry of$0.054Linear Issue: LIT-3777