unslothai/unsloth · error · CodexAuthError

Device login is unavailable. Enable device-code login in Cha

Error message

Device login is unavailable. Enable device-code login in ChatGPT settings.

What it means

Raised as CodexAuthError when the initial POST to the device-code endpoint returns HTTP >= 400. Unlike the polling-stage errors, any 4xx/5xx here means the device grant itself was refused before a user code was even issued. The message targets the dominant cause — the account/server rejecting the codex device grant — rather than enumerating server codes.

Source

Thrown at studio/backend/core/inference/openai_codex_auth.py:510

        await _persist_terminal_flow(flow)


async def _start_device_flow(
    provider_id: str,
    persist_bundle: Callable[[str, dict[str, Any]], Awaitable[None] | None],
    marker: str = "",
) -> OAuthFlow:
    try:
        async with httpx.AsyncClient(
            timeout = 30.0, follow_redirects = False, trust_env = False
        ) as client:
            response = await client.post(
                OPENAI_CODEX_DEVICE_CODE_URL, json = {"client_id": OPENAI_CODEX_CLIENT_ID}
            )
    except httpx.HTTPError as exc:
        raise CodexAuthError("Could not reach ChatGPT authentication.") from exc
    if response.status_code >= 400:
        raise CodexAuthError(
            "Device login is unavailable. Enable device-code login in ChatGPT settings."
        )
    try:
        body = response.json()
        device_auth_id = body["device_auth_id"]
        user_code = body["user_code"]
        verification_url = (
            body.get("verification_uri_complete")
            or body.get("verification_uri")
            or "https://auth.openai.com/codex/device"
        )
    except Exception as exc:
        raise CodexAuthError("ChatGPT returned an invalid device authorization response.") from exc
    flow = OAuthFlow(
        id = secrets.token_urlsafe(24),
        provider_id = provider_id,
        method = "device",
        created_at = time.time(),

View on GitHub (pinned to 203007d190)

Solutions

  1. Enable device-code login in ChatGPT settings and retry.
  2. If still refused, use the browser loopback flow, which does not depend on the device grant.
  3. Update Studio to pick up current client constants.
  4. Check OpenAI status page for auth endpoint incidents if the failure is sudden and account-wide.

Example fix

// before
flow = await codex_auth.start_device_flow(provider_id, persist_bundle)

// after
try:
    flow = await codex_auth.start_device_flow(provider_id, persist_bundle)
except codex_auth.CodexAuthError as exc:
    if "Device login is unavailable" in str(exc):
        flow = await codex_auth.start_browser_flow(provider_id, persist_bundle)
Defensive patterns

Strategy: fallback

Type guard

def is_device_unavailable(exc: BaseException) -> bool:
    return isinstance(exc, codex_auth.CodexAuthError) and "Device login is unavailable" in str(exc)

Try / catch

try:
    flow = await start_device_flow(provider_id, persist_bundle)
except codex_auth.CodexAuthError as exc:
    if "Device login is unavailable" in str(exc):
        flow = await start_browser_flow(provider_id, persist_bundle)
    else:
        raise

Prevention

When it happens

Trigger: The device authorization endpoint rejecting the client_id (400/401 invalid_client); the codex device grant disabled server-side for this account or region (403); 5xx during outages; malformed or outdated client id constant sent in the request body.

Common situations: Device-code login not enabled for the ChatGPT account (the message's explicit hint); OpenAI account policy or plan restrictions; library version with a stale OPENAI_CODEX_CLIENT_ID; temporary endpoint outages.

Related errors


AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15). Data as JSON: /api/errors/3f2646d6bbc6cec9. Report an issue: GitHub.