openclaw - 💡(How to fix) Fix Bug: Anthropic OAuth refresh intermittently fails across chats/topics [10 comments, 1 participants]

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…
GitHub stats
openclaw/openclaw#44616Fetched 2026-04-08 00:44:31
View on GitHub
Comments
10
Participants
1
Timeline
14
Reactions
0
Author
Participants
Timeline (top)
commented ×9cross-referenced ×4subscribed ×1

Error Message

  1. In some Telegram topics requests still fail with OAuth refresh error.

Fix Action

Fix / Workaround

Mitigation used

  • Temporarily fallback to openai-codex/gpt-5.3-codex
  • Re-auth via claude login
  • Resync anthropic:default OAuth fields into OpenClaw auth profiles

Code Example

Config        : ~/.openclaw/openclaw.json
Agent dir     : ~/.openclaw/agents/main/agent
Default       : openai-codex/gpt-5.3-codex
Fallbacks (0) : -
Image model   : -
Image fallbacks (0): -
Aliases (2)   : opus -> anthropic/claude-opus-4-6, sonnet -> anthropic/claude-sonnet-4-6
Configured models (7): openai-codex/gpt-5.3-codex, openrouter/stepfun/step-3.5-flash:free, openrouter/nvidia/nemotron-3-nano-30b-a3b:free, routerai/qwen/qwen3-235b-a22b-thinking-2507, openai-codex/gpt-5.2-codex, anthropic/claude-opus-4-6, anthropic/claude-sonnet-4-6

Auth overview
Auth store    : ~/.openclaw/agents/main/agent/auth-profiles.json
Shell env     : off
Providers w/ OAuth/tokens (2): anthropic (1), openai-codex (1)
- anthropic effective=profiles:~/.openclaw/agents/main/agent/auth-profiles.json | profiles=1 (oauth=1, token=0, api_key=0) | anthropic:default=OAuth
- openai-codex effective=profiles:~/.openclaw/agents/main/agent/auth-profiles.json | profiles=1 (oauth=1, token=0, api_key=0) | openai-codex:default=OAuth
- openrouter effective=profiles:~/.openclaw/agents/main/agent/auth-profiles.json | profiles=1 (oauth=0, token=0, api_key=1) | openrouter:default=sk-or-v1...d945a06b | env=sk-or-v1...d945a06b | source=env: OPENROUTER_API_KEY | models.json=sk-or-v1...d945a06b | source=models.json: ~/.openclaw/agents/main/agent/models.json
- polza effective=models.json:pza_lkxa...o8U1B9d- | models.json=pza_lkxa...o8U1B9d- | source=models.json: ~/.openclaw/agents/main/agent/models.json
- routerai effective=models.json:sk-n1B4Z...oxOOgS_y | models.json=sk-n1B4Z...oxOOgS_y | source=models.json: ~/.openclaw/agents/main/agent/models.json

OAuth/token status
- anthropic
  - anthropic:default ok expires in 0m
- openai-codex usage: 5h 41% left ⏱42m · Week 0% left ⏱5d 13h
  - openai-codex:default ok expires in 3d

Auth probes
┌──────────────────┬────────────────────────┬──────────────────────────────────────────────────────────────────────────┐
ModelProfileStatus├──────────────────┼────────────────────────┼──────────────────────────────────────────────────────────────────────────┤
│ anthropic/       │ anthropic:default      │ auth · 19s                                                               │
│ claude-opus-4-6   (oauth)                │ ↳ OAuth token refresh failed for anthropic: Failed to refresh OAuth│                  │                        │ token for anthropic. Please try again or re-authenticate.                
└──────────────────┴────────────────────────┴──────────────────────────────────────────────────────────────────────────┘
Probed 1 target in 19.4s

---

expires_in_min= 450.28
access_prefix= sk-ant-oat01-Tfn4C
refresh_prefix= sk-ant-ort01-veHin
RAW_BUFFERClick to expand / collapse

Bug Report: Anthropic OAuth refresh fails intermittently across Telegram topics

  • Date (UTC): 2026-03-13 03:40:11
  • OpenClaw version: OpenClaw 2026.3.11 (29dc654)
  • Default model: openai-codex/gpt-5.3-codex

Symptom

Agent fails before reply in some chats/topics with: OAuth token refresh failed for anthropic: Failed to refresh OAuth token for anthropic

Reproduction (observed)

  1. Anthropic model enabled globally (opus alias).
  2. Fresh Claude login completed successfully.
  3. In some Telegram topics requests still fail with OAuth refresh error.
  4. Manual sync from ~/.claude/.credentials.json to auth-profiles sometimes restores temporarily.

Expected

If credentials are valid, refresh should be consistent across all chats/topics and not require manual resync.

Actual

OAuth refresh is flaky/inconsistent; some topics fail while global status may look valid.

Diagnostics

models status --probe

Config        : ~/.openclaw/openclaw.json
Agent dir     : ~/.openclaw/agents/main/agent
Default       : openai-codex/gpt-5.3-codex
Fallbacks (0) : -
Image model   : -
Image fallbacks (0): -
Aliases (2)   : opus -> anthropic/claude-opus-4-6, sonnet -> anthropic/claude-sonnet-4-6
Configured models (7): openai-codex/gpt-5.3-codex, openrouter/stepfun/step-3.5-flash:free, openrouter/nvidia/nemotron-3-nano-30b-a3b:free, routerai/qwen/qwen3-235b-a22b-thinking-2507, openai-codex/gpt-5.2-codex, anthropic/claude-opus-4-6, anthropic/claude-sonnet-4-6

Auth overview
Auth store    : ~/.openclaw/agents/main/agent/auth-profiles.json
Shell env     : off
Providers w/ OAuth/tokens (2): anthropic (1), openai-codex (1)
- anthropic effective=profiles:~/.openclaw/agents/main/agent/auth-profiles.json | profiles=1 (oauth=1, token=0, api_key=0) | anthropic:default=OAuth
- openai-codex effective=profiles:~/.openclaw/agents/main/agent/auth-profiles.json | profiles=1 (oauth=1, token=0, api_key=0) | openai-codex:default=OAuth
- openrouter effective=profiles:~/.openclaw/agents/main/agent/auth-profiles.json | profiles=1 (oauth=0, token=0, api_key=1) | openrouter:default=sk-or-v1...d945a06b | env=sk-or-v1...d945a06b | source=env: OPENROUTER_API_KEY | models.json=sk-or-v1...d945a06b | source=models.json: ~/.openclaw/agents/main/agent/models.json
- polza effective=models.json:pza_lkxa...o8U1B9d- | models.json=pza_lkxa...o8U1B9d- | source=models.json: ~/.openclaw/agents/main/agent/models.json
- routerai effective=models.json:sk-n1B4Z...oxOOgS_y | models.json=sk-n1B4Z...oxOOgS_y | source=models.json: ~/.openclaw/agents/main/agent/models.json

OAuth/token status
- anthropic
  - anthropic:default ok expires in 0m
- openai-codex usage: 5h 41% left ⏱42m · Week 0% left ⏱5d 13h
  - openai-codex:default ok expires in 3d

Auth probes
┌──────────────────┬────────────────────────┬──────────────────────────────────────────────────────────────────────────┐
│ Model            │ Profile                │ Status                                                                   │
├──────────────────┼────────────────────────┼──────────────────────────────────────────────────────────────────────────┤
│ anthropic/       │ anthropic:default      │ auth · 19s                                                               │
│ claude-opus-4-6  │ (oauth)                │ ↳ OAuth token refresh failed for anthropic: Failed to refresh OAuth      │
│                  │                        │ token for anthropic. Please try again or re-authenticate.                │
└──────────────────┴────────────────────────┴──────────────────────────────────────────────────────────────────────────┘
Probed 1 target in 19.4s

credentials snapshot (masked)

expires_in_min= 450.28
access_prefix= sk-ant-oat01-Tfn4C
refresh_prefix= sk-ant-ort01-veHin

auth profile paths

  • /root/.openclaw/agents/main/agent/auth-profiles.json
  • /root/.openclaw/auth-profiles.json

Mitigation used

  • Temporarily fallback to openai-codex/gpt-5.3-codex
  • Re-auth via claude login
  • Resync anthropic:default OAuth fields into OpenClaw auth profiles

extent analysis

Fix Plan

To resolve the intermittent OAuth refresh failure for Anthropic, follow these steps:

  • Update the auth-profiles.json file to ensure consistency across all chats/topics.
  • Implement a retry mechanism for OAuth token refresh to handle temporary failures.
  • Verify the expires_in_min value in the credentials snapshot to ensure it's within a valid range.

Code Changes

import requests
import time

def refresh_oauth_token():
    # Retry mechanism for OAuth token refresh
    max_retries = 3
    retry_delay = 10  # seconds

    for attempt in range(max_retries):
        try:
            # Refresh OAuth token using the Anthropic API
            response = requests.post("https://api.anthropic.com/oauth/token", 
                                    headers={"Content-Type": "application/x-www-form-urlencoded"},
                                    data={"grant_type": "refresh_token", 
                                          "refresh_token": "sk-ant-ort01-veHin"})
            response.raise_for_status()
            return response.json()
        except requests.RequestException as e:
            if attempt < max_retries - 1:
                print(f"OAuth token refresh failed (attempt {attempt + 1}/{max_retries}). Retrying in {retry_delay} seconds...")
                time.sleep(retry_delay)
            else:
                print(f"OAuth token refresh failed after {max_retries} attempts. Error: {e}")
                return None

# Example usage:
oauth_token = refresh_oauth_token()
if oauth_token:
    print("OAuth token refreshed successfully:")
    print(oauth_token)

Verification

To verify the fix, monitor the OAuth token refresh process and check for any errors. You can also test the refresh_oauth_token function manually to ensure it's working as expected.

Extra Tips

  • Ensure the auth-profiles.json file is properly formatted and contains the correct OAuth credentials.
  • Consider implementing a more robust retry mechanism, such as exponential backoff, to handle temporary failures.
  • Regularly review the expires_in_min value in the credentials snapshot to ensure it's within a valid range and update the OAuth token accordingly.

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