Skip to content

NVIDIA NIM kimik2.5 returns numeric tool call IDs causing 'expected id to be a string' error #19947

Closed as not planned

Description

@JoshCLWren

Describe the bug

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

  1. Configure NVIDIA NIM kimik2.5 as provider
  2. Attempt a tool call (e.g., read, write, etc.)
  3. 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.

Environment

  • Provider: NVIDIA NIM
  • Model: kimik2.5
  • OpenCode version: latest

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Mar 29, 2026
  2. ydrk12 commented on Apr 4, 2026

    @ydrk12

    Same error happens using a local model loaded by lmstudio

  3. crsmillan commented on Apr 10, 2026

    @crsmillan

    same using NIM with any model.

  4. easyfrog commented on Apr 13, 2026

    @easyfrog

    same error using kimi k2.5 model nim

  5. DragonX1901 commented on Apr 19, 2026

    @DragonX1901

    Same error using GLM 5.1

  6. tenny1225 commented on Apr 20, 2026

    @tenny1225

    Same error using GLM 5.1

  7. Qiiks commented on Apr 20, 2026

    @Qiiks

    I've submitted a fix for this issue in PR #23592.

    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.

    Changes:

    • Modified OpenAICompatibleChatResponseSchema tool_calls.id schema
    • Modified streaming chunk schema tool_calls.id similarly
    • Updated error message for missing ID
    • Added test case for numeric tool call IDs
  8. Qiiks commented on Apr 20, 2026

    @Qiiks

    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.

    Please see #22612 for the fix.

  9. added a commit that references this issue on Apr 21, 2026
    5528200
  10. Qiiks commented on Apr 21, 2026

    @Qiiks

    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
    • No changes to the copilot SDK
  11. Qiiks commented on Apr 22, 2026

    @Qiiks

    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:

    • 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.

  12. added a commit that references this issue on Apr 22, 2026
    9078c0e
  13. Zireael commented on Apr 24, 2026

    @Zireael

    Adding a second data point from a different NVIDIA model path.

    I hit the same AI_InvalidResponseDataError: Expected 'id' to be a string in OpenCode with providerID=nvidia and modelID=z-ai/glm-5.1.

    Relevant log evidence from my session:

    • C:\Users\zir\.local\share\opencode\log\2026-04-24T072123.log#L22327
    • The failing session is ses_2419f9a5bffeVdR1llFHd6IAIG
    • The log shows service=llm providerID=nvidia modelID=z-ai/glm-5.1
    • OpenCode then stops in session.processor with Expected 'id' to be a string.

    I also saw an earlier NVIDIA 502 Bad Gateway in the same session, but the final hard stop was the id validation failure.

    This looks like the same NVIDIA/OpenAI-compatible response-shape issue reported here, just on z-ai/glm-5.1 instead of kimik2.5.

  14. removed
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  15. igrisqq commented on May 15, 2026

    @igrisqq

    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.

  16. github-actions commented on Jul 15, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions