budget_cap_reachedA weekly or monthly budget cap was reached; raise or reset the cap.
credit_limit_exceededA monthly-billing organization's credit line was exhausted; contact billing.
insufficient_creditsThe prepaid balance is insufficient; add credits.
spend_limit_exceededThe API key reached its daily, weekly, or monthly spend limit.
capacity_unavailableThis model is temporarily at capacity. Retry shortly; the Retry-After header says how long to wait.
Stable error.code catalog
These string codes are emitted by public inference and media paths. Branch on the string code when present; the HTTP status remains the broad failure class.
รูปแบบ error envelope แตกต่างตาม endpoint ใช้ HTTP status และ error.type เมื่อมี error.code อาจเป็น string หรือ numeric status และอาจไม่มี; error.message ใช้แสดงผลเท่านั้น
สถานะทรัพยากรวิดีโอและสื่อ
Video validation commonly returns numeric code 400. Missing jobs return 404, retired models 410, unfinished video content 409, and invalid video byte ranges 416.
ลองนโยบายอีกครั้ง
Retry only failures that may recover without changing the request. Honor Retry-After or use exponential backoff with jitter. Do not stack SDK and manual retries.
ลองอีกครั้งโดยถอยกลับ
429, 502, 503, and 504. Check the original generation job before creating another after an ambiguous network failure.
Fix ก่อนลองอีกครั้ง
400, 401, 402, 403, 404, 409, 410, 413, and 416. Fix the request, credentials, balance, permissions, resource state, or Range header first.
การจัดการข้อผิดพลาด
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import random
import time
from openai import OpenAI, APIStatusError
client = OpenAI(
base_url="https://api.bazaarlink.ai/v1",
api_key="sk-bl-YOUR_API_KEY",
max_retries=0, # Avoid double retries; this example handles them.
)
RETRYABLE = {429, 502, 503, 504}
for attempt inrange(5):
try:
response = client.chat.completions.create(
model="openai/gpt-4o",
messages=[{"role": "user", "content": "Hello!"}],
)
breakexcept APIStatusError as error:
if error.status_code notin RETRYABLE or attempt == 4:
raise
retry_after = error.response.headers.get("Retry-After")
delay = (
float(retry_after)
if retry_after
elsemin(8, 0.5 * (2 ** attempt)) + random.uniform(0, 0.25)
)
time.sleep(delay)
data: {"error":{"message":"The request could not be completed.","type":"upstream_error","code":502}}
data: [DONE]
// Branch on error.code; error.type can vary by failure path.
Support
Hi! How can we help you? Send a message and we'll get back to you soon.