翻篇收录说明
翻篇网页快照

API Credit & Rate Limits - Handle 402 and 429 Errors

https://openrouter.ai/docs/api_reference/limits

最近抓取:2026-12-04 13:28:03(北京时间)

最近内容变化:2026-12-04 13:28:03(北京时间)

这是最近一次有效抓取的文本快照,不含网页脚本、图片和动态交互内容。实际网页可能已更新。

访问原网页

页面简介

Credit Limits and Rate Limits

正文摘录

Making additional accounts or API keys will not affect your rate limits, as we govern capacity globally. We do however have different rate limits for different models, so you can share the load that way if you do run into issues. OpenRouter enforces three kinds of limits: Limit typeWhat it governsError on exceedingWhere to checkCredit limitsHow much you can spend (account balance, per-key credit caps, and the in-flight spending budget)402GET /api/v1/key → limit_remaining; error.metadata.limit_source on the error responseBudget limitsSpend caps an org admin configured: guardrail budgets, workspace budgets, and the key’s own limit once it is spent403GET /api/v1/key → budgets and effective_budget; error.metadata on the error responseRate limitsHow many requests you can make (free-model request caps, key-management caps, per-IP burst limits, and DDoS protection)429X-RateLimit-* headers on free-model and key-management errors Checking your limits To check the rate limit or credits left on an API key, make a GET request to https://openrouter.ai/api/v1/key. TypeScript SDKPythonTypeScript (Raw API)GocURLimport { OpenRouter } from '@openrouter/sdk'; const openRouter = new OpenRouter({ apiKey: '<OPENROUTER_API_KEY>', }); const keyInfo = await openRouter.apiKeys.getCurrentKeyMetadata(); console.log(keyInfo); Output{ data: { label: "<OPENROUTER_API_KEY>...6ed", is_management_key: false, is_provisioning_key: false, limit: 500, limit_reset: "weekly", limit_remaining: 406.54343450199997, include_byok_in_limit: false, budgets: [ [Object ...], [Object ...] ], effective_budget: { scope: "key_limit", guardrail_id: null, budget_id: null, limit_usd: 500, spend_usd: 93.456565498, remaining_usd: 406.54343450199997, reset_interval: "weekly", resets_at: "2026-11-23T00:00:00.000Z", include_byok: false, }, usage: 420.006262049, usage_daily: 93.456565498, usage_weekly: 93.456565498, usage_monthly: 420.006262049, byok_usage: 0, byok_usage_daily: 0, byok_usage_weekly: 0, byok_usage_monthly: 0, is_free_tier: false, expires_at: null, creator_user_id: null, organization_id: "org_2uMVNwONqhSdZXQy1QtyWuCjTxZ", workspace_id: "b04919e8-b623-5ca1-a91f-01007c41d2c6", allowed_data_regions: [ "global", "europe", "us" ], free_model_daily_requests: { used: 1004, limit: 1000, If you submit a valid API key, you should get a response of the form: TypeScriptPythonGocURL// One budget that applies to requests made with the key (see Budget limits below) type Budget = { scope: 'workspace_default_member' | 'workspace_default_key' | 'member' | 'api_key' | 'workspace' | 'key_limit'; guardrail_id: string | null; // Set for guardrail scopes budget_id: string | null; // Set for the workspace scope limit_usd: number; spend_usd: number; // Spend counted against the limit in the current window remaining_usd: number; // limit_usd - spend_usd; zero or negative blocks requests reset_interval: 'daily' | 'weekly' | 'monthly' | null; // null never resets resets_at: string | null; // ISO 8601 UTC instant the window rolls over, or null include_byok: boolean; // Whether external BYOK spend counts toward this budget }; type Key = { data: { label: string; limit: number | null; // Credit limit for the key, or null if unlimited limit_reset: string | null; // Type of limit reset for the key, or null if never resets limit_remaining: number | null; // Remaining credits for the key, or null if unlimited include_byok_in_limit: boolean; // Whether to include external BYOK usage in the credit limit budgets: Budget[]; // Every budget enforced for this key, in the order enforcement checks them effective_budget: Budget | null; // The budget that blocks requests first, or null if none usage: number; // Number of credits used (all time) usage_daily: number; // Number of credits used (current UTC day) usage_weekly: number; // ... (current UTC week, starting Monday) usage_monthly: number; // ... (current UTC month) byok_usage: number; // Same for external BYOK usage byok_usage_daily: number; byok_usage_weekly: number; byok_usage_monthly: number; is_free_tier: boolean; // Whether the user has paid for credits before free_model_daily_requests: { used: number; // Free-model requests recorded so far in the current UTC day limit: number; // Free-model requests allowed per UTC day (see the free usage limits below) remaining: number; // Free-model requests left in the current UTC day }; // rate_limit: { ... } // A deprecated object in the response, safe to ignore }; }; See all 44 lines Credit limits Credit limits govern how much you can spend. They come from three places: Account balance, your available credits across the account. If your account has a negative credit balance, you may see 402 errors, including for free models. Adding credits to put your balance above zero allows you to use those models again. Per-key credit limits, an optional spending cap configured on an individual API key. The limit, limit_reset, and limit_remaining fields in the GET /api/v1/key response above describe this cap and how much of it remains. In-flight spending budget, a cap on the estimated cost of the paid requests you have running or recently completed, relative to your balance. See In-flight spending budget below. In-flight spending budget OpenRouter charges a request when it finishes, so many requests running at the same time could commit more than your balance covers before any of them settles. To prevent that, OpenRouter estimates each paid request’s cost up front at the endpoint’s prices. For chat and completion requests, the estimate covers input tokens plus the completion tokens allowed by max_tokens up to a fixed per-request cap (the cap is used when max_tokens is not set). Dedicated Image API (POST /api/v1/images) requests are also held against your in-flight spending budget based on the endpoint’s estimated image cost. Video API (POST /api/v1/videos) jobs are held at the job’s estimated cost, which for most models grows with the requested duration and resolution; the hold lasts while the job renders, not only while the submit request is open, so long-running video jobs count against the budget until they complete, fail, or are cancelled. Per-request fees and plugin charges on token-priced endpoints are not part of the estimate. The estimate is held against your account while the request runs. When the request completes or fails, the hold is replaced by the request’s actual cost for a short settlement window, and then released. The total that can be held at once is your in-flight spending budget: a fraction of your current credit balance, up to a fixed ceiling. A request whose estimated cost does not fit alongside your running and recently completed requests is rejected with 402 before it reaches a provider, even though your balance is positive. The error’s metadata says which case you hit: "reason": "in_flight_budget_exhausted" with "limit_source": "openrouter_in_flight_budget": your running and recently completed requests already fill the budget. This is transient and can occur with no request still running, while recent costs are settling. The response includes a Retry-After header; wait for it and retry. "reason": "weight_exceeds_budget" with "limit_source": "openrouter_credits": this single request’s estimated cost is larger than your whole budget, so retrying will not help. Lower max_tokens or the prompt size, or add credits. Every 402 whose metadata carries limit_source also carries remedy_hint, a one-line human-readable next step for that source. It is meant for people reading logs; branch on limit_source, not on the hint text. { "error": { "code": 402, "message": "This request would exceed your available credits given your current in-flight requests. Retry after in-flight requests settle, or add credits.", "metadata": { "reason": "in_flight_budget_exhausted", "limit_source": "openrouter_in_flight_budget", "remedy_hint": "Retry after your in-flight requests settle (see the Retry-After header). Adding credits at https://openrouter.ai/settings/credits raises your in-flight budget, up to a capped ceiling." } } } The budget applies to prepaid accounts spending their own credits, and only to a subset of them: accounts whose balance is below a threshold, and, while the mechanism is being rolled out, newer accounts without an established spending history. A larger balance raises the budget up to the ceiling, and a balance at or above the threshold is not subject to it at all. It does not apply to requests to free models, to requests served entirely with your own provider keys (see BYOK) that use no paid plugins, or to enterprise, paid-subscription, or invoice-billed accounts. Handling 402 errors To resolve 402 errors: Check error.metadata.limit_source in the response body. openrouter_in_flight_budget means your running and recently completed requests filled your in-flight spending budget, not your balance: wait for the Retry-After header and retry. openrouter_key_limit means the API key’s credit limit is exhausted. openrouter_credits means your balance cannot cover the request, or the single request is too expensive for your in-flight budget. Add credits to bring your account balance above zero, or to raise your in-flight spending budget. Check per-key limits. If limit_remaining on the key is exhausted, raise the key’s credit limit or wait for it to reset (see limit_reset). Reduce the request size (fewer input tokens, a lower max_tokens, or fewer/lower-resolution images) so its estimated cost fits your balance and in-flight budget. Monitor proactively. Call GET /api/v1/key as shown above to track limit_remaining and usage before requests start failing. Budget limits Budget limits are spend caps an org admin configures. They come from three places, and OpenRouter checks them in this order on every paid request, so the first one that is spent is the one that blocks: Guardrail budgets: a limit_usd with a reset_interval on the workspace default guardrail (checked against the member’s combined spend, then again