Error envelopes vary by endpoint. Use HTTP status and error.type when present; error.code may be a string or numeric HTTP status, and can be absent. Use error.message for display only.
1
2
3
4
5
6
7
{"error":{"message":"Insufficient credits. Please top up to continue.","type":"invalid_request_error","code":"insufficient_credits"}}
HTTP status and error.code
Error envelopes vary by endpoint. Use HTTP status and error.type when present; error.code may be a string or numeric HTTP status, and can be absent. Use error.message for display only.
Code
Name
Description
424Failed DependencyYour BYOK key was rejected by the upstream provider; check or rotate it in BYOK settings. This appears only in strict mode
400Bad RequestMalformed request, empty messages array, or missing required fields
401UnauthorizedAPI key is missing, invalid, or disabled
402Payment RequiredInsufficient account credits, per-key spend limit reached, or monthly/weekly budget cap exceeded
403ForbiddenAccount is suspended or does not have permission
404Not FoundThe requested model, generation, key, or other resource does not exist
409ConflictThe resource is not in the required state, such as a video job that is not complete
410GoneThe requested model has been retired and must be replaced
413Payload Too LargeRequest body exceeds 10 MB; reduce content size or split the request
416Range Not SatisfiableThe requested byte range is invalid for generated video content
429Too Many RequestsRate limit exceeded; check Retry-After header before retrying
432Free Quota ExhaustedTavily-compatible endpoints (/v1/search, /v1/extract, /v1/crawl, /v1/map): the free search allowance is used up, or the balance is zero or below; add credits to continue. The body is Tavily-shaped: {"detail":{"error":"..."}}
500Server ErrorInternal BazaarLink error
502Bad GatewayAll upstream sources failed; no source could handle the request.
503Service UnavailableNo upstream provider is configured for this model; contact admin
504Gateway TimeoutThe upstream connection or stream stalled and timed out
Machine-readable billing codes
A 402 response can represent different controls. These stable codes let clients show the correct next action.
Code
Description
byok_key_invalidYour own BYOK key was rejected by the upstream provider; check or rotate it in BYOK settings. This appears only in strict mode.
budget_cap_reachedA weekly or monthly advisory budget cap was reached; raise or reset the cap.
credit_limit_exceededA monthly-billing organization's hard credit line was exhausted; contact billing.
insufficient_creditsA prepaid user or organization cannot reserve enough balance; add credits.
spend_limit_exceededThe API key reached its configured daily, weekly, or monthly spend limit.
capacity_unavailableThis model is temporarily at capacity. Retry shortly; the Retry-After header says how long to wait.
Detailed error codes
When an API request fails, error.code tells you the specific reason. Two errors can both use HTTP 400 but require different fixes: unknown_model means the model name is wrong, while image_too_large means the image must be reduced. Use the table below to find the cause and next action.
Model and endpoint
Model lookup, lifecycle, pricing, modality, and endpoint compatibility errors.
Code
HTTP status
unknown_model400
invalid_model_id400
model_not_found404
model_retired410
model_endpoint_mismatch400
embedding_on_chat_endpoint400
model_not_priced400
invalid_modality_for_model400
Request and safety
Invalid parameters, context, tools, schemas, and content-safety refusals.
Code
HTTP status
missing_required_field400
unsupported_param400
max_tokens_invalid400
context_too_long400
tool_use_unsupported400
malformed_tool_messages400
invalid_response_format_schema400
invalid_tools_definition400
content_moderation403
content_filter403
unknown_4xx400
Image generation and editing
Image input, multipart editing, output, and image-pipeline errors.
Code
HTTP status
invalid_image_url400
input_images_not_supported400
invalid_content_type400
mask_not_supported400
unsupported_response_format400
missing_prompt400
missing_image400
too_many_images400
invalid_image_type400
image_too_large400
invalid_n400
pipeline_error502
no_images502
Upstream routing
Sanitized provider connectivity, authentication, throttling, and availability errors.
Code
HTTP status
upstream_unreachable502
upstream_auth_failed502
upstream_rate_limited429
capacity_unavailable429
upstream_unavailable502/503
byok_key_invalid424
Content Moderation
All requests are automatically reviewed before being sent to the model. Requests that violate our usage policy are rejected before dispatch and return a 403 error.
Categories that get blocked
Moderation is based on our Acceptable Use Policy and primarily blocks the following categories of content:
Sexual exploitation content
Violent threats
Operational guidance for illegal acts
Biohazard-related content
403 response format
A request blocked by moderation returns an error in this shape:
1
2
3
4
5
6
7
{"error":{"message":"Your prompt was blocked by content moderation.","type":"invalid_request_error","code":"content_filter"}}
Blocked requests are not billed — you are not charged for a rejected request.
Appealing a false positive
If you believe a request was blocked incorrectly, contact support with the request time and (if convenient) the request id, and we'll review it.
Privacy
Requests are automatically reviewed for content safety; the text and images of your latest input may be sent to a third-party content-safety scoring service.
For requests judged violating, suspected, near the threshold or randomly sampled, we may keep the full text or the leading portion for compliance evidence, dispute handling and auditing, with no fixed deletion period promised.
Other ordinary successful requests do not have their prompts or responses retained; requests made with ZDR keys are not subject to the first two points.
Rate limits, budgets, and emergency brakes
These controls can reject an otherwise valid request. They are separate from provider failures and require different recovery actions.
Control
HTTP status
How to identify it
Request rate limit429String code or numeric code 429; use Retry-After and X-RateLimit-* headers.
Rate-limit penalty block429Numeric code 429 and a temporary restriction message; use Retry-After.
Global spend emergency brake503Numeric code 503, global spend-limit message, and Retry-After of 30 or 300 seconds.
Org/team/member/user spend brake429Numeric code 429 and a spend circuit-breaker message naming the affected scope.
Billing and budget controls402Use the stable billing string codes listed above.
Error envelopes vary by endpoint. Use HTTP status and error.type when present; error.code may be a string or numeric HTTP status, and can be absent. Use error.message for display only.
Video and media resource state
Video validation commonly returns numeric code 400. A missing job returns 404, a retired model returns 410, unfinished video content returns 409, and an invalid video byte range returns 416. Poll until completion or correct the Range header before retrying.
Retry policy
Retry only failures that may recover without changing the request. When Retry-After is present, wait that long; otherwise use exponential backoff with jitter. Limit attempts and avoid layering manual retries on top of SDK automatic retries.
Retry with backoff
429, 502, 503, and 504. Respect Retry-After when provided. For generation requests, do not create a second job after an ambiguous network failure until you have checked the original job.
Fix before retrying
400, 401, 402, 403, 404, 409, 410, 413, and 416. Change the request, credentials, balance, permissions, resource state, or Range header first.
Handling Errors
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)
Streaming Error Formats
Errors that occur before any tokens are streamed return a standard HTTP error response with a JSON body.
After a stream has started, the HTTP response is already 200. Parse every SSE data frame and treat a top-level error or choices[0].finish_reason === "error" as a failed, incomplete response.
If a stream fails after it starts, BazaarLink may emit a final SSE event with a top-level error object followed by data: [DONE]. Treat the response as incomplete; do not use partial output as a completed result.
1
2
3
4
5
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.