mirror of
https://github.com/openai/codex.git
synced 2026-12-03 00:41:03 +00:00
## Why Clients need to show the spend and cap for the account behind a thread's model provider. The existing ChatGPT usage read cannot provide those figures for a gateway account. ## What changed - Route `account/rateLimits/read` through the provider's configured `usage_url` using the provider's credentials. An optional `threadId` selects a loaded thread's provider for the account-wide read. Omitting it selects the default provider. - Return `usageUnavailable` for a thread whose provider has neither a usage endpoint nor first-party authentication. Surface gateway errors without falling back to ChatGPT usage. - Report monthly gateway spend in `individualLimit` as exact USD decimal strings, with `limit: "unlimited"` for uncapped accounts. Use `spendControlReached` for the gateway's cap status. Spend snapshots identify their unit as `usd` or `credit`, with omitted units defaulting to `credit` for compatibility. ## Testing Add integration coverage for thread-specific provider selection, gateway usage taking precedence over ChatGPT without fallback, and reuse of an existing gateway OAuth session without interactive login. GitOrigin-RevId: e6ec9d83eecc3084fcc98e72e2c031bd3e53a2cd
359 lines
8.6 KiB
JSON
Generated
359 lines
8.6 KiB
JSON
Generated
{
|
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
"definitions": {
|
|
"CreditsSnapshot": {
|
|
"properties": {
|
|
"balance": {
|
|
"type": [
|
|
"string",
|
|
"null"
|
|
]
|
|
},
|
|
"hasCredits": {
|
|
"type": "boolean"
|
|
},
|
|
"unlimited": {
|
|
"type": "boolean"
|
|
}
|
|
},
|
|
"required": [
|
|
"hasCredits",
|
|
"unlimited"
|
|
],
|
|
"type": "object"
|
|
},
|
|
"PlanType": {
|
|
"enum": [
|
|
"free",
|
|
"go",
|
|
"plus",
|
|
"pro",
|
|
"prolite",
|
|
"promax",
|
|
"team",
|
|
"self_serve_business_prolite",
|
|
"self_serve_business_usage_based",
|
|
"business",
|
|
"ent26",
|
|
"enterprise_cbp_automation",
|
|
"enterprise_cbp_usage_based",
|
|
"enterprise",
|
|
"edu",
|
|
"edu_plus",
|
|
"edu_pro",
|
|
"sci",
|
|
"sci_plus",
|
|
"unknown"
|
|
],
|
|
"type": "string"
|
|
},
|
|
"RateLimitReachedType": {
|
|
"enum": [
|
|
"rate_limit_reached",
|
|
"workspace_owner_credits_depleted",
|
|
"workspace_member_credits_depleted",
|
|
"workspace_owner_usage_limit_reached",
|
|
"workspace_member_usage_limit_reached"
|
|
],
|
|
"type": "string"
|
|
},
|
|
"RateLimitResetCredit": {
|
|
"properties": {
|
|
"description": {
|
|
"description": "Backend-provided display description for this credit, or `null` when unavailable.",
|
|
"type": [
|
|
"string",
|
|
"null"
|
|
]
|
|
},
|
|
"expiresAt": {
|
|
"description": "Unix timestamp in seconds when the credit expires, or `null` if it does not expire.",
|
|
"format": "int64",
|
|
"type": [
|
|
"integer",
|
|
"null"
|
|
]
|
|
},
|
|
"grantedAt": {
|
|
"description": "Unix timestamp in seconds when the credit was granted.",
|
|
"format": "int64",
|
|
"type": "integer"
|
|
},
|
|
"id": {
|
|
"description": "Opaque backend identifier for this reset credit.",
|
|
"type": "string"
|
|
},
|
|
"resetType": {
|
|
"$ref": "#/definitions/RateLimitResetType"
|
|
},
|
|
"status": {
|
|
"$ref": "#/definitions/RateLimitResetCreditStatus"
|
|
},
|
|
"title": {
|
|
"description": "Backend-provided display title for this credit, or `null` when unavailable.",
|
|
"type": [
|
|
"string",
|
|
"null"
|
|
]
|
|
}
|
|
},
|
|
"required": [
|
|
"grantedAt",
|
|
"id",
|
|
"resetType",
|
|
"status"
|
|
],
|
|
"type": "object"
|
|
},
|
|
"RateLimitResetCreditStatus": {
|
|
"enum": [
|
|
"available",
|
|
"redeeming",
|
|
"redeemed",
|
|
"unknown"
|
|
],
|
|
"type": "string"
|
|
},
|
|
"RateLimitResetCreditsSummary": {
|
|
"properties": {
|
|
"availableCount": {
|
|
"format": "int64",
|
|
"type": "integer"
|
|
},
|
|
"credits": {
|
|
"description": "Detail rows for available reset credits, when the backend provides them.\n\n`null` means only `availableCount` is known, while an empty array means details were fetched and no available credits were returned. The backend may cap this list, so its length can be less than `availableCount`.",
|
|
"items": {
|
|
"$ref": "#/definitions/RateLimitResetCredit"
|
|
},
|
|
"type": [
|
|
"array",
|
|
"null"
|
|
]
|
|
}
|
|
},
|
|
"required": [
|
|
"availableCount"
|
|
],
|
|
"type": "object"
|
|
},
|
|
"RateLimitResetType": {
|
|
"enum": [
|
|
"codexRateLimits",
|
|
"unknown"
|
|
],
|
|
"type": "string"
|
|
},
|
|
"RateLimitSnapshot": {
|
|
"properties": {
|
|
"credits": {
|
|
"anyOf": [
|
|
{
|
|
"$ref": "#/definitions/CreditsSnapshot"
|
|
},
|
|
{
|
|
"type": "null"
|
|
}
|
|
]
|
|
},
|
|
"individualLimit": {
|
|
"anyOf": [
|
|
{
|
|
"$ref": "#/definitions/SpendControlLimitSnapshot"
|
|
},
|
|
{
|
|
"type": "null"
|
|
}
|
|
]
|
|
},
|
|
"limitId": {
|
|
"type": [
|
|
"string",
|
|
"null"
|
|
]
|
|
},
|
|
"limitName": {
|
|
"type": [
|
|
"string",
|
|
"null"
|
|
]
|
|
},
|
|
"normalModelSlug": {
|
|
"description": "Normal model whose display name and reasoning options describe this quota alias.",
|
|
"type": [
|
|
"string",
|
|
"null"
|
|
]
|
|
},
|
|
"planType": {
|
|
"anyOf": [
|
|
{
|
|
"$ref": "#/definitions/PlanType"
|
|
},
|
|
{
|
|
"type": "null"
|
|
}
|
|
]
|
|
},
|
|
"primary": {
|
|
"anyOf": [
|
|
{
|
|
"$ref": "#/definitions/RateLimitWindow"
|
|
},
|
|
{
|
|
"type": "null"
|
|
}
|
|
]
|
|
},
|
|
"rateLimitReachedType": {
|
|
"anyOf": [
|
|
{
|
|
"$ref": "#/definitions/RateLimitReachedType"
|
|
},
|
|
{
|
|
"type": "null"
|
|
}
|
|
]
|
|
},
|
|
"secondary": {
|
|
"anyOf": [
|
|
{
|
|
"$ref": "#/definitions/RateLimitWindow"
|
|
},
|
|
{
|
|
"type": "null"
|
|
}
|
|
]
|
|
},
|
|
"spendControlReached": {
|
|
"description": "Backend-reported spend-control state. `None` is unavailable, not a sparse-update recovery.",
|
|
"type": [
|
|
"boolean",
|
|
"null"
|
|
]
|
|
}
|
|
},
|
|
"type": "object"
|
|
},
|
|
"RateLimitWindow": {
|
|
"properties": {
|
|
"resetsAt": {
|
|
"format": "int64",
|
|
"type": [
|
|
"integer",
|
|
"null"
|
|
]
|
|
},
|
|
"usedPercent": {
|
|
"format": "int32",
|
|
"type": "integer"
|
|
},
|
|
"windowDurationMins": {
|
|
"format": "int64",
|
|
"type": [
|
|
"integer",
|
|
"null"
|
|
]
|
|
}
|
|
},
|
|
"required": [
|
|
"usedPercent"
|
|
],
|
|
"type": "object"
|
|
},
|
|
"SpendControlLimitSnapshot": {
|
|
"properties": {
|
|
"limit": {
|
|
"description": "Decimal amount, or \"unlimited\" when the provider has no spend cap.",
|
|
"type": "string"
|
|
},
|
|
"remainingPercent": {
|
|
"description": "For an unlimited cap this is 100 for compatibility. Ignore it for display and warnings.",
|
|
"format": "int32",
|
|
"type": "integer"
|
|
},
|
|
"resetsAt": {
|
|
"format": "int64",
|
|
"type": "integer"
|
|
},
|
|
"unit": {
|
|
"allOf": [
|
|
{
|
|
"$ref": "#/definitions/SpendControlUnit"
|
|
}
|
|
],
|
|
"default": "credit",
|
|
"description": "Unit of `used` and any numeric `limit`. Older servers omit this for credits."
|
|
},
|
|
"used": {
|
|
"type": "string"
|
|
}
|
|
},
|
|
"required": [
|
|
"limit",
|
|
"remainingPercent",
|
|
"resetsAt",
|
|
"used"
|
|
],
|
|
"type": "object"
|
|
},
|
|
"SpendControlUnit": {
|
|
"enum": [
|
|
"credit",
|
|
"usd"
|
|
],
|
|
"type": "string"
|
|
}
|
|
},
|
|
"properties": {
|
|
"accountId": {
|
|
"description": "Account associated with this usage snapshot, when supplied by the backend.",
|
|
"type": [
|
|
"string",
|
|
"null"
|
|
]
|
|
},
|
|
"ordinaryUsageAllowed": {
|
|
"description": "Backend permission for ordinary included usage, validated against the active account. Null means unavailable; clients must not infer recovery from percentages or reset times.",
|
|
"type": [
|
|
"boolean",
|
|
"null"
|
|
]
|
|
},
|
|
"rateLimitResetCredits": {
|
|
"anyOf": [
|
|
{
|
|
"$ref": "#/definitions/RateLimitResetCreditsSummary"
|
|
},
|
|
{
|
|
"type": "null"
|
|
}
|
|
]
|
|
},
|
|
"rateLimitUpsell": {
|
|
"description": "Optional backend-owned banner from the same usage read. Its nested keys retain the backend's snake_case contract; an absent banner leaves the client's existing UI unchanged."
|
|
},
|
|
"rateLimits": {
|
|
"allOf": [
|
|
{
|
|
"$ref": "#/definitions/RateLimitSnapshot"
|
|
}
|
|
],
|
|
"description": "Backward-compatible single-bucket view; mirrors the historical payload."
|
|
},
|
|
"rateLimitsByLimitId": {
|
|
"additionalProperties": {
|
|
"$ref": "#/definitions/RateLimitSnapshot"
|
|
},
|
|
"description": "Multi-bucket view keyed by metered `limit_id` (for example, `codex`).",
|
|
"type": [
|
|
"object",
|
|
"null"
|
|
]
|
|
}
|
|
},
|
|
"required": [
|
|
"rateLimits"
|
|
],
|
|
"title": "GetAccountRateLimitsResponse",
|
|
"type": "object"
|
|
} |