Skip to content

feat: add POST /v1/images/generations endpoint#43

Open
tbille wants to merge 1 commit intomainfrom
feat/image-generation-endpoint
Open

feat: add POST /v1/images/generations endpoint#43
tbille wants to merge 1 commit intomainfrom
feat/image-generation-endpoint

Conversation

@tbille
Copy link
Copy Markdown
Contributor

@tbille tbille commented Apr 14, 2026

Summary

  • Add OpenAI-compatible image generation endpoint (POST /v1/images/generations) to the gateway
  • Proxies requests through any_llm's aimage_generation() function to any OpenAI-compatible provider
  • Includes full auth, rate limiting, budget validation, usage logging, and cost tracking

Details

New route: src/gateway/api/routes/images.py

  • ImageGenerationRequest pydantic model with fields: model, prompt, n, size, quality, style, response_format, user
  • Standard gateway flow: auth → resolve user → rate limit → budget check → split provider/model → proxy call → log usage → return response
  • Cost tracking: repurposes input_price_per_million from pricing table as price-per-image (tokens set to 0)
  • Registered in non-platform mode in api/main.py

Tests: tests/integration/test_images_endpoint.py — 12 tests:

  • Auth required (401)
  • API key auth works (200)
  • Master key requires user field (400)
  • Master key + user field works (200)
  • Provider error returns 500
  • Usage logging on success
  • Error logging on failure
  • Optional fields forwarded (n, size, quality, style)
  • Cost tracking with pricing

Dependencies: Requires mozilla-ai/any-llm#1035 for aimage_generation() support in the SDK.

Add OpenAI-compatible image generation endpoint to the gateway,
proxying requests through any_llm's new aimage_generation() function.

- New route at POST /v1/images/generations with full auth, rate limiting,
  budget validation, and usage logging
- Cost tracking repurposes input_price_per_million as price-per-image
- Tokens set to 0 for image requests (no token-based usage)
- Registered in non-platform mode alongside other proxy endpoints
- 12 integration tests covering auth, usage logging, error handling,
  optional fields, and cost tracking
- OpenAPI spec regenerated

Depends on: mozilla-ai/any-llm#1035
@tbille tbille had a problem deploying to integration-tests April 14, 2026 19:43 — with GitHub Actions Failure
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.

1 participant