langchain-ai/deepagents · error · MissingCredentialsError

ChatGPT session expired. Run `/auth` and select openai_codex

Error message

ChatGPT session expired. Run `/auth` and select openai_codex to sign in again.

What it means

Raised as MissingCredentialsError when the Codex integration reports CodexAuthExpiredError: an auth token file exists but its refresh token is no longer accepted (refresh flow failed), i.e. the ChatGPT session has lapsed. It deliberately routes through the MissingCredentialsError recovery path instead of generic ModelConfigError so the retry flow re-attempts after the user signs in via `/auth`.

Source

Thrown at libs/code/deepagents_code/config.py:5911

        kwargs.pop("api_key", None)
        try:
            model = _codex.build_chat_model(model_name, **kwargs)
        except FileNotFoundError as exc:
            msg = (
                "Not signed in to ChatGPT. Run `/auth` and select "
                "openai_codex to sign in with your ChatGPT account."
            )
            raise MissingCredentialsError(msg, provider=provider, env_var=None) from exc
        except _codex.CodexAuthExpiredError as exc:
            # A token exists but its refresh token is dead. Route through the
            # same `MissingCredentialsError` recovery path as a missing token
            # (which the retry flow re-attempts after `/auth`) instead of the
            # generic `ModelConfigError` below, which would not offer sign-in.
            msg = (
                "ChatGPT session expired. Run `/auth` and select openai_codex "
                "to sign in again."
            )
            raise MissingCredentialsError(msg, provider=provider, env_var=None) from exc
        except Exception as exc:
            spec = f"{provider}:{model_name}"
            msg = f"Failed to initialize Codex model '{spec}': {exc}"
            raise ModelConfigError(msg) from exc
    elif class_path:
        model = _create_model_from_class(class_path, model_name, provider, kwargs)
    else:
        model = _create_model_via_init(model_name, provider, kwargs)

    resolved_provider = provider or getattr(model, "_model_provider", provider)
    from deepagents_code.cost_tracking import _set_configured_model_metadata

    _set_configured_model_metadata(model, model_name, resolved_provider)

    # Apply profile overrides from config.toml (e.g., max_input_tokens)
    if provider:
        config_profile_overrides = config.get_profile_overrides(
            provider, model_name=model_name

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Run `/auth`, select `openai_codex`, and sign in again to obtain a fresh token; the retry flow then re-attempts the request.
  2. Remove the stale auth file if `/auth` behaves oddly, then re-authenticate.
  3. Keep sessions alive by using dcode regularly, or re-auth proactively after account-level security changes.

Example fix

// inside dcode
/auth            # select openai_codex, complete browser sign-in
// previous request is then retried with the fresh token
Defensive patterns

Strategy: retry

Validate before calling

from deepagents_code import codex as _codex

def codex_auth_still_valid() -> bool:
    try:
        _codex.refresh_auth_if_needed()  # surfaces CodexAuthExpiredError early
        return True
    except _codex.CodexAuthExpiredError:
        return False

Try / catch

try:
    model = build_model("openai_codex", model_name)
except MissingCredentialsError as exc:
    if "expired" in str(exc).lower():
        run_auth_flow("openai_codex")  # re-sign in to get a fresh refresh token
        model = build_model("openai_codex", model_name)

Prevention

When it happens

Trigger: Building/refreshing an `openai_codex` model when `_codex.CodexAuthExpiredError` is raised by `_codex.build_chat_model` — the stored refresh token was revoked or expired (long idle period, password change, token rotated elsewhere, signing out of ChatGPT on another device).

Common situations: Returning to dcode after weeks of inactivity; ChatGPT account password reset or session revocation; copying an old auth file from a backup; multiple machines sharing one account where a newer sign-in invalidated older refresh tokens.

Related errors


AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29). Data as JSON: /api/errors/317b014577007254. Report an issue: GitHub.