{"record":{"id":"195a48a633c45c4f","repo":"BerriAI/litellm","slug":"failed-to-request-device-code-exc","errorCode":null,"errorMessage":"Failed to request device code: {exc}","messagePattern":"Failed to request device code: (.+?)","errorType":"exception","errorClass":"GetDeviceCodeError","httpStatus":null,"severity":"error","filePath":"litellm/llms/chatgpt/authenticator.py","lineNumber":175,"sourceCode":"            flush=True,\n        )\n        auth_code: Final = self._poll_for_authorization_code(device_code)\n        tokens: Final = self._exchange_code_for_tokens(auth_code)\n        auth_data: Final = self._build_auth_record(tokens)\n        self._write_auth_file(auth_data)\n        return tokens\n\n    def _request_device_code(self) -> dict[str, str]:\n        try:\n            client: Final = _get_httpx_client()\n            resp: Final = client.post(\n                CHATGPT_DEVICE_CODE_URL,\n                json={\"client_id\": CHATGPT_CLIENT_ID},\n            )\n            resp.raise_for_status()\n            data: Final = resp.json()\n        except httpx.HTTPStatusError as exc:\n            raise GetDeviceCodeError(\n                message=f\"Failed to request device code: {exc}\",\n                status_code=exc.response.status_code,\n            )\n        except Exception as exc:\n            raise GetDeviceCodeError(\n                message=f\"Failed to request device code: {exc}\",\n                status_code=400,\n            )\n\n        device_auth_id: Final = data.get(\"device_auth_id\")\n        user_code: Final = data.get(\"user_code\") or data.get(\"usercode\")\n        interval: Final = data.get(\"interval\")\n        if not device_auth_id or not user_code:\n            raise GetDeviceCodeError(\n                message=f\"Device code response missing fields: {data}\",\n                status_code=400,\n            )\n        return {","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/chatgpt/authenticator.py#L157-L193","documentation":"GetDeviceCodeError raised by litellm's ChatGPT OAuth authenticator when the initial POST to the device-code endpoint (CHATGPT_DEVICE_CODE_URL, auth.openai.com) returns an HTTP error status. This is step one of the 'Sign in with ChatGPT' device-code flow; resp.raise_for_status() fires and the HTTPStatusError is wrapped with the upstream status code attached. The message embeds the underlying httpx error string so you can see the exact status and URL.","triggerScenarios":"Starting ChatGPT OAuth login (e.g. litellm's chatgpt auth path calling _login_device_code -> _request_device_code) and the device-code endpoint responding 4xx/5xx — rate limiting (429), bad request, or upstream 5xx.","commonSituations":"OpenAI temporarily rate-limiting device-code requests after repeated logins; a corporate proxy or firewall rewriting the response; litellm version drift where the endpoint or client_id changed; region blocks on auth.openai.com.","solutions":["Wait and retry the login after a minute — transient 429/5xx from the auth endpoint usually clears","If it persists, upgrade litellm so the CHATGPT_CLIENT_ID and endpoint constants match what OpenAI currently ships","Check the embedded status code in the message: 429 means back off longer; 4xx other than 429 suggests a client/endpoint mismatch fixed by upgrading","Verify network egress to auth.openai.com is unmodified (no MITM proxy returning error pages)"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"from litellm.llms.chatgpt.authenticator import GetDeviceCodeError\n\nfor attempt in range(3):\n    try:\n        tokens = authenticator.login()\n        break\n    except GetDeviceCodeError as e:\n        if e.status_code in (429, 500, 502, 503) and attempt < 2:\n            time.sleep(2 ** attempt * 5)\n            continue\n        raise","preventionTips":["Run device login rarely; persist the auth file/tokens and refresh instead of re-authenticating each run","Do not launch concurrent device logins from one host to avoid 429s","Keep litellm updated so the client_id matches OpenAI's current OAuth app"],"tags":["chatgpt","oauth","device-code","http-status","auth"],"backgroundTag":"oauth-device-flow-failed","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}