Skip to content

Add OpenRouter as third image generation backend#29

Open
luyao618 wants to merge 1 commit intohtdt:masterfrom
luyao618:feat/openrouter-backend
Open

Add OpenRouter as third image generation backend#29
luyao618 wants to merge 1 commit intohtdt:masterfrom
luyao618:feat/openrouter-backend

Conversation

@luyao618
Copy link
Copy Markdown

@luyao618 luyao618 commented Apr 9, 2026

Summary

  • Adds OpenRouter as a third image backend (--model openrouter) alongside Gemini and Grok, providing flexible access to any OpenRouter-hosted image model via --openrouter-model <id> (default: openai/gpt-5-image-mini).
  • Dynamically estimates per-generation cost by querying the OpenRouter /v1/models API, checking pricing.image, pricing.request, and pricing.prompt/pricing.completion in priority order — so budget tracking stays accurate regardless of how the model is priced.
  • Adapts the modalities field per model: requests ["image", "text"] for models that support both, ["image"] for image-only models (FLUX, Seedream, etc.), preventing rejected requests.
  • Parses multiple OpenRouter response formats: choices[].message.content[] image_url entries, choices[].message.images[], and DALL-E-style data[].b64_json.
  • Caches the model catalog per process to avoid redundant API calls.
  • Updates README, setup.md, asset-gen.md, and asset-planner.md with OpenRouter documentation.

Why

Gemini and Grok cover most use cases, but having a third backend is useful when:

  • A user doesn't have Google or xAI API keys but has an OpenRouter key
  • A specific OpenRouter-hosted model fits the asset better (e.g. a different style or quality)
  • Gemini or xAI is down or rate-limited

Changed files

File Change
skills/godogen/tools/asset_gen.py OpenRouter backend implementation, dynamic pricing, adaptive modalities
skills/godogen/asset-gen.md CLI docs for --model openrouter and --openrouter-model
skills/godogen/asset-planner.md Updated cost table and backend selection guidance
README.md Added OPENROUTER_API_KEY to prerequisites
setup.md Added OPENROUTER_API_KEY to API keys section

Test plan

  • asset_gen.py image --model openrouter --prompt "red ball" -o test.png with OPENROUTER_API_KEY set — verify image generation works
  • --openrouter-model google/gemini-2.5-flash-image — verify custom model selection
  • Run without OPENROUTER_API_KEY — verify clear error message
  • set_budget 10 then generate with openrouter — verify budget check uses dynamic cost, not flat 5¢
  • Verify budget.json log records actual estimated cost

🤖 Generated with Claude Code

Adds OpenRouter support to asset_gen.py alongside Gemini and Grok,
providing flexible access to any OpenRouter-hosted image model via
--model openrouter and --openrouter-model <id>.

Key details:
- Default model: openai/gpt-5-image-mini (~5¢)
- Dynamic cost estimation from OpenRouter /v1/models API, checking
  per-image, per-request, and per-token pricing in priority order
- Adaptive modalities: requests text+image for models that support
  both, image-only for pure image models (FLUX, Seedream, etc.)
- Multi-strategy response parsing (content array, images array,
  DALL-E style b64_json)
- Model catalog cached per process to avoid redundant API calls

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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