mirror of
https://github.com/openai/codex.git
synced 2026-11-19 22:30:42 +00:00
Report API spend limit errors by scope (#62329)
## Why Generic quota errors hide whether the project or organization spend limit blocked a request. Reporting the scope tells users which limit to check. ## What changed Recognize API key, project, and organization spend limit errors across HTTP, SSE, and WebSocket responses. Show a message that names the scope and treat the error as non-retryable, even when the provider sends `Retry-After`. Apply the existing usage-limit handling to goals and compaction. Expose distinct `CodexErrorInfo` values in the app-server protocol and generated bindings so clients can identify the limit in live errors and failed turn history. ## Testing Extend the transport tests to cover all three scopes and verify that they stop retries. Extend the app-server test to check that the error survives `thread/read` and that a subsequent turn can succeed in the same thread. GitOrigin-RevId: 03341f7a78daa7540e7baa519f1a29ec07e34509
This commit is contained in:
@@ -2,6 +2,7 @@ use crate::rate_limits::RateLimitError;
|
||||
use codex_client::TransportError;
|
||||
use codex_http_client::RetryAfter;
|
||||
use codex_protocol::error::ResponseIncompleteError;
|
||||
use codex_protocol::error::SpendLimitScope;
|
||||
use codex_protocol::protocol::MisalignmentErrorDetails;
|
||||
use http::StatusCode;
|
||||
use serde_json::Value;
|
||||
@@ -25,6 +26,8 @@ pub enum ApiError {
|
||||
ContextWindowExceeded,
|
||||
#[error("quota exceeded")]
|
||||
QuotaExceeded,
|
||||
#[error("spend limit exceeded")]
|
||||
SpendLimitExceeded(SpendLimitScope),
|
||||
#[error("usage not included")]
|
||||
UsageNotIncluded,
|
||||
#[error("session budget exceeded")]
|
||||
@@ -100,6 +103,16 @@ pub(crate) fn parse_terminal_provider_error(
|
||||
.and_then(Value::as_str)
|
||||
.filter(|message| !message.trim().is_empty());
|
||||
match (code, status) {
|
||||
("api_key_spend_limit_exceeded", None | Some(StatusCode::TOO_MANY_REQUESTS)) => {
|
||||
Some(ApiError::SpendLimitExceeded(SpendLimitScope::ApiKey))
|
||||
}
|
||||
("project_spend_limit_exceeded", None | Some(StatusCode::TOO_MANY_REQUESTS)) => {
|
||||
Some(ApiError::SpendLimitExceeded(SpendLimitScope::Project))
|
||||
}
|
||||
("organization_spend_limit_exceeded", None | Some(StatusCode::TOO_MANY_REQUESTS)) => {
|
||||
Some(ApiError::SpendLimitExceeded(SpendLimitScope::Organization))
|
||||
}
|
||||
|
||||
("inference_hook_denied", None | Some(StatusCode::FORBIDDEN)) => {
|
||||
Some(ApiError::InferenceHookDenied {
|
||||
message: message
|
||||
|
||||
Reference in New Issue
Block a user