{"record":{"id":"16e0fcb4fe26e5df","repo":"langchain-ai/deepagents","slug":"device-code-request-failed-http-response-status","errorCode":null,"errorMessage":"Device code request failed: HTTP {response.status_code} from {device_code_url}.","messagePattern":"Device code request failed: HTTP (.+?) from (.+?)\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/mcp_auth.py","lineNumber":1910,"sourceCode":"\n    init_data = {\"client_id\": client_id}\n    if scope is not None:\n        init_data[\"scope\"] = scope\n\n    async with httpx.AsyncClient(timeout=30.0) as client:\n        response = await client.post(\n            device_code_url,\n            data=init_data,\n            headers={\"Accept\": \"application/json\"},\n        )\n        try:\n            response.raise_for_status()\n        except httpx.HTTPStatusError as exc:\n            msg = (\n                f\"Device code request failed: HTTP {response.status_code} \"\n                f\"from {device_code_url}.\"\n            )\n            raise RuntimeError(msg) from exc\n        try:\n            device = _DeviceCodeResponse.model_validate(response.json())\n        except (ValueError, ValidationError) as exc:\n            msg = (\n                f\"Device code response from {device_code_url} is missing \"\n                f\"required fields: {exc}\"\n            )\n            raise RuntimeError(msg) from exc\n\n        await interaction.show_device_code(\n            verification_uri=device.verification_uri,\n            user_code=device.user_code,\n            expires_in=device.expires_in,\n        )\n\n        interval = max(device.interval, 1)\n        loop = asyncio.get_running_loop()\n        deadline = loop.time() + device.expires_in","sourceCodeStart":1892,"sourceCodeEnd":1928,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/mcp_auth.py#L1892-L1928","documentation":"During the OAuth device-authorization flow, the initial POST to the provider's device_code endpoint returned an HTTP error status; _run_device_flow converts httpx.HTTPStatusError into a RuntimeError naming the status code and endpoint. The device flow never starts because the provider rejected the device-code request itself.","triggerScenarios":"_run_device_flow (and tests like test_device_code_request_failure_raises) POST to device_code_url and receive 4xx/5xx; also called via _preseed_github_auth in tests.","commonSituations":"Wrong or missing client_id for the provider, incorrect device authorization endpoint URL in the server's OAuth metadata, network/proxy returning 4xx/5xx, provider outage, or rate limiting.","solutions":["Check the HTTP status in the message: 401/404 usually mean a wrong client_id or device endpoint; 429 means rate limited - back off and retry.","Verify the MCP server's OAuth metadata advertises the correct device_authorization_endpoint for your client_id.","Confirm network/proxy access to the endpoint (curl the device_code_url) and retry `/mcp login <server>`."],"exampleFix":"// before\ndevice_code_url = \"https://github.com/login/device/code2\"  # typo\n// after\ndevice_code_url = \"https://github.com/login/device/code\"  # per provider docs","handlingStrategy":"retry","validationCode":"# verify reachability and client_id before running the flow\nimport httpx\nresp = httpx.post(device_code_url, data={\"client_id\": client_id})\nresp.raise_for_status()  # surfaces the same 4xx/5xx before the library does","typeGuard":null,"tryCatchPattern":"try:\n    token = await _run_device_flow(...)\nexcept RuntimeError as e:\n    if str(e).startswith(\"Device code request failed\"):\n        if \"HTTP 429\" in str(e):\n            await asyncio.sleep(30)  # rate limited: back off and retry\n        else:\n            raise SystemExit(f\"Check client_id/device endpoint: {e}\")\n    else:\n        raise","preventionTips":["Confirm client_id and the device_authorization_endpoint against the provider's current docs.","Test endpoint reachability with curl before interactive login sessions.","Retry with backoff on 429/5xx; treat 401/404 as configuration errors, not transient."],"tags":["mcp","oauth","device-flow","http","network"],"backgroundTag":"device-code-request-failed","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}