Skip to content

fix(baoyu-image-gen): align OpenRouter image generation with current API#101

Merged
JimLiu merged 4 commits intoJimLiu:mainfrom
cwandev:fix/openrouter
Mar 21, 2026
Merged

fix(baoyu-image-gen): align OpenRouter image generation with current API#101
JimLiu merged 4 commits intoJimLiu:mainfrom
cwandev:fix/openrouter

Conversation

@cwandev
Copy link
Copy Markdown
Contributor

@cwandev cwandev commented Mar 19, 2026

Summary

Fix OpenRouter image generation in baoyu-image-gen to match the current OpenRouter API.

Changes

  • switch request payload from imageGenerationOptions to image_config
  • send plain string content for text-only image generation
  • keep multimodal array content when reference images are provided
  • include finish_reason in no-image errors for easier debugging
  • add OpenRouter provider tests for request/response handling

Why

The previous OpenRouter request format could return No image in OpenRouter response for image-capable models such as google/gemini-3.1-flash-image-preview.

Verification

node --import tsx --test "skills/baoyu-image-gen/scripts/providers/*.test.ts"

All provider tests passed locally.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1af984a64f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread skills/baoyu-image-gen/scripts/providers/openrouter.ts
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: efb7a1917a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread skills/baoyu-image-gen/scripts/providers/openrouter.ts Outdated
Comment thread skills/baoyu-image-gen/scripts/providers/openrouter.ts Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 96ef6e2251

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread skills/baoyu-image-gen/scripts/providers/openrouter.ts
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e43eec260a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +161 to +162
function getModalities(model: string): string[] {
return isGeminiImageModel(model) ? ["image", "text"] : ["image"];
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Recognize non-Gemini OpenRouter models that need text output

getModalities() now treats every non-Gemini model as image-only. The skill explicitly accepts arbitrary OpenRouter model IDs (skills/baoyu-image-gen/SKILL.md:258-263), and OpenRouter's openai/gpt-5-image quickstart documents that model as requiring modalities: ["image", "text"]. In that scenario this provider will send modalities: ["image"], so requests for GPT-5 Image (and similar non-Gemini multimodal image models) can be rejected before any image is returned.

Useful? React with 👍 / 👎.

Comment on lines +153 to +155
const inferred = inferAspectRatio(args.size);
if (!inferred || !getSupportedAspectRatios(model).has(inferred)) {
return null;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Fail when --size maps to an unsupported OpenRouter ratio

getAspectRatio() now drops any inferred ratio that is not in the supported set, but buildRequestBody() still forwards the inferred image_size. For inputs like --size 1000x500, that means the request keeps image_size: "1K" while omitting aspect_ratio, and OpenRouter falls back to its default 1:1 output instead of anything close to the requested landscape size. This silently turns an explicit size request into the wrong dimensions; if a ratio cannot be represented, the CLI should error or map it to a supported ratio instead of discarding it.

Useful? React with 👍 / 👎.

@JimLiu JimLiu merged commit e7f9764 into JimLiu:main Mar 21, 2026
1 check passed
@cwandev cwandev deleted the fix/openrouter branch March 21, 2026 08:11
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