Skip to content

provider: add image generation support for OpenRouter#1722

Open
Robinnnnn wants to merge 1 commit into
Portkey-AI:mainfrom
Robinnnnn:openrouter-image-generation
Open

provider: add image generation support for OpenRouter#1722
Robinnnnn wants to merge 1 commit into
Portkey-AI:mainfrom
Robinnnnn:openrouter-image-generation

Conversation

@Robinnnnn

Copy link
Copy Markdown

Description: (required)

  • Adds imageGenerate support to the OpenRouter provider, wiring it to OpenRouter's dedicated image generation endpoint (POST https://openrouter.ai/api/v1/images), which is OpenAI-Images-compatible.
  • src/providers/openrouter/api.ts: route imageGenerate to /v1/images (resolves to https://openrouter.ai/api/v1/images).
  • src/providers/openrouter/imageGenerate.ts (new): request config mapping OpenAI Images params (prompt, model, n 1-10, size) plus OpenRouter-specific params (seed, aspect_ratio, resolution, input_references for image-to-image). response_format is intentionally not mapped — OpenRouter always returns base64 (b64_json) and ignores/strips unknown params. Response transform follows the OpenAI/Deepbricks pattern: pass through the already-OpenAI-shaped success body ({created, data: [{b64_json}], usage}), and normalize upstream errors via OpenAIErrorResponseTransform (OpenRouter errors are {error: {message, code}}).
  • src/providers/openrouter/index.ts: register the config and response transform.

Tests Run/Test cases added: (required)

  • Live end-to-end through a locally running gateway (tsx src/start-server.ts) with a real OpenRouter API key against google/gemini-2.5-flash-image:
    • POST /v1/images/generations with {model, prompt, n: 1} → 200, data[0].b64_json decodes to a valid PNG (checked magic bytes), usage passed through.
    • size: "1024x1024" passthrough → 200, valid PNG.
    • Error normalization: unknown model → 404 {"error":{"message":"openrouter error: No model found...","code":404},"provider":"openrouter"}; conflicting size + aspect_ratio → 400 with OpenRouter's message, both in the gateway's standard error shape.
  • tsc --noEmit (no new errors; two pre-existing errors in bytez/open-ai-base untouched), npm run build succeeds, prettier --check clean, npm run test:gateway results identical to main (47 passed; the 8 pre-existing suite failures on main are unchanged).

Type of Change:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)

@Robinnnnn

Copy link
Copy Markdown
Author

@VisargD @narengogi @b4s36t4 would appreciate a review! 🙏

This adds imageGenerate support to the OpenRouter provider, routed to OpenRouter's dedicated OpenAI-Images-compatible endpoint (POST /api/v1/images). It follows the existing OpenAI/Deepbricks pattern: map the OpenAI Images params (plus OpenRouter extras seed/aspect_ratio/resolution/input_references) and normalize upstream errors via OpenAIErrorResponseTransform. Like every other provider here, model is a passthrough param, so this exposes all of OpenRouter's image models with no hardcoded list to maintain.

Verified locally: tsc --noEmit clean on the new files (the 2 pre-existing bytez/open-ai-base errors are untouched), npm run build succeeds, and prettier --check passes on all 3 changed files (the CI formatting check should go green once the fork-PR workflow is approved to run). Happy to adjust anything.

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