-
Notifications
You must be signed in to change notification settings - Fork 901
OpenAIModel fails with OpenRouter Gemini: missing "choices" and "created" keys #1746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I was able to reproduce this. It only happens sometimes--since OpenRouter has two providers for this model, I'm guessing it happens for one of the providers but not the other. |
The OpenAI spec defines this as required, but other OpenAI-compatible providers (like OpenRouter) may not populate it on all responses. This adds code to handle the case where the field is None. Fixes pydantic#1746
Probably yes. If I set up OpenAI or DeepSeek it works. The problem practically only occurs with Google models. In any case, I only noticed it with them. |
I can't reproduce it. Also, trying many times is hard because there's a lot of 429. |
I've created the |
See this: https://github.com/pydantic/pydantic-ai/pull/1778/files#r2097604759. It didn't fail... How can I reproduce it? |
Initial Checks
Description
Summary
When using
OpenAIModel
with OpenRouter and the modelgoogle/gemini-2.0-flash-exp:free
, the agent fails with:TypeError: 'NoneType' object is not subscriptable
This happens because the response returned by OpenRouter for Gemini does not include the
choices
orcreated
keys expected by_process_response()
.Steps to Reproduce
Observed Error
Suggestion
Why it matters
OpenRouter is a growing ecosystem for multimodel access, and many of the available models (Gemini, Cohere, etc.) do not fully follow the OpenAI ChatCompletion schema. Supporting them would improve compatibility.
Let me know if you'd like me to submit a PR or share sample responses.
Thanks for the awesome tool!
Example Code
Python, Pydantic AI & LLM client version
The text was updated successfully, but these errors were encountered: