Skip to content

fix(oauth): use platform.claude.com endpoint for token refresh + startup warning#2968

Closed
ygd58 wants to merge 1 commit into
NousResearch:mainfrom
ygd58:fix/oauth-token-refresh-endpoint
Closed

fix(oauth): use platform.claude.com endpoint for token refresh + startup warning#2968
ygd58 wants to merge 1 commit into
NousResearch:mainfrom
ygd58:fix/oauth-token-refresh-endpoint

Conversation

@ygd58

@ygd58 ygd58 commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

Fixes #2962

Fix 1: Correct OAuth token refresh endpoint

_refresh_oauth_token() was using https://console.anthropic.com/v1/oauth/token which returns HTTP 500 for tokens obtained via Claude Code OAuth flow.

Now tries platform.claude.com first (correct endpoint per Claude Code's cli.js), then falls back to console.anthropic.com for legacy tokens. Also tries both application/json and application/x-www-form-urlencoded content types.

Fix 2: Startup warning when refresh credentials missing

When an OAuth token is detected but no ~/.claude/.credentials.json with a refreshToken exists, logs a warning at startup so users know the token will expire in ~8 hours with no auto-renewal path.

Fix 3 (already existed)

401 recovery via _try_refresh_anthropic_client_credentials() was already implemented — Fix 1 makes it actually work by correcting the endpoint.

@nrubioru

nrubioru commented Apr 1, 2026

Copy link
Copy Markdown

Hey @ygd58 — thanks for the quick fix on this. Just checking in: the PR has a merge conflict now (base branch moved since Mar 25) and the supply chain audit CI check failed. Would you be able to rebase against main to resolve the conflict?

We filed the original issue (#2962) and can confirm the root cause analysis — we've been running Hermes on a headless server with Anthropic Max OAuth tokens and hit this exact failure daily. The endpoint correction to platform.claude.com matches what Claude Code's own source uses.

Would love to see this get merged. Happy to help test if needed.

cc @NousResearch maintainers — would appreciate a review when the conflict is resolved. This is a pretty straightforward fix (correct endpoint + startup warning) that makes OAuth refresh actually work for headless deployments.

…tartup warning when refresh credentials missing
@ygd58 ygd58 force-pushed the fix/oauth-token-refresh-endpoint branch from ddc4bf4 to 09705b5 Compare April 1, 2026 16:07
@ygd58

ygd58 commented Apr 1, 2026

Copy link
Copy Markdown
Contributor Author

Rebased against main — conflict resolved. The fix now uses refresh_anthropic_oauth_pure(use_json=True) for platform.claude.com first, then falls back to use_json=False for console.anthropic.com legacy tokens.

@teknium1

teknium1 commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Superseded by commit 2c719f0 (PR #3246) which landed the same fix on main. Credit to @ygd58 for identifying the correct endpoint (platform.claude.com) — your analysis was the basis for the merged fix. The remaining _OAUTH_TOKEN_URL inconsistency in the PKCE login flow is being addressed separately.

@teknium1 teknium1 closed this Apr 7, 2026
Isla-Liu added a commit to Isla-Liu/hermes-agent that referenced this pull request May 28, 2026
Adds a public wrapper pair for the per-turn session-identity ContextVar in gateway.session_context, mirroring the structural pattern that tools/approval.py uses for the approval-session ContextVar.

Naming: deliberately distinct from approval.py's set_current_session_key -- the two ContextVars carry different concerns and downstream callers will eventually need to set both. 'turn_session' disambiguates from the approval-session.

Motivation: hermes-webui PR NousResearch#2968 (nesquena/hermes-webui#2968) currently binds per-turn session identity by importing _SESSION_KEY and calling .set() directly, which the maintainer flagged as a private-API touch. This wrapper closes that gap; the webui-side refactor lands as a follow-up commit on that PR once this lands.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: OAuth token refresh fails on headless gateway — wrong endpoint + no recovery, causing persistent 401s with Anthropic Max

3 participants