Skip to content

fix(provider): sanitize xAI tool schemas for OpenRouter and native xai provider - #23707

Closed
dotCipher wants to merge 1 commit into
anomalyco:devfrom
dotCipher:fix/openrouter-xai-tool-schema-sanitization
Closed

dotCipher wants to merge 1 commit into
anomalyco:devfrom
dotCipher:fix/openrouter-xai-tool-schema-sanitization

Conversation

@dotCipher

@dotCipher dotCipher commented Apr 21, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #23704

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Tool calling fails for xAI models (e.g. grok-4.1-fast) when used through OpenRouter or the native xai provider. The error is:

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

xAI structured output docs state:

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

So the fix strips additionalProperties: false from tool/input JSON schemas before sending to xAI. This preserves the intended strictness (since false is the default) while avoiding the validator rejection.

The change is scoped to:

  • providerID === "xai" (native xAI provider)
  • providerID === "openrouter" with model.api.id.startsWith("x-ai/") (xAI models via OpenRouter)

Non-xAI models are unaffected.

How did you verify your code works?

Added unit tests in packages/opencode/test/provider/transform.test.ts:

  • Verifies recursive removal of additionalProperties: false for both OpenRouter xAI and native xai provider
  • Verifies object-valued and true additionalProperties are preserved
  • Verifies non-xAI OpenRouter models are not affected

Local verification pending (installing bun to run bun test and E2E test against openrouter/x-ai/grok-4.1-fast).

Screenshots / recordings

N/A — no UI changes.

Checklist

  • I have tested my changes locally (pending bun install)
  • I have not included unrelated changes in this PR

Strip additionalProperties: false from tool/input JSON schemas
when targeting xAI models via OpenRouter. xAI rejects this
keyword while their validator already defaults to false.

Fixes anomalyco#23704
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Apr 21, 2026
@github-actions

github-actions Bot commented Apr 21, 2026 •

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • Not all checklist items are checked. Please confirm you have tested locally and have not included unrelated changes.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Found a potential duplicate:

This PR has the exact same title as the current PR (#23707) and appears to address the same issue - sanitizing xAI tool schemas for OpenRouter by removing additionalProperties: false.

You may want to check if PR #23706 is already merged or under review, and coordinate with it if needed.

@dotCipher

Copy link
Copy Markdown
Author

Closing, using the other one (double added via GH API), reference this one instead: #23707

@dotCipher dotCipher closed this Apr 21, 2026
@dotCipher dotCipher changed the title fix(provider): sanitize xAI tool schemas for OpenRouter fix(provider): sanitize xAI tool schemas for OpenRouter and native xai provider Apr 21, 2026
@dotCipher dotCipher changed the title fix(provider): sanitize xAI tool schemas for OpenRouter fix(provider): sanitize xAI tool schemas for OpenRouter and native xai provider Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:compliance This means the issue will auto-close after 2 hours.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant