{"record":{"id":"743f808ecc2097c6","repo":"langchain-ai/deepagents","slug":"token-request-failed-http-token-response-status","errorCode":null,"errorMessage":"Token request failed: HTTP {token_response.status_code} from {token_url}.","messagePattern":"Token request failed: HTTP (.+?) from (.+?)\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/mcp_auth.py","lineNumber":1971,"sourceCode":"                )\n                body = {}\n            err = body.get(\"error\")\n            if err == \"authorization_pending\":\n                continue\n            if err == \"slow_down\":\n                interval += 5\n                continue\n            if err:\n                msg = f\"Device flow failed: {err}: {body.get('error_description', '')}\"\n                raise RuntimeError(msg)\n            try:\n                token_response.raise_for_status()\n            except httpx.HTTPStatusError as exc:\n                msg = (\n                    f\"Token request failed: HTTP {token_response.status_code} \"\n                    f\"from {token_url}.\"\n                )\n                raise RuntimeError(msg) from exc\n            try:\n                return OAuthToken.model_validate(body)\n            except ValidationError as exc:\n                msg = (\n                    f\"Token response from {token_url} is not a valid \"\n                    f\"OAuth token payload: {exc}\"\n                )\n                raise RuntimeError(msg) from exc\n\n    msg = \"Device flow timed out. Try logging in again.\"\n    raise RuntimeError(msg)\n\n\ndef format_login_failure(exc: BaseException) -> str:\n    \"\"\"Return a token-safe single-line summary of an OAuth-login exception.\n\n    OAuth handshakes commonly surface as `ExceptionGroup` (anyio task\n    groups) or as MCP-SDK errors whose `args`/`repr` may include an","sourceCodeStart":1953,"sourceCodeEnd":1989,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/mcp_auth.py#L1953-L1989","documentation":"`_run_device_flow` raises this RuntimeError when the HTTP request to exchange the device code for an OAuth token returns a non-2xx status that is not part of the expected polling protocol. The raw status code and token URL are surfaced to make the failing endpoint identifiable.","triggerScenarios":"The POST to the GitHub token URL returns an unexpected HTTP status (e.g. 403 rate-limit response, 500 server error, or a proxy 407) instead of 200-with-error-field or the tolerated 400 pending responses handled earlier in the loop.","commonSituations":"Corporate proxy intercepts github.com traffic; GitHub API rate limiting; transient GitHub outage; a firewall or SSL-terminating middlebox rewrites the response; misconfigured GITHUB_API_URL-like base URL override pointing at a non-GitHub server.","solutions":["Check the HTTP status in the message — 4xx from a proxy usually means network/proxy misconfiguration, not an auth problem","Retry the login; transient 5xx/429 responses from GitHub often resolve on retry","Verify any base-URL override or HTTPS_PROXY/HTTP_PROXY env vars point at a working endpoint that forwards to github.com","If persistent, check GitHub status (githubstatus.com) for an ongoing incident"],"exampleFix":"// before: restrictive proxy blocking the token endpoint\nexport HTTPS_PROXY=http://proxy.corp:8080  # blocks github.com/login/oauth\n// after\nexport NO_PROXY=github.com  # or allowlist github.com on the proxy","handlingStrategy":"retry","validationCode":"# Pre-check connectivity to the token host before login\nimport httpx\ntry:\n    httpx.head(\"https://github.com\", timeout=10).raise_for_status()\nexcept httpx.HTTPStatusError as exc:\n    print(f\"github.com unreachable via current proxy: {exc}\")","typeGuard":null,"tryCatchPattern":"try:\n    login(server_name)\nexcept RuntimeError as exc:\n    if \"Token request failed: HTTP\" in str(exc):\n        status = int(str(exc).split(\"HTTP \")[1].split()[0])\n        if status in (429, 500, 502, 503, 504):\n            time.sleep(5)\n            login(server_name)  # transient — retry\n    raise","preventionTips":["Configure HTTPS_PROXY/NO_PROXY so github.com is reachable directly","Retry login on 5xx/429 statuses; they are usually transient","Check githubstatus.com before diagnosing auth failures"],"tags":["oauth","http-status","github","network"],"backgroundTag":"token-endpoint-http-error","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}