{"record":{"id":"a82d046076c836eb","repo":"router-for-me/CLIProxyAPI","slug":"token-exchange-failed-with-status-d-s","errorCode":null,"errorMessage":"token exchange failed with status %d: %s","messagePattern":"token exchange failed with status (.+?): (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/auth/claude/anthropic_auth.go","lineNumber":423,"sourceCode":"\n\tresp, err := o.httpClient.Do(req)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"token exchange request failed: %w\", err)\n\t}\n\tdefer func() {\n\t\tif errClose := resp.Body.Close(); errClose != nil {\n\t\t\tlog.Errorf(\"failed to close response body: %v\", errClose)\n\t\t}\n\t}()\n\n\tbody, err := readClaudeOAuthResponseBody(resp)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to read token response: %w\", err)\n\t}\n\t// log.Debugf(\"Token response: %s\", string(body))\n\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"token exchange failed with status %d: %s\", resp.StatusCode, string(body))\n\t}\n\t// log.Debugf(\"Token response: %s\", string(body))\n\n\tvar tokenResp tokenResponse\n\tif err = json.Unmarshal(body, &tokenResp); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to parse token response: %w\", err)\n\t}\n\n\tdeviceIDs, errDeviceIDs := GenerateDeviceIDPool()\n\tif errDeviceIDs != nil {\n\t\treturn nil, errDeviceIDs\n\t}\n\n\t// Create token data.\n\ttokenData := ClaudeTokenData{\n\t\tAccessToken:      tokenResp.AccessToken,\n\t\tRefreshToken:     tokenResp.RefreshToken,\n\t\tEmail:            tokenResp.Account.EmailAddress,","sourceCodeStart":405,"sourceCodeEnd":441,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/auth/claude/anthropic_auth.go#L405-L441","documentation":"Error \"token exchange failed with status %d: %s\" thrown in router-for-me/CLIProxyAPI.","triggerScenarios":"Thrown at internal/auth/claude/anthropic_auth.go:423 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the status code and response body: re-authenticate on 400/401 (invalid grant or expired code).","Verify the client ID, redirect URI, and PKCE verifier match the original authorization request."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}