BerriAI/litellm · error · GetDeviceCodeError

Failed to request device code

Error message

Failed to request device code: {exc}

What it means

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.

Solutions

  1. Wait and retry the login after a minute — transient 429/5xx from the auth endpoint usually clears
  2. If it persists, upgrade litellm so the CHATGPT_CLIENT_ID and endpoint constants match what OpenAI currently ships
  3. 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
  4. Verify network egress to auth.openai.com is unmodified (no MITM proxy returning error pages)
Defensive patterns

Strategy: retry

Try / catch

from litellm.llms.chatgpt.authenticator import GetDeviceCodeError

for attempt in range(3):
    try:
        tokens = authenticator.login()
        break
    except GetDeviceCodeError as e:
        if e.status_code in (429, 500, 502, 503) and attempt < 2:
            time.sleep(2 ** attempt * 5)
            continue
        raise

Prevention

When it happens

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

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

Related errors


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

Appendix: 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 77b7c6c40c)