{"record":{"id":"16af285a94548881","repo":"openai/codex","slug":"context-window-exceeded","errorCode":null,"errorMessage":"context window exceeded","messagePattern":"context window exceeded","errorType":"exception","errorClass":"ApiError","httpStatus":null,"severity":"error","filePath":"codex-rs/codex-api/src/error.rs","lineNumber":15,"sourceCode":"use crate::rate_limits::RateLimitError;\nuse codex_client::TransportError;\nuse http::StatusCode;\nuse std::time::Duration;\nuse thiserror::Error;\n\n#[derive(Debug, Error)]\npub enum ApiError {\n    #[error(transparent)]\n    Transport(#[from] TransportError),\n    #[error(\"api error {status}: {message}\")]\n    Api { status: StatusCode, message: String },\n    #[error(\"stream error: {0}\")]\n    Stream(String),\n    #[error(\"context window exceeded\")]\n    ContextWindowExceeded,\n    #[error(\"quota exceeded\")]\n    QuotaExceeded,\n    #[error(\"usage not included\")]\n    UsageNotIncluded,\n    #[error(\"retryable error: {message}\")]\n    Retryable {\n        message: String,\n        delay: Option<Duration>,\n    },\n    #[error(\"rate limit: {0}\")]\n    RateLimit(String),\n    #[error(\"invalid request: {message}\")]\n    InvalidRequest { message: String },\n    #[error(\"cyber policy: {message}\")]\n    CyberPolicy { message: String },\n    #[error(\"misalignment policy violation: {message}\")]\n    MisalignmentPolicyViolation { message: String },","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/openai/codex/blob/339751715c64496cb86246bfb3935f40e309dd3d/codex-rs/codex-api/src/error.rs#L1-L33","documentation":"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.","triggerScenarios":"Thrown at codex-rs/codex-api/src/error.rs:15 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Start a new session or compact/summarize the context","Remove large attachments or long history items","Switch to a model with a larger context window"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"339751715c64496cb86246bfb3935f40e309dd3d","analyzedAt":"2026-08-25T05:35:09.876Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}