Conversation
… backend OpenClaw's openai-codex provider always emits POST /v1/responses regardless of the upstream baseUrl. When the bearer token is a ChatGPT-mode JWT (eyJ...) rather than an sk-* API key, api.openai.com rejects the call. ChatGPT-mode tokens only work against chatgpt.com/backend-api/codex/*. Detect JWT-shaped bearer tokens at /v1/responses and reroute them to codex/responses (which dispatches to the ChatGPT backend), leaving sk-* keys and the chat/completions surface unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
openai-codexprovider always emitsPOST /v1/responsesregardless of the configured upstream base URL. When the bearer token is a ChatGPT-mode JWT (eyJ...) rather than ansk-*API key,api.openai.comrejects the call — those tokens only work againstchatgpt.com/backend-api/codex/*./v1/responsesin the proxy and reroutes them tocodex/responses(which already dispatches to the ChatGPT backend).sk-*API keys and thechat/completionssurface are unchanged.anthropic,codex, etc.) pass through untouched.Why
OpenClaw users running ChatGPT subscription auth through the agentweave proxy currently get auth-rejected at OpenAI. Without this reroute, the only workaround is to hand-edit the openclaw provider catalog to point at
codex/responses, which fights the plugin's normalization.Implementation
_is_chatgpt_mode_bearer(auth_header)— true iff token starts witheyJand notsk-(Anthropicsk-ant-*keys are explicitly excluded by thesk-check)._maybe_reroute_openai_to_codex(provider, path, auth_header)— narrow rewrite forprovider == "openai" && path == "v1/responses" && JWT bearer. Returns(provider, path); no-op for everything else._detect_provider, so_extract_model, streaming detection, and upstream URL building all see the rewritten provider/path.Test plan
TestChatGPTModeBearerDetection(5 cases): JWT with/withoutBearerprefix,sk-*keys,sk-ant-*, empty header.TestMaybeRerouteOpenAIToCodex(6 cases): reroute happy path, sk-key passthrough, no-auth passthrough,chat/completionsunaffected,anthropicunaffected,codexprovider unaffected./v1/responsestraffic to exercise this path).🤖 Generated with Claude Code