Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: ensure ResponseUsage token fields are int, not None (fixes #1179)#1181

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
rm-openai merged 1 commit intoopenai:mainfromkobol:fix/responseusage-token-none
Jul 18, 2025

Conversation

kobol
Copy link
Contributor

@kobolkobol commentedJul 18, 2025
edited by seratch
Loading

Problem

When using streaming responses, some models or API endpoints may returnusage fields (prompt_tokens,completion_tokens,total_tokens) asNone or omit them entirely. The current implementation passes these values directly to theResponseUsage Pydantic model, which expects integers. This causes a validation error:

3 validation errors for ResponseUsage
input_tokens
Input should be a valid integer [type=int_type, input_value=None, input_type=NoneType]
output_tokens
Input should be a valid integer [type=int_type, input_value=None, input_type=NoneType]
total_tokens
Input should be a valid integer [type=int_type, input_value=None, input_type=NoneType]

Solution

This PR ensures that all token fields passed toResponseUsage are always integers. If any of the fields areNone or missing, they default to0. This is achieved by usingor 0 and explicitis not None checks for nested fields.

Key changes:

  • Allinput_tokens,output_tokens,total_tokens fields useor 0 fallback.

Impact

  • Fixes Pydantic validation errors for streaming responses with missing/None usage fields.
  • Improves compatibility with OpenAI and third-party models.
  • No breaking changes; only adds robustness.

fixes#1179

@seratchseratch added bugSomething isn't working feature:chat-completions labelsJul 18, 2025
Copy link
Member

@seratchseratch left a comment

Choose a reason for hiding this comment

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

LGTM

@rm-openairm-openai merged commit23404e8 intoopenai:mainJul 18, 2025
5 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@seratchseratchseratch approved these changes

@rm-openairm-openairm-openai approved these changes

Assignees
No one assigned
Labels
bugSomething isn't workingfeature:chat-completions
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Streaming: ResponseUsage validation error when token fields are None
3 participants
@kobol@seratch@rm-openai

[8]ページ先頭

©2009-2025 Movatter.jp