Skip to content

Handle the case where OpenAI ChatCompletion created is None #1764

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

wdhorton
Copy link

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.

Also added a test case that covers this scenario.

Fixes #1746

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
@wdhorton
Copy link
Author

Just tested this locally with this branch, using the code from the issue, and I saw it successfully get a response from OpenRouter

@DouweM
Copy link
Contributor

DouweM commented May 19, 2025

@wdhorton Thanks! Can you please have a look at the failing coverage check?

@Kludex
Copy link
Member

Kludex commented May 20, 2025

Please check https://github.com/pydantic/pydantic-ai/pull/1778/files#r2097604759.

I've added a real test case for it, and it actually didn't fail. How can I reproduce this?

@Kludex Kludex assigned Kludex and unassigned DouweM May 20, 2025
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.

OpenAIModel fails with OpenRouter Gemini: missing "choices" and "created" keys
3 participants