Skip to content

OpenRouter xAI/Grok tool schemas fail when additionalProperties: false is emitted #23704

Closed as not planned

Description

@dotCipher

Summary

Tool calling fails in OpenCode for xAI models via OpenRouter because emitted tool/input JSON schemas include additionalProperties: false, which xAI rejects.

Repro

Model:

  • openrouter/x-ai/grok-4.1-fast

Observed error:

  • [xAI] Invalid request content: Schema validation failed: [standard_violation] /properties/properties/additionalProperties: property schema 'false' is not supported

Notes

This happens on the native OpenCode OpenRouter path, not from external plugins.

OpenCode currently runs tool schemas through ProviderTransform.schema(...) before handing them to the model. For xAI via OpenRouter, that transform should strip additionalProperties: false recursively.

Why this is safe

xAI structured output docs state:

  • additionalProperties defaults to false
  • schemas with boolean property schemas like false are rejected

So omitting explicit additionalProperties: false preserves behavior while avoiding the xAI validator error.

Proposed fix

In packages/opencode/src/provider/transform.ts, add an xAI/OpenRouter schema sanitizer:

  • apply only when providerID === "openrouter" and model.api.id.startsWith("x-ai/")
  • recursively remove additionalProperties: false
  • preserve additionalProperties: true and object-valued additionalProperties

Related context

OpenCode already has related provider-specific schema sanitization work:

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 21, 2026
  2. github-actions commented on Apr 21, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of an existing issue. Please check:

  3. dotCipher commented on Apr 21, 2026

    @dotCipher
    Author

    Sorry for the double add, closing the other and using this one instead

  4. added a commit that references this issue on Apr 21, 2026
    c8692ce
  5. dotCipher commented on Apr 21, 2026

    @dotCipher
    Author

    Attempted a fix, but ended up failing after thorough testing: #23706 (comment)

    Still an open issue here

  6. dotCipher commented on Apr 21, 2026

    @dotCipher
    Author

    Also filed upstream at Vercel AI: vercel/ai#14678

    The root cause is in @ai-sdk/provider-utils's addAdditionalPropertiesToJsonSchema function, which unconditionally adds additionalProperties: false to all object schemas during tool serialization. A proper fix needs to happen there.

  7. removed
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  8. github-actions commented on Jul 3, 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