Skip to content

Conversation

@ajac-zero
Copy link
Contributor

Closes #3258

This PR enables using OpenRouter for image generation.

It also adds a couple of new hooks to OpenAIChatModel._process_response to make it easier for subclasses to implement their own logic for FilePart responses, which OpenAIChatModel doesn't support.

@ajac-zero ajac-zero marked this pull request as ready for review November 30, 2025 09:16
@ajac-zero ajac-zero force-pushed the openrouter-image-gen branch from 95fb961 to cfbcb51 Compare December 1, 2025 05:16
...
```

## Image Generation
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should also make this work with builtin_tools=[ImageGenerationTool()] and document it here: https://ai.pydantic.dev/builtin-tools/#image-generation-tool

As with Google, which doesn't expose that as a tool, using that tool or BinaryImage in output_type should automatically enable the modality.


settings = OpenRouterModelSettings(
openrouter_modalities=['image', 'text'],
openrouter_image_config={'aspect_ratio': '3:2'}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I want this to be an option on ImageGenerationTool as in #3412.

Copy link
Collaborator

@DouweM DouweM Dec 1, 2025

Choose a reason for hiding this comment

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

I'm OK with it also being a model setting if it supports more keys than ImageGenerationTool does currently (or really: after that PR), but if this is the only field supported so far I'd prefer to leave that and the modality settings off.

If you want, you can finish that PR as we're at it to make your life here easier.


async with agent.run_stream('A dog') as result:
async for output in result.stream_output():
if isinstance(output, str):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This means we may never actually get to the image assertions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support OpenRouter image generation

2 participants