{"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/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/chatgpt/authenticator.py#L157-L193","documentation":"Raised as `GetDeviceCodeError` when the ChatGPT OAuth device-code initiation request (`POST` to `CHATGPT_DEVICE_CODE_URL`) returns an HTTP error status. This is the first step of ChatGPT's device-login flow; the HTTP status from OpenAI's auth server is propagated as the error's status_code.","triggerScenarios":"Starting `litellm` login for the `chatgpt` provider (`authenticator.get_access_token()` triggering device flow) while OpenAI's auth endpoint responds 4xx/5xx — e.g. invalid client_id, rate limiting (429), or auth server outage.","commonSituations":"First-time `chatgpt` provider setup; corporate proxies or firewalls altering the request so the server rejects it; OpenAI temporarily disabling device auth; running an outdated litellm version whose hardcoded `CHATGPT_CLIENT_ID` OpenAI no longer accepts.","solutions":["Retry after a short delay — transient 5xx/429 from the auth server usually clear.","Upgrade litellm (`pip install -U litellm`) so the bundled client_id and device-flow URLs are current.","Check https://status.openai.com for auth endpoint incidents.","If behind a proxy, verify `HTTPS_PROXY` settings allow POSTs to OpenAI auth domains."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"from litellm.llms.chatgpt.common_utils import GetDeviceCodeError\n\nfor attempt in range(3):\n    try:\n        device = authenticator._request_device_code()\n        break\n    except GetDeviceCodeError as e:\n        if e.status_code and e.status_code >= 500 and attempt < 2:\n            time.sleep(2 ** attempt)\n            continue\n        raise","preventionTips":["Keep litellm updated so device-flow client IDs stay valid.","Check OpenAI auth endpoint status before starting login in automation.","Wrap interactive login in retry-with-backoff for 5xx/429 only."],"tags":["chatgpt","oauth","device-flow","network","auth"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}