> ## Documentation Index
> Fetch the complete documentation index at: https://aisa.one/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> - Base URLs: models `https://api.aisa.one/v1` (Gemini GenerateContent: `https://api.aisa.one/v1beta`); data APIs `https://api.aisa.one/apis/v1`. The `servers` of each operation in https://aisa.one/openapi.yaml is authoritative.
> - Auth: `Authorization: Bearer $AISA_API_KEY`. Never print, log, or commit the key.
> - MCP (preferred for agents): `https://mcp.aisa.one/mcp`, signed in with OAuth, so there is no key to paste.
> - Agent Skill: `npx skills add AIsa-team/agent-skills --skill aisa`. Fallback with the AIsa CLI: `aisa skills install aisa`.
> - Spending: docs, https://aisa.one/models, https://aisa.one/api, `/v1/models`, and MCP `search`, `list_categories`, `get_details`, `batch_quote`, and the `account` operation are free. Quote the exact calls before running them (MCP `batch_quote`, CLI `aisa quote --json`). If the quote reports `auto_execute_eligible: true`, run it unless the user set a tighter limit or asked only for a quote. Otherwise, tell the user in one message the planned calls, the quoted price, and a total USD budget for the task, then wait for approval. Direct HTTP calls follow the stricter rule at https://aisa.one/docs/get-started/cli.md#direct-http-fallback. Do not make paid calls to test availability. Full rule: https://aisa.one/llms.txt

# 速率限制

> AIsa 如何限流：部分模型的成功调用次数限制、上游提供商返回的 429，以及如何根据 Retry-After 处理 429 响应。

AIsa 不公布固定的每分钟请求数（RPM）、每分钟 Token 数（TPM）或并发档位，响应中也没有 `X-RateLimit-*` 响应头。`429 Too Many Requests` 可能来自下面几种来源。无论哪种，只要有 `Retry-After` 就先等待，再退避重试。

## 429 的来源

| 来源 | 适用范围 | 如何识别 |
| - | - | - |
| 按模型的成功调用限制 | 仅配置了限制的模型 | `error.code = "model_success_rate_limit_exceeded"`，并带 `Retry-After` 响应头 |
| 上游提供商 | 任意模型或数据 API | 上游限流且没有可用的回退尝试；响应体遵循[该端点的错误格式](https://aisa.one/docs/zh/api-reference/errors.md) |
| 异步容量 | 异步数据 API 任务 | `{"error": "integration async capacity is unavailable"}`，并带 `Retry-After: 2` |

### 按模型的成功调用限制

部分模型会限制同一账户在以小时计的滚动窗口内对该模型的**成功**调用次数。失败的调用不计入。大多数模型没有这类限制。

达到上限时，网关返回 `429`，带 `Retry-After` 响应头（秒），响应体如下：

```json theme={null}
{
  "error": {
    "message": "model <model-id> is limited to 100 successful calls per 1h0m0s for this user",
    "code": "model_success_rate_limit_exceeded",
    "model": "<model-id>",
    "limit": 100,
    "window_seconds": 3600,
    "retry_after_seconds": 812,
    "reset_at": "2026-10-14T09:30:00Z"
  }
}
```

以上数值仅为示例。`reset_at` 是窗口内最早一次计数调用移出窗口、空出名额的时间。

## 处理 429 响应

**1. 遵守 `Retry-After`**

有该响应头时，至少等待对应秒数再发起下一次请求。不要立即重试。

**2. 使用指数退避加抖动**

没有 `Retry-After` 时，从约 1 秒开始，每次连续遇到 429 将延迟翻倍，加 ±25% 抖动，并设置上限。请参阅[重试指南](https://aisa.one/docs/zh/api-reference/errors.md#重试指南)。

**3. 成功调用限制可换模型**

`model_success_rate_limit_exceeded` 按模型计算。如果不能等到 `reset_at`，可以改用其他模型。

**4. 用队列代替循环重试**

批量任务应先入队，再以稳定速率消费，不要在紧密循环里反复重试。

## 示例：遇到 429 时重试

```python theme={null}
import time
from openai import OpenAI, RateLimitError

client = OpenAI(base_url="https://api.aisa.one/v1", api_key="sk-aisa-...")

def create_with_retry(max_attempts=5, **kwargs):
    delay = 1.0
    for attempt in range(max_attempts):
        try:
            return client.chat.completions.create(**kwargs)
        except RateLimitError as err:
            if attempt == max_attempts - 1:
                raise
            retry_after = err.response.headers.get("retry-after")
            time.sleep(float(retry_after) if retry_after else delay)
            delay = min(delay * 2, 30)

response = create_with_retry(
    model="qwen3.7-flash",
    messages=[{"role": "user", "content": "Hello"}],
)
```

## 需要更多容量？

如果按模型的限制或上游限流影响了生产负载，请发邮件至 [developer@aisa.one](mailto:developer@aisa.one)，说明模型或端点、预期峰值请求速率，以及使用场景的简要描述。

## 相关页面

> [card] [错误代码](https://aisa.one/docs/zh/api-reference/errors.md)
>
> 响应格式与重试指南。

> [card] [用量](https://aisa.one/docs/zh/guides/dashboard/overview.md#用量)
>
> 控制台中的单次请求状态与计费。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.