Skip to content

fix: allow null values for prompt_tokens_details and completion_tokens_details #75

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

Merged

Conversation

devin-ai-integration[bot]
Copy link
Contributor

Fix null validation for prompt_tokens_details and completion_tokens_details

Fixes #73

Problem

The OpenRouter API can return null for prompt_tokens_details and completion_tokens_details fields (e.g., with models like deepseek/deepseek-chat-v3-0324:free), but the current Zod schema validation only allows these fields to be objects or undefined with .optional(). This causes type validation errors:

Expected object, received null
path: ["usage", "prompt_tokens_details"]

Solution

Changed both prompt_tokens_details and completion_tokens_details in OpenRouterChatCompletionBaseResponseSchema from .optional() to .nullish() to allow null, undefined, or the object values.

Changes

  • Updated schema in src/openrouter-chat-language-model.ts lines 732-742
  • Both fields now use .nullish() instead of .optional()

Testing

  • Existing tests continue to pass with object values
  • Schema now accepts null values from OpenRouter API responses
  • No breaking changes to existing functionality

Link to Devin run

https://app.devin.ai/sessions/2bcf790816c649e1ae7b047c64262726

Requested by: Louis ([email protected])

…s_details

Fixes #73 where OpenRouter API returns null for prompt_tokens_details and
completion_tokens_details but schema validation only allowed object or undefined.
Changed .optional() to .nullish() to accept null, undefined, or object values.

Co-Authored-By: Louis   <[email protected]>
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@louisgv louisgv merged commit ff918aa into main Jun 4, 2025
3 checks passed
@louisgv louisgv deleted the devin/1749070514-fix-prompt-tokens-details-null-validation branch June 4, 2025 23:07
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.

JWT Token error after version 0.5.0
1 participant