You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NVIDIA NIM kimik2.5 returns numeric tool call IDs causing 'expected id to be a string' error #19947
When using NVIDIA NIM kimik2.5 model with tool calls, the provider returns tool call IDs as numeric values instead of strings, causing Zod validation errors: expected id to be a string
To Reproduce
Configure NVIDIA NIM kimik2.5 as provider
Attempt a tool call (e.g., read, write, etc.)
Observe validation error in logs
Expected behavior
Tool calls should work seamlessly with NVIDIA NIM kimik2.5, automatically converting numeric IDs to strings.
Root Cause
NVIDIA NIM kimik2.5 returns tool call IDs as numbers (e.g., 123) instead of strings (e.g., "123"), violating OpenAI API specification which requires string IDs.
Root Cause: The Zod schemas in openai-compatible-chat-language-model.ts require id: z.string() for tool call IDs, rejecting numeric values.
Fix: Modified the schemas to accept both string and numeric IDs using z.union([z.string(), z.number().transform((v) => String(v))]). Numeric IDs are automatically coerced to strings, making the fix backward-compatible with all existing providers.
Update: There's already an open PR #22612 that fixes this issue. It uses a similar approach with z.preprocess to coerce numeric IDs to strings. I've closed my duplicate PR #23592.
Update: I've completely revised my fix in PR #23592.
What was wrong before: My initial fix modified the GitHub Copilot SDK (openai-compatible-chat-language-model.ts), which the maintainer correctly pointed out is only used for GitHub Copilot, not for other OpenAI-compatible providers like NVIDIA NIM.
Correct approach: The Zod validation for @ai-sdk/openai-compatible providers happens inside the external npm package, not in OpenCode's codebase. The correct fix is to intercept responses at the fetch wrapper level in provider.ts and coerce numeric tool call IDs to strings before the external SDK's Zod validation sees them.
The new fix:
Intercepts responses in the fetch wrapper (applies to ALL @ai-sdk/openai-compatible providers)
Handles both JSON responses and SSE streaming responses
Transforms numeric IDs to strings before the SDK processes them
I've reopened this work with a corrected approach. My previous PR (#23592) was auto-closed due to template issues, and the fix location was also wrong.
The fix is now at the fetch wrapper level in provider.ts (correct location)
Applies to all@ai-sdk/openai-compatible providers (not just GitHub Copilot)
Handles both JSON and SSE streaming responses
Coerces numeric tool call IDs to strings before the external SDK's Zod validation
This addresses the maintainer's feedback that my first fix was in the wrong place (copilot SDK only). The new fix is in the right place and should work for NVIDIA NIM and any other OpenAI-compatible provider that returns numeric IDs.
That issue produces on most models which support openai endpoints. Also if you fix it locally the next error will occur: Expected 'function.name' to be a string.
Activity
ydrk12 commentedon Apr 4, 2026
Same error happens using a local model loaded by lmstudio
crsmillan commentedon Apr 10, 2026
same using NIM with any model.
easyfrog commentedon Apr 13, 2026
same error using kimi k2.5 model nim
DragonX1901 commentedon Apr 19, 2026
Same error using GLM 5.1
tenny1225 commentedon Apr 20, 2026
Same error using GLM 5.1
Qiiks commentedon Apr 20, 2026
I've submitted a fix for this issue in PR #23592.
Root Cause: The Zod schemas in
openai-compatible-chat-language-model.tsrequireid: z.string()for tool call IDs, rejecting numeric values.Fix: Modified the schemas to accept both string and numeric IDs using
z.union([z.string(), z.number().transform((v) => String(v))]). Numeric IDs are automatically coerced to strings, making the fix backward-compatible with all existing providers.Changes:
OpenAICompatibleChatResponseSchematool_calls.id schemaQiiks commentedon Apr 20, 2026
Update: There's already an open PR #22612 that fixes this issue. It uses a similar approach with
z.preprocessto coerce numeric IDs to strings. I've closed my duplicate PR #23592.Please see #22612 for the fix.
fix(provider): coerce numeric tool call IDs for OpenAI-compatible pro…
Qiiks commentedon Apr 21, 2026
Update: I've completely revised my fix in PR #23592.
What was wrong before: My initial fix modified the GitHub Copilot SDK (
openai-compatible-chat-language-model.ts), which the maintainer correctly pointed out is only used for GitHub Copilot, not for other OpenAI-compatible providers like NVIDIA NIM.Correct approach: The Zod validation for
@ai-sdk/openai-compatibleproviders happens inside the external npm package, not in OpenCode's codebase. The correct fix is to intercept responses at the fetch wrapper level inprovider.tsand coerce numeric tool call IDs to strings before the external SDK's Zod validation sees them.The new fix:
@ai-sdk/openai-compatibleproviders)Qiiks commentedon Apr 22, 2026
I've reopened this work with a corrected approach. My previous PR (#23592) was auto-closed due to template issues, and the fix location was also wrong.
New PR: #23886
What changed:
provider.ts(correct location)@ai-sdk/openai-compatibleproviders (not just GitHub Copilot)This addresses the maintainer's feedback that my first fix was in the wrong place (copilot SDK only). The new fix is in the right place and should work for NVIDIA NIM and any other OpenAI-compatible provider that returns numeric IDs.
fix(provider): coerce numeric tool call IDs for OpenAI-compatible pro…
Zireael commentedon Apr 24, 2026
Adding a second data point from a different NVIDIA model path.
I hit the same
AI_InvalidResponseDataError: Expected 'id' to be a stringin OpenCode withproviderID=nvidiaandmodelID=z-ai/glm-5.1.Relevant log evidence from my session:
C:\Users\zir\.local\share\opencode\log\2026-04-24T072123.log#L22327ses_2419f9a5bffeVdR1llFHd6IAIGservice=llm providerID=nvidia modelID=z-ai/glm-5.1session.processorwithExpected 'id' to be a string.I also saw an earlier NVIDIA
502 Bad Gatewayin the same session, but the final hard stop was theidvalidation failure.This looks like the same NVIDIA/OpenAI-compatible response-shape issue reported here, just on
z-ai/glm-5.1instead ofkimik2.5.igrisqq commentedon May 15, 2026
That issue produces on most models which support openai endpoints. Also if you fix it locally the next error will occur:
Expected 'function.name' to be a string.github-actions commentedon Jul 15, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.