router-for-me/CLIProxyAPI · error

token refresh failed after %d attempts: %w

Error message

token refresh failed after %d attempts: %w

What it means

Error "token refresh failed after %d attempts: %w" thrown in router-for-me/CLIProxyAPI.

Source

Thrown at internal/auth/claude/anthropic_auth.go:661

			case <-ctx.Done():
				return nil, ctx.Err()
			case <-time.After(time.Duration(attempt) * time.Second):
			}
		}

		tokenData, err := o.RefreshTokens(ctx, refreshToken)
		if err == nil {
			return tokenData, nil
		}

		lastErr = err
		log.Warnf("Token refresh attempt %d failed: %v", attempt+1, err)
		if !isClaudeRefreshRetryable(err) {
			break
		}
	}

	return nil, fmt.Errorf("token refresh failed after %d attempts: %w", maxRetries, lastErr)
}

// UpdateTokenStorage updates an existing token storage with new token data.
// This method refreshes the token storage with newly obtained access and refresh tokens,
// updating timestamps and expiration information.
//
// Parameters:
//   - storage: The existing token storage to update
//   - tokenData: The new token data to apply
func (o *ClaudeAuth) UpdateTokenStorage(storage *ClaudeTokenStorage, tokenData *ClaudeTokenData) {
	storage.AccessToken = tokenData.AccessToken
	storage.RefreshToken = tokenData.RefreshToken
	storage.LastRefresh = time.Now().Format(time.RFC3339)
	if tokenData.Email != "" {
		storage.Email = tokenData.Email
	}
	if tokenData.AccountUUID != "" {
		storage.AccountUUID = tokenData.AccountUUID

View on GitHub (pinned to 78f0c4079e)

Solutions

  1. Inspect the final wrapped error: re-authenticate if the refresh token was revoked.
  2. Verify the token endpoint is reachable and retry after resolving the underlying failure.

When it happens

Trigger: Thrown at internal/auth/claude/anthropic_auth.go:661 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of router-for-me/CLIProxyAPI@78f0c4079e (2026-08-15). Data as JSON: /api/errors/4d7849cf9685d2c3. Report an issue: GitHub.