Skip to Content

速率限制

OfoxAI 的速率限制保障平台穩定性。了解限制規則並最佳化呼叫策略。

預設限制

OfoxAI 按量付費,所有使用者共享統一的速率策略:

限制項額度
RPM(請求/分鐘)100(團隊級聚合)
TPM(Token/分鐘)不限

團隊級聚合:RPM 按整個組織(團隊)累計計算,團隊下的多個 API Key 共享同一配額,從根源防止多 Key 疊加擊穿上游供應商限速。如需更高 RPM 配額,請聯繫 [email protected] 申請調整。

Rate Limit Header

每個 API 回應都包含速率限制資訊:

x-ratelimit-limit-requests: 100 x-ratelimit-remaining-requests: 95 x-ratelimit-reset-requests: 12s
Header說明
x-ratelimit-limit-requestsRPM 限制值
x-ratelimit-remaining-requests剩餘請求次數
x-ratelimit-reset-requests請求限制重置時間

429 錯誤處理

當觸發限流時,API 回傳 429 Too Many Requests

from openai import RateLimitError import time try: response = client.chat.completions.create(...) except RateLimitError as e: retry_after = float(e.response.headers.get("retry-after", 1)) print(f"觸發限流,等待 {retry_after}s...") time.sleep(retry_after)

最佳化策略

1. 使用 Prompt Caching

對於重複的 system prompt,啟用快取可以減少 token 消耗:

response = client.chat.completions.create( model="openai/gpt-4o", messages=[ # 較長的 system prompt 會被自動快取 {"role": "system", "content": "你是一個專業的...(此處省略長文本)"}, {"role": "user", "content": "使用者問題"} ] )

詳見 提示快取

2. 批次處理

將多個短請求合併為一個請求:

# ❌ 不推薦:為每個問題傳送獨立請求 for question in questions: client.chat.completions.create(messages=[{"role": "user", "content": question}]) # ✅ 推薦:合併為一個請求 combined = "\n".join(f"{i+1}. {q}" for i, q in enumerate(questions)) client.chat.completions.create( messages=[{"role": "user", "content": f"請依次回答以下問題:\n{combined}"}] )

3. 選擇合適的模型

推薦模型請參考 模型廣場 

4. 控制 max_tokens

設定合理的 max_tokens 限制,避免不必要的 token 消耗:

response = client.chat.completions.create( model="openai/gpt-4o", messages=[{"role": "user", "content": "一句話總結"}], max_tokens=100 # 限制輸出長度 )

5. 使用模型回退

當主模型達到限制時,自動切換到備選模型:

response = client.chat.completions.create( model="openai/gpt-4o", messages=[...], extra_body={ "provider": { "fallback": ["anthropic/claude-sonnet-4.6", "google/gemini-3.1-flash-lite-preview"] } } )

詳見 故障回退

Last updated on