Skip to content

fix: add OpenRouter image generation support & fix retry task directory#64

Open
voidborne-d wants to merge 1 commit intoHisMax:mainfrom
voidborne-d:fix/openrouter-compat-and-retry-dir
Open

fix: add OpenRouter image generation support & fix retry task directory#64
voidborne-d wants to merge 1 commit intoHisMax:mainfrom
voidborne-d:fix/openrouter-compat-and-retry-dir

Conversation

@voidborne-d
Copy link

Problem

1. OpenRouter API incompatibility (image_api.py)

When using OpenRouter as the image provider with endpoint_type: chat, the Chat API generator:

  • Does not include modalities: ["image", "text"] and image_config in the request payload, so OpenRouter returns text-only responses
  • Does not parse OpenRouter's message.images[] array format, only looking for images in message.content

2. Retry fails with "任务目录未设置" (image.py)

retry_failed_images() never sets self.current_task_dir before spawning worker threads. When workers call _generate_single_image()_save_image(), the task directory is None, causing all retries to fail even though image generation succeeds.

Changes

backend/generators/image_api.py

  • Add modalities: ["image", "text"] and image_config (with aspect_ratio and image_size) to Chat API request payload
  • Parse OpenRouter's message.images[] array response format (base64 data URLs)
  • Handle multimodal content parts (content as list of image_url objects)
  • Preserves backward compatibility with existing response formats (markdown URLs, plain base64, etc.)

backend/services/image.py

  • Set self.current_task_dir at the start of retry_failed_images(), consistent with generate_images() and retry_single_image()

OpenRouter Config Example

active_provider: openrouter_gemini

providers:
  openrouter_gemini:
    type: image_api
    api_key: sk-or-v1-xxxxx
    base_url: https://openrouter.ai/api/v1
    model: google/gemini-3.1-flash-image-preview
    endpoint_type: chat
    high_concurrency: false
    image_size: 4K

Testing

  • Tested with google/gemini-3.1-flash-image-preview via OpenRouter
  • Successfully generated 7-page Xiaohongshu post (cover + 5 content + summary)
  • Retry ("一键补全失败图片") works correctly after fix
  • Existing images/generations endpoint path still works (no regression)

- Add modalities and image_config to Chat API request payload for OpenRouter compatibility
- Parse OpenRouter's message.images[] array response format (base64 data URLs)
- Handle multimodal content parts (list of image_url objects)
- Set current_task_dir in retry_failed_images() to fix '任务目录未设置' error

Tested with google/gemini-3.1-flash-image-preview via OpenRouter.
Backward compatible with existing images/generations endpoint.
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