hermes - 💡(How to fix) Fix [Bug]: xAI Grok (xai-oauth) returns HTTP 400 or streaming fallback errors on Responses API [1 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

HTTP 400: {'code': 'Client specified an invalid argument', 'error': 'Invalid arguments passed to the model.'}

Additional Logs / Traceback (optional)

Root Cause

Root Cause Analysis (optional)

Fix Action

Fixed

Code Example

model:
     provider: xai-oauth
     default: grok-4.3
     base_url: https://api.x.ai/v1
     api_mode: codex_responses

---

hermes chat -q "Reply OK only." -Q

---

HTTP 400: {'code': 'Client specified an invalid argument', 'error': 'Invalid arguments passed to the model.'}

---

Report       https://paste.rs/xq8PR
  agent.log    https://paste.rs/qdhwe
  gateway.log  https://paste.rs/wSdK7

---



---

"includeDomains": {
  "items": {
    "type": "string",
    "pattern": "^(?=.{1,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$"
  }
}
RAW_BUFFERClick to expand / collapse

Bug Description

Using Grok models (grok-4.3) with provider: xai-oauth and api_mode: codex_responses fails after hermes update.

Two distinct failure modes occur:

  1. Streaming path: responses.stream() fails with runtime errors about missing terminal events, followed by a broken create(stream=True) fallback.
  2. Non-streaming path: responses.create() returns HTTP 400: Client specified an invalid argument when MCP Firecrawl tools are present.

Minimal direct requests to https://api.x.ai/v1/responses succeed with the same credentials, confirming this is not an OAuth/entitlement problem.

Steps to Reproduce

  1. Configure Hermes with:
    model:
      provider: xai-oauth
      default: grok-4.3
      base_url: https://api.x.ai/v1
      api_mode: codex_responses
  2. Ensure MCP Firecrawl tools are enabled (default).
  3. Run any prompt:
    hermes chat -q "Reply OK only." -Q

Expected Behavior

  • Request succeeds using the Responses API.
  • Logs show codex_response_request and a normal turn completion.

Actual Behavior

Either:

  • Responses create(stream=True) fallback did not emit a terminal response.
  • or
    HTTP 400: {'code': 'Client specified an invalid argument', 'error': 'Invalid arguments passed to the model.'}

Affected Component

CLI (interactive chat)

Messaging Platform (if gateway-related)

No response

Debug Report

Report       https://paste.rs/xq8PR
  agent.log    https://paste.rs/qdhwe
  gateway.log  https://paste.rs/wSdK7

Operating System

Arch Linux

Python Version

3.11.15

Hermes Version

v0.14.0 (2026.5.16)

Additional Logs / Traceback (optional)

Root Cause Analysis (optional)

1. Streaming path always chosen for codex_responses

In run_agent.py, _interruptible_api_call() unconditionally routes codex_responses through _run_codex_stream()active_client.responses.stream(...).

xAI’s Responses streaming implementation is incompatible with the OpenAI SDK’s state machine. The SDK raises RuntimeError (missing response.completed / prelude errors), triggering the broken create(stream=True) fallback that also fails.

2. Tool schemas contain regex pattern constraints that xAI rejects

The MCP Firecrawl tool mcp_firecrawl_firecrawl_search registers schemas with:

"includeDomains": {
  "items": {
    "type": "string",
    "pattern": "^(?=.{1,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$"
  }
}

The existing strip_pattern_and_format() sanitizer in tools/schema_sanitizer.py only walked OpenAI-style tool shapes ({"function": {"parameters": ...}}). It never processed Responses-style shapes ({"name": "...", "parameters": ...}).

xAI’s /responses endpoint rejects pattern (and format) keywords in tool schemas, producing the 400.

Proposed Fix (optional)

  • Make the streaming decision provider-aware: treat xai and xai-oauth as non-streaming for codex_responses.
  • Extend schema_sanitizer.py to handle both OpenAI and Responses tool shapes.
  • Call strip_pattern_and_format() inside the xAI non-streaming Responses path before responses.create().
  • Add regression tests for Responses-format tools containing pattern/format.

Are you willing to submit a PR for this?

  • I'd like to fix this myself and submit a PR

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - 💡(How to fix) Fix [Bug]: xAI Grok (xai-oauth) returns HTTP 400 or streaming fallback errors on Responses API [1 pull requests]