Skip to content

[Python SDK] Upgrade OpenRouter image generation with new models and image_config #466

@santoshkumarradha

Description

@santoshkumarradha

Summary

Update OpenRouterProvider.generate_image() and vision.generate_image_openrouter() to support the latest OpenRouter image models and the expanded image_config options (aspect_ratio, image_size, super_resolution_references, font_inputs).

Context

OpenRouter has added several new image models since the original integration:

Model Notes
google/gemini-2.5-flash-image Nano Banana — GA, contextual understanding
google/gemini-3.1-flash-image-preview Nano Banana 2 — Pro-level quality at Flash speed
google/gemini-3-pro-image Nano Banana Pro — improved multimodal reasoning
bytedance/seedream-4.5 ByteDance's latest, editing consistency
openai/gpt-5-image GPT-5 with image gen, superior text rendering
sourceful/riverflow-v2-pro SOTA with integrated reasoning model

New image_config Parameters

{
  "image_config": {
    "aspect_ratio": "16:9",
    "image_size": "2K",
    "super_resolution_references": ["url1", "url2"],
    "font_inputs": [{"font_url": "...", "text": "..."}]
  }
}
  • aspect_ratio: 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9 (+ 1:4, 4:1, 1:8, 8:1 for Gemini 3.1 Flash)
  • image_size: 0.5K, 1K (default), 2K, 4K
  • super_resolution_references: Up to 4 reference URLs for enhancing low-quality elements (Sourceful only, $0.20/ref)
  • font_inputs: Up to 2 font inputs for text rendering (Sourceful only, $0.03/input)

Files

File Change
sdk/python/agentfield/vision.py Update generate_image_openrouter() to accept and pass image_config properly
sdk/python/agentfield/media_providers.py Update OpenRouterProvider.generate_image() signature with aspect_ratio, image_size params that map to image_config

Developer Experience

# New models work transparently
result = await app.ai_generate_image(
    "A photorealistic sunset",
    model="openrouter/openai/gpt-5-image",
)

# Aspect ratio and size control
result = await app.ai_generate_image(
    "A landscape painting",
    model="openrouter/google/gemini-3.1-flash-image-preview",
    image_config={"aspect_ratio": "21:9", "image_size": "4K"},
)

# Super resolution
result = await app.ai_generate_image(
    "Enhance this scene",
    model="openrouter/sourceful/riverflow-v2-pro",
    image_config={"super_resolution_references": ["https://example.com/highres.jpg"]},
)

Dependencies

Acceptance Criteria

  • image_config parameter properly passed through to OpenRouter API
  • New model slugs work (test with at least one new model)
  • aspect_ratio and image_size convenience params map to image_config
  • Existing image generation behavior unchanged
  • pytest sdk/python/ passes
  • ruff check sdk/python/ passes

Notes for Contributors

Severity: LOW — Enhancement to existing working feature.

The image_config is already partially supported via **kwargs passthrough, but it's not documented or explicitly handled. Making it a first-class parameter improves discoverability.

Metadata

Metadata

Labels

ai-friendlyWell-documented task suitable for AI-assisted developmentarea:aiAI/LLM integrationenhancementNew feature or requestgood first issueGood for newcomerssdk:pythonPython SDK related

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions