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:
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-fastObserved error:
[xAI] Invalid request content: Schema validation failed: [standard_violation] /properties/properties/additionalProperties: property schema 'false' is not supportedNotes
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 stripadditionalProperties: falserecursively.Why this is safe
xAI structured output docs state:
additionalPropertiesdefaults tofalsefalseare rejectedSo omitting explicit
additionalProperties: falsepreserves behavior while avoiding the xAI validator error.Proposed fix
In
packages/opencode/src/provider/transform.ts, add an xAI/OpenRouter schema sanitizer:providerID === "openrouter"andmodel.api.id.startsWith("x-ai/")additionalProperties: falseadditionalProperties: trueand object-valuedadditionalPropertiesRelated context
OpenCode already has related provider-specific schema sanitization work: