Skip to content

Fix: Handle usage.prompt_tokens_details when missing or None in API r… #69

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

LuminaX-alt
Copy link
Owner

…esponse

Fix NoneType issue for usage.prompt_tokens_details in API responses

Some API responses omit the prompt_tokens_details field or set it to None, causing downstream code to throw AttributeError when accessed directly.

This change ensures that usage.prompt_tokens_details defaults to an empty dictionary {} when missing or None, preventing runtime errors and improving compatibility across models and endpoints.

  • Added check in convert_to_openai_object to normalize missing fields
  • Maintains backward compatibility
  • I understand that this repository is auto-generated and my pull request may not be merged

Changes being requested

Additional context & links

…esponse

Fix NoneType issue for usage.prompt_tokens_details in API responses

Some API responses omit the `prompt_tokens_details` field or set it to `None`, 
causing downstream code to throw AttributeError when accessed directly.

This change ensures that `usage.prompt_tokens_details` defaults to an empty 
dictionary `{}` when missing or None, preventing runtime errors and improving 
compatibility across models and endpoints.

- Added check in `convert_to_openai_object` to normalize missing fields
- Maintains backward compatibility
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant