8000 Handle the case where OpenAI ChatCompletion created is None by wdhorton · Pull Request #1764 · pydantic/pydantic-ai · GitHub
[go: up one dir, main page]

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

Closed
wants to merge 1 commit into 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
@DouweM
Copy link
Contributor
DouweM commented Jul 7, 2025

@wdhorton I'm closing this PR as it's been a few months with no response; if you're still running into this issue and interested in implementing this feel free to reopen it!

@DouweM DouweM closed this Jul 7, 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
0