openai/codex · error · ApiError

context window exceeded

Error message

context window exceeded

What it means

ApiError::ContextWindowExceeded sentinel: the request+history exceeds the model's context window. The server (or client heuristics) classified the failure as too-large input; callers should compact/trim history rather than retry unchanged.

Solutions

  1. Start a new session or compact/summarize the context
  2. Remove large attachments or long history items
  3. Switch to a model with a larger context window
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at codex-rs/codex-api/src/error.rs:15 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/16af285a94548881. Report an issue: GitHub.

Appendix: source

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

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 },
    #[error("cyber policy: {message}")]
    CyberPolicy { message: String },
    #[error("misalignment policy violation: {message}")]
    MisalignmentPolicyViolation { message: String },

View on GitHub (pinned to 339751715c)