Errors, Limits & Code Examples
Complete HTTP and SSE error reference, default rate limits and daily quotas, retry guidelines, and production Node.js, TypeScript, and Python examples.
Updated 2026-12-02
Synchronous HTTP Error Codes
Common, Auth & Chat
| HTTP | code | Cause | Retryable |
|---|---|---|---|
400 | EMPTY_BODY / INVALID_JSON | Empty body or malformed JSON | No |
400 | VISION_UNAVAILABLE | images provided while vision model is disabled | No |
401 | UNAUTHORIZED / PARTNER_SESSION_CHANGED | Missing/invalid key, disabled tenant, or key revoked mid-run | No |
402 | PARTNER_BALANCE_EXHAUSTED | Insufficient tenant balance under metered billing | No |
403 | CHANNEL_DISABLED | API channel is not enabled for this tenant | No |
403 | CAPABILITY_DISABLED | Requested sub-capability (vision, history, TTS, image) is disabled | No |
404 | CONVERSATION_NOT_FOUND / RUN_NOT_FOUND | Missing or cross-user/cross-tenant conversation or run | No |
409 | RUN_ACTIVE / DUPLICATE_REQUEST / ARCHIVED | Active run in conversation, request_id conflict, or archived thread | No |
413 | BODY_TOO_LARGE / IMAGE_TOO_LARGE | Request body or image payload exceeds ceiling | No |
415 | IMAGE_FORMAT | Sniffed image format is not in the allowed list | No |
422 | INVALID_REQUEST / INVALID_IMAGE | Invalid parameters, unknown JSON field, or invalid image encoding | No |
429 | RATE_LIMITED / DAILY_LIMIT_REACHED | Concurrency, per-minute rate, or UTC+8 daily quota exceeded | Backoff on rate limit |
429 | SESSION_LIMIT / THREAD_LIMIT / ACCOUNT_QUOTA_EXHAUSTED | Active thread cap, 100-message cap, or user metered quota reached | No |
503 | SERVICE_RESTARTING / MODEL_UNAVAILABLE | Rolling restart or temporary model unavailability | Yes (reuse request_id, fail over) |
500 / 502 | INTERNAL_ERROR / terminal errors | Gateway 502 may fail over; business 502 with error.run_id needs new request_id | Depends |
TTS Audio & AI Image Specific
| Scope | HTTP | code | Cause | Retryable |
|---|---|---|---|---|
| Audio | 400 / 422 | SPEECH_TEXT_INVALID / SPEECH_VOICE_INVALID | Empty prose after cleanup, > 600 chars, or invalid voice | No |
| Audio | 429 | SPEECH_BUSY | Temporary upstream TTS contention | Yes (backoff) |
| Audio | 503 / 502 / 504 | SPEECH_NOT_CONFIGURED / SPEECH_UPSTREAM_FAILED / SPEECH_TIMEOUT | TTS disabled, upstream failure, or timeout | Backoff on 502/504 |
| Image | 413 / 422 | IMAGE_REFERENCE_TOO_LARGE / IMAGE_SPEC_UNSUPPORTED / IMAGE_EDIT_UNSUPPORTED / IMAGE_PROVIDER_REJECTED | Reference too large, unsupported spec/edit, or prompt rejected | No |
| Image | 429 | IMAGE_PLATFORM_CONCURRENCY / IMAGE_PROVIDER_LIMIT / IMAGE_PLATFORM_BUDGET | Image queue saturated or platform daily budget reached | Backoff on queue busy |
| Image | 503 / 502 | IMAGE_PROVIDER_DISABLED / IMAGE_GENERATION_FAILED / IMAGE_INVALID_OUTPUT | Image service disabled, timeout, or invalid output | Backoff on 502 |
SSE error & Sync 502 Terminal Codes
CANCELLED (stopped or disconnected, do not retry), TIMEOUT (> 600 s), SERVICE_RESTART, EMPTY_RESPONSE / INCOMPLETE_RESPONSE, SAVE_FAILED / ANSWER_SETUP_FAILED / ANSWER_FAILED (generate a new request_id before retrying).
Use exponential backoff 2s -> 5s -> 10s (with +/-20% jitter, up to 3 attempts) for retryable errors.
Default Limits & Quotas (UTC+8)
| Module | Limit | Default Ceiling |
|---|---|---|
| Chat | message length / images count & size | 8,000 chars / up to 3 images (<= 5 MB each, <= 15 MB total) |
| Chat | Request body size | 64 KB text-only / 24 MB with images |
| Chat | Tenant concurrency / per min / per day / per user per min | 20 / 60 / 5,000 / 12 |
| History | Active threads per user / messages per thread / run timeout | 100 / 100 / 600 s (suggestions up to 10 s) |
| TTS | Input text / tenant concurrency / per min / per day / per user per min | 600 chars / 4 / 30 / 1,000 / 15 |
| Images | Prompt / references / tenant concurrency / tenant per day / user per day | 6,000 chars / up to 3 (8 MB each, 20 MB total) / 1 / 50 / 10 |
| Polish | Tenant per min / per user per min | 30 / 12 |
Reference Code
TypeScript Universal SSE Parser
ts
export async function readPartnerStream(
response: Response,
handlers: {
meta?: (d: { conversation_id: string; run_id: string | null; request_id: string }) => void;
delta?: (d: { text: string }) => void;
done?: (d: { conversation_id: string; text: string; suggestions: string[]; usage: unknown }) => void;
error?: (d: { code: string; message: string; text?: string }) => void;
},
) {
if (!response.body) throw new Error("EMPTY_STREAM_BODY");
const reader = response.body.getReader();
const decoder = new TextDecoder();
let buffer = "";
const dispatch = (block: string) => {
let eventName = "";
const dataLines: string[] = [];
for (const line of block.split(/\r?\n/)) {
if (!line || line.startsWith(":")) continue;
if (line.startsWith("event:")) eventName = line.slice(6).trim();
else if (line.startsWith("data:")) dataLines.push(line.slice(5).trimStart());
}
if (!eventName || !dataLines.length) return;
const payload = JSON.parse(dataLines.join("\n"));
if (eventName === "meta") handlers.meta?.(payload);
else if (eventName === "delta") handlers.delta?.(payload);
else if (eventName === "done") handlers.done?.(payload);
else if (eventName === "error") handlers.error?.(payload);
};
try {
for (;;) {
const { value, done } = await reader.read();
if (value) buffer += decoder.decode(value, { stream: true });
let idx: number;
while ((idx = buffer.search(/\r?\n\r?\n/)) >= 0) {
const block = buffer.slice(0, idx);
buffer = buffer.slice(idx).replace(/^\r?\n\r?\n/, "");
dispatch(block);
}
if (done) {
buffer += decoder.decode();
if (buffer.trim()) dispatch(buffer);
break;
}
}
} finally {
reader.releaseLock();
}
}Python Failover, Chat & Image Generation Example
python
import base64
import os
import uuid
import requests
API_BASES = [
"https://feixiaohao.io/api/partner/v1",
"https://fxh.one/api/partner/v1",
]
AUTH = {"Authorization": f"Bearer {os.environ['PARTNER_API_KEY']}"}
def request_failover(method: str, path: str, *, json_body=None, stream=False, timeout=(20, 660)):
last_exc = None
for i, base in enumerate(API_BASES):
try:
r = requests.request(
method,
f"{base}{path}",
headers=AUTH,
json=json_body,
stream=stream,
allow_redirects=False,
timeout=timeout,
)
if 300 <= r.status_code < 400:
r.close()
last_exc = RuntimeError(f"Unexpected redirect {r.status_code}")
continue
if r.status_code in (502, 503, 504) and i < len(API_BASES) - 1:
if "application/json" not in r.headers.get("Content-Type", ""):
r.close()
continue
err = (r.json() or {}).get("error", {})
if not err.get("run_id") and err.get("code") in (None, "SERVICE_RESTARTING", "MODEL_UNAVAILABLE"):
r.close()
continue
return r
except requests.RequestException as exc:
last_exc = exc
raise RuntimeError(f"All API bases failed: {last_exc}")
def ask_once(user_id: str, message: str):
body = {"user_id": user_id, "message": message, "request_id": str(uuid.uuid4()), "stream": False}
with request_failover("POST", "/chat", json_body=body) as r:
return r.status_code, r.json()
def generate_image(prompt: str, out_file: str):
body = {"prompt": prompt, "style": "minimal-fintech", "aspect_ratio": "landscape", "response_format": "b64_json"}
with request_failover("POST", "/images/generations", json_body=body, timeout=(20, 270)) as r:
data = r.json()
if r.status_code != 200:
raise RuntimeError(data.get("error", {}))
with open(out_file, "wb") as f:
f.write(base64.b64decode(data["b64_json"]))
return {k: v for k, v in data.items() if k != "b64_json"}