BerriAI/litellm · error · GetDeviceCodeError

Failed to request device code: {exc}

Error message

Failed to request device code: {exc}

What it means

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.

Source

Thrown at litellm/llms/chatgpt/authenticator.py:175

            flush=True,
        )
        auth_code: Final = self._poll_for_authorization_code(device_code)
        tokens: Final = self._exchange_code_for_tokens(auth_code)
        auth_data: Final = self._build_auth_record(tokens)
        self._write_auth_file(auth_data)
        return tokens

    def _request_device_code(self) -> dict[str, str]:
        try:
            client: Final = _get_httpx_client()
            resp: Final = client.post(
                CHATGPT_DEVICE_CODE_URL,
                json={"client_id": CHATGPT_CLIENT_ID},
            )
            resp.raise_for_status()
            data: Final = resp.json()
        except httpx.HTTPStatusError as exc:
            raise GetDeviceCodeError(
                message=f"Failed to request device code: {exc}",
                status_code=exc.response.status_code,
            )
        except Exception as exc:
            raise GetDeviceCodeError(
                message=f"Failed to request device code: {exc}",
                status_code=400,
            )

        device_auth_id: Final = data.get("device_auth_id")
        user_code: Final = data.get("user_code") or data.get("usercode")
        interval: Final = data.get("interval")
        if not device_auth_id or not user_code:
            raise GetDeviceCodeError(
                message=f"Device code response missing fields: {data}",
                status_code=400,
            )
        return {

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Retry after a short delay — transient 5xx/429 from the auth server usually clear.
  2. Upgrade litellm (`pip install -U litellm`) so the bundled client_id and device-flow URLs are current.
  3. Check https://status.openai.com for auth endpoint incidents.
  4. If behind a proxy, verify `HTTPS_PROXY` settings allow POSTs to OpenAI auth domains.
Defensive patterns

Strategy: retry

Try / catch

from litellm.llms.chatgpt.common_utils import GetDeviceCodeError

for attempt in range(3):
    try:
        device = authenticator._request_device_code()
        break
    except GetDeviceCodeError as e:
        if e.status_code and e.status_code >= 500 and attempt < 2:
            time.sleep(2 ** attempt)
            continue
        raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/195a48a633c45c4f. Report an issue: GitHub.