速率限制

速率限制

Lawbot AI API 對每個 API 金鑰設有兩種限制:每分鐘請求次數(RPM)上限,以及Lifetime(累計)請求次數上限。 了解這兩種機制有助於您規劃 API 用量。

方案限制總覽

免費方案每位使用者僅能建立一個 API 金鑰。 如需更高配額,請聯絡 Lawbot 業務團隊升級為企業方案。

模型 / APIEndpointRPM 上限免費方案 Lifetime企業方案 Lifetime
lawbot-flash/api/v1/chat/completions60200 次自訂配額
lawbot-search/api/v1/search60500 次自訂配額

* Chat API 與搜尋 API 各有獨立的 Lifetime 計數,互不影響。

限制類型說明

RPM(每分鐘請求次數)

每個 API 金鑰每分鐘最多可發出 60 次請求, 超過後返回 HTTP 429。此限制每分鐘自動重置, 稍等片刻後即可繼續使用。

Lifetime 請求次數(累計上限)

每個 API 金鑰有一個終生累計請求次數上限, 不會隨時間重置。一旦達到上限,後續請求均返回 HTTP 429, 需聯絡 Lawbot 業務團隊升級方案。

回應 Headers

每個成功回應(HTTP 200)都包含以下 headers,可用於監控目前累計用量:

response_headers.txt
HTTP/1.1 200 OK
x-ratelimit-limit-requests: 200
x-ratelimit-remaining-requests: 158
Header說明
x-ratelimit-limit-requests此 API 金鑰的 Lifetime 請求次數上限。
x-ratelimit-remaining-requestsLifetime 上限內尚餘可用的請求次數。

* 僅在可查得使用者設定時才附帶 headers,部分情境下可能不包含。

HTTP 429 回應

當 lifetime 次數已達上限時,API 回傳 HTTP 429, 回應 body 格式如下:

429_response.json
{
  "detail": {
    "error": "lifetime_limit_exceeded",
    "model": "lawbot-flash",
    "lifetime_requests": 200,
    "lifetime_limit": 200
  }
}
欄位說明
error固定為 "lifetime_limit_exceeded"。
model超限的模型名稱,例如 lawbot-flash 或 lawbot-search。
lifetime_requests目前已使用的累計請求次數。
lifetime_limit此金鑰的 lifetime 請求次數上限。

讀取用量 Headers(Python)

check_quota.py
import openai

client = openai.OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://developer-api.lawbot.tw/api/v1",
)

# 透過 with_raw_response 取得完整 HTTP headers
with client.chat.completions.with_raw_response.create(
    model="lawbot-flash",
    messages=[{"role": "user", "content": "..."}],
    extra_body={"reasoning_effort": "low"},
) as raw:
    limit = raw.headers.get("x-ratelimit-limit-requests")
    remaining = raw.headers.get("x-ratelimit-remaining-requests")
    print(f"Lifetime 上限:{limit},剩餘:{remaining}")

    completion = raw.parse()
    print(completion.choices[0].message.content)

處理 Lifetime 上限(Python)

Lifetime 限制為永久累計,達到上限後重試不會自動解除, 應通知使用者並聯絡 Lawbot 業務團隊:

handle_limit.py
import openai

client = openai.OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://developer-api.lawbot.tw/api/v1",
)

try:
    response = client.chat.completions.create(
        model="lawbot-flash",
        messages=[{"role": "user", "content": "請說明契約解除的要件"}],
    )
    print(response.choices[0].message.content)
except openai.RateLimitError as e:
    # HTTP 429:lifetime 請求次數已達上限
    # 此種限制為永久性,重試不會解除,請聯絡 Lawbot 升級方案
    print("Lifetime 請求次數已達上限,請聯絡 Lawbot 業務團隊升級配額。")
    print(f"詳細資訊:{e.message}")