openai/codex · error · ApiError

api error

Error message

api error {status}: {message}

What it means

ApiError::Api variant: the backend HTTP API returned a non-success status that is not mapped to a more specific variant. Carries the raw status code and server-provided message; handling depends on the status (4xx terminal, 5xx may be retryable).

Solutions

  1. Check the status code and server message for the specific cause
  2. For 401/403 re-authenticate via `codex login`
  3. For 5xx retry after a delay
  4. For 4xx fix the request per the API error details
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at codex-rs/codex-api/src/error.rs:11 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of openai/codex@339751715c (2026-08-25). Data as JSON: /api/errors/c8df8054c8bf4df5. Report an issue: GitHub.

Appendix: source

Thrown at codex-rs/codex-api/src/error.rs:11

use crate::rate_limits::RateLimitError;
use codex_client::TransportError;
use http::StatusCode;
use std::time::Duration;
use thiserror::Error;

#[derive(Debug, Error)]
pub enum ApiError {
    #[error(transparent)]
    Transport(#[from] TransportError),
    #[error("api error {status}: {message}")]
    Api { status: StatusCode, message: String },
    #[error("stream error: {0}")]
    Stream(String),
    #[error("context window exceeded")]
    ContextWindowExceeded,
    #[error("quota exceeded")]
    QuotaExceeded,
    #[error("usage not included")]
    UsageNotIncluded,
    #[error("retryable error: {message}")]
    Retryable {
        message: String,
        delay: Option<Duration>,
    },
    #[error("rate limit: {0}")]
    RateLimit(String),
    #[error("invalid request: {message}")]
    InvalidRequest { message: String },

View on GitHub (pinned to 339751715c)