Skip to content

fix: add xAI/Grok API compatibility#2809

Merged
amitksingh1490 merged 3 commits intotailcallhq:mainfrom
golah:fix/xai-grok-compatibility
Apr 13, 2026
Merged

fix: add xAI/Grok API compatibility#2809
amitksingh1490 merged 3 commits intotailcallhq:mainfrom
golah:fix/xai-grok-compatibility

Conversation

@golah
Copy link
Copy Markdown
Contributor

@golah golah commented Apr 2, 2026

Summary

ForgeCode currently fails to connect to xAI's API (Grok models) with "Client specified an invalid argument" error on every request.

Root Cause

xAI's API rejects null values in enum arrays within tool schemas. The fs_search tool's output_mode parameter generates "enum": ["content", "files_with_matches", "count", null] via schemars, which xAI rejects.

Additionally, xAI doesn't support several parameters that MakeOpenAiCompat passes through (stream_options, max_completion_tokens, reasoning_effort, etc.).

Fix

  1. Enable EnforceStrictToolSchema for xAI — this existing transformer converts nullable enums to anyOf format that xAI accepts.

  2. Add MakeXaiCompat transformer — handles xAI-specific parameter differences:

    • Removes stream_options (not reliably supported)
    • Reverts max_completion_tokens back to max_tokens (xAI uses max_tokens)
    • Strips reasoning_effort, thinking, logit_bias, top_logprobs, seed, prediction, parallel_tool_calls

Testing

Tested locally with:

  • grok-4-1-fast-reasoning — tool calling, file reading, code analysis ✅
  • grok-4.20-0309-reasoning — code editing with verification ✅
  • grok-4.20-0309-non-reasoning — basic chat and edits ✅

Files Changed

  • crates/forge_app/src/dto/openai/transformers/make_xai_compat.rs (new) — xAI parameter compatibility transformer
  • crates/forge_app/src/dto/openai/transformers/pipeline.rs — add xAI to strict schema condition + wire MakeXaiCompat into pipeline
  • crates/forge_app/src/dto/openai/transformers/mod.rs — register new module

xAI's API rejects null values in enum arrays in tool schemas.
Enable EnforceStrictToolSchema for xAI provider to convert
nullable enums to anyOf format.

Also adds MakeXaiCompat transformer to handle xAI-specific
parameter differences (stream_options, max_completion_tokens,
reasoning_effort, etc.).

Tested with grok-4-1-fast-reasoning and grok-4.20-0309 models.
@github-actions github-actions bot added the type: fix Iterations on existing features or infrastructure. label Apr 2, 2026
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 2, 2026

CLA assistant check
All committers have signed the CLA.

@github-actions
Copy link
Copy Markdown

Action required: PR inactive for 5 days.
Status update or closure in 10 days.

@github-actions github-actions bot added the state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. label Apr 13, 2026
@amitksingh1490 amitksingh1490 merged commit 7c430bb into tailcallhq:main Apr 13, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. type: fix Iterations on existing features or infrastructure.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants