openai/codex · error · RequestError

thread usage response did not contain requested thread

Error message

thread usage response did not contain requested thread {thread_id}

What it means

Consistency error in get_thread_usage: the backend answered the usage query successfully, but the returned totals contain no entry for the thread id that was requested (e.g. the thread was pruned or the response is for different threads). Rather than attributing another thread's usage, the accessor fails with the requested thread id in the message.

Solutions

  1. Verify the thread id exists and was created on the same backend/account
  2. Treat the thread as having no usage data and handle the missing-entry case explicitly instead of retrying blindly
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at codex-rs/backend-client/src/client/thread_usage.rs:68 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/ffbc04fcc99e6e53. Report an issue: GitHub.

Appendix: source

Thrown at codex-rs/backend-client/src/client/thread_usage.rs:68

        let url = self.thread_usage_url();
        let request = self
            .request(Method::POST, &url)
            .headers(self.headers())
            .header(CONTENT_TYPE, HeaderValue::from_static("application/json"))
            .json(&ThreadUsageQueryRequest {
                thread_ids: [thread_id],
            });
        let (body, content_type) = self.exec_request_detailed(request, "POST", &url).await?;
        let response = self
            .decode_json::<ThreadUsageQueryResponse>(&url, &content_type, &body)
            .map_err(RequestError::from)?;

        response
            .threads
            .into_iter()
            .find(|usage| usage.thread_id == thread_id)
            .ok_or_else(|| {
                RequestError::from(anyhow!(
                    "thread usage response did not contain requested thread {thread_id}"
                ))
            })
    }

    fn thread_usage_url(&self) -> String {
        match self.path_style {
            PathStyle::CodexApi => {
                format!("{}/api/codex/usage/thread_usage/query", self.base_url)
            }
            PathStyle::ChatGptApi => {
                format!("{}/wham/usage/thread_usage/query", self.base_url)
            }
        }
    }
}

#[cfg(test)]

View on GitHub (pinned to 339751715c)