Skip to content

fix(auxiliary): xai-oauth uses chat.completions, not Responses API (#34171) - #34376

Closed
Bartok9 wants to merge 1 commit into
NousResearch:mainfrom
Bartok9:fix/34171-xai-oauth-no-codex-wrapper
Closed

fix(auxiliary): xai-oauth uses chat.completions, not Responses API (#34171)#34376
Bartok9 wants to merge 1 commit into
NousResearch:mainfrom
Bartok9:fix/34171-xai-oauth-no-codex-wrapper

Conversation

@Bartok9

@Bartok9 Bartok9 commented May 29, 2026

Copy link
Copy Markdown
Contributor

Closes #34171

Problem

xAI OAuth tokens are scoped to /v1/chat/completions only — NOT authorized for the Responses API. Wrapping the client in CodexAuxiliaryClient (which translates chat.completions calls to /v1/responses) caused every auxiliary task on an xai-oauth session to fail with HTTP 403:

'The OAuth2 access token could not be validated.
 [WKE=unauthenticated:bad-credentials]'

Same token works fine on direct /v1/chat/completions, confirming the mode (not the credential) was the problem.

Affected tasks: context compression, vision, web_extract, title generation, goal judge, summary — anything routed through get_text_auxiliary_client() for an xai-oauth session.

Fix

_build_xai_oauth_aux_client now returns a plain OpenAI client pointed at the xAI base URL. Every other auxiliary task already expects a chat.completions client → no upstream caller changes needed.

Tests (4)

$ python -m pytest tests/agent/test_xai_oauth_aux_client_chat_completions.py
=== 4 passed in 0.35s ===

🎻 Co-authored-by: Cursor cursoragent@cursor.com

…ousResearch#34171)

xAI OAuth tokens are scoped to /v1/chat/completions only — they are
NOT authorized for the Responses API. Wrapping the client in
CodexAuxiliaryClient (which translates chat.completions.create() calls
to responses.stream()) caused every auxiliary task on an xai-oauth
session to fail with HTTP 403:

  'The OAuth2 access token could not be validated.
   [WKE=unauthenticated:bad-credentials]'

Same token works fine on direct /v1/chat/completions, confirming the
mode (not the credential) was the problem.

Affected tasks: context compression, vision, web_extract, title
generation, goal judge, summary — anything routed through
auxiliary_client.get_text_auxiliary_client() for an xai-oauth session.

Fix: _build_xai_oauth_aux_client returns a plain OpenAI client
pointed at the xAI base URL. Every other auxiliary task already
expects a chat.completions client, so no upstream caller changes are
needed.

Tests (4 in test_xai_oauth_aux_client_chat_completions.py):

  - test_xai_oauth_aux_returns_plain_openai_client_not_codex_wrapper
    The NousResearch#34171 fix: client is a plain OpenAI, NOT a
    CodexAuxiliaryClient.
  - test_xai_oauth_aux_returns_none_when_no_model
    Defensive: empty model returns (None, None) + warning.
  - test_xai_oauth_aux_returns_none_when_unauthenticated
    No OAuth token → (None, None) cleanly.
  - test_xai_oauth_aux_uses_correct_base_url
    Plain client hits api.x.ai, not api.openai.com.

Refs: NousResearch#34171
Closes: NousResearch#34171

Co-authored-by: Cursor <cursoragent@cursor.com>
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/xai xAI (Grok) labels May 29, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #34241 — same fix (keep xAI OAuth aux client on chat.completions, not CodexAuxiliaryClient/Responses API). Both close #34171.

@Bartok9

Bartok9 commented May 29, 2026

Copy link
Copy Markdown
Contributor Author

Closing as duplicate of #34241 — thanks @alt-glitch for flagging.

Confirmed via diff: PR #34241 (by @LeonSGP, opened 23 min before this one at 01:45 UTC) makes the same surgical fix in _build_xai_oauth_aux_client (return plain OpenAI client, drop CodexAuxiliaryClient wrapper). Their PR also updates the existing routing test (test_auxiliary_client_routes_xai_oauth_through_chat_completions_api), which is cleaner than my approach of adding 4 net-new tests in a separate file.

I missed #34241 when I scanned open PRs against issue list before I started \u2014 my bad. #34241 is the canonical fix; this can be closed safely.

Apologies for the noise on the maintainer queue.

\u2014 Bartok9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P3 Low — cosmetic, nice to have provider/xai xAI (Grok) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

xai-oauth auxiliary client incorrectly uses Responses API (CodexAuxiliaryClient), causing 403 on compression/vision/web_extract

2 participants