Zvikanganiso
Request inokundikana inodzosa HTTP status code ne-JSON body ine error type ne-message. Peji iyi inoratidza status imwe neimwe, inoratidza error body ye-API format imwe neimwe uye inoti ma-error api akakodzera kutumirwa zvakare.
SDKs dzinoburitsa error object inotakura status code nema-field e-body. Request iyi inotumidza model isipo:
import openai
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.shannon-ai.com/v1",
)
try:
client.chat.completions.create(
model="no-such-model",
messages=[{"role": "user", "content": "Hello"}],
)
except openai.APIStatusError as error:
print(error.status_code) # 400
print(error.type) # invalid_request_error
print(error.body["message"]) # unknown model: no-such-model
print(error.response.headers.get("x-request-id")) # the id of this request import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_API_KEY",
baseURL: "https://api.shannon-ai.com/v1",
});
try {
await client.chat.completions.create({
model: "no-such-model",
messages: [{ role: "user", content: "Hello" }],
});
} catch (error) {
if (!(error instanceof OpenAI.APIError)) throw error;
console.log(error.status); // 400
console.log(error.type); // invalid_request_error
console.log(error.error.message); // unknown model: no-such-model
} curl -i https://api.shannon-ai.com/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "no-such-model",
"messages": [{"role": "user", "content": "Hello"}]
}' Inodzosa status 400 ne-body iyi:
{
"error": {
"type": "invalid_request_error",
"message": "unknown model: no-such-model"
}
} Muviri we-error
Kune ma-body maviri. /v1/messages inopindura mu-Anthropic format; endpoint imwe neimwe inopindura mu-OpenAI format. Mune ese maviri, ruzivo ruri mu-error.type ne-error.message, saka reader imwe inoshandira ma-endpoint ese.
{
"error": {
"type": "authentication_error",
"message": "Invalid API key",
"code": "invalid_api_key",
"param": null
}
} {
"type": "error",
"error": {
"type": "authentication_error",
"message": "Invalid API key"
}
} | Field | Mhando | Tsananguro |
|---|---|---|
error.type | string | Mhando ye-error. Tarisa Error types pazasi. |
error.message | string | Mutsara wemunhu. Ma-text ari mumatafura ari pazasi anogara akadaro kunze kwezvikamu zvinochinja, zvinoratidzwa se-<id>, <n> kana …. |
error.code | string | null | Iripo pane mamwe ma-error e-OpenAI format: invalid_api_key ne-401, request_too_large ne-413, context_length_exceeded kana hurukuro yakareba kwazvo, kana zvimwe null kana isipo. Sarudza pa-status ne-error.type kutanga uye utore code sechiwedzerwa. |
error.param | null | Iripo pane ma-error akafanana ne-code. Inogara iri null. |
type | string | Anthropic format chete. Inogara iri error. |
Error types
| Mhando | Statuses | Tsananguro |
|---|---|---|
invalid_request_error | 400, 413, 415, 422 | Request pachayo yakashata: field, body, model id kana input isingagamuchirwi ne-model. Chinja request usati watumira zvakare. |
authentication_error | 401 | API key haisipo, haizivikanwi kana kuti yabviswa. |
not_found_error | 404 | Path haipo. |
rate_limit_error | 429 | Balance haikwani request, flood protection yainomisa, kana model iri busy. Message inoti ndeipi. |
api_error | 500, 502, 503, 504 | Request yaiva nani uye kundikana kuri kwatiri. Itumire zvakare. |
server_error | 500 | Request yaiva nani uye kundikana kuri kwatiri. Itumire zvakare. |
Status codes
| Status | Mhando | Message | Rinhi |
|---|---|---|---|
400 | invalid_request_error | Failed to parse the request body as JSON: … | Body haisi JSON chaiyo. |
400 | invalid_request_error | unknown model: <id> | model haisi published id. Pa-/v1/responses zvakare kana model isipo. |
400 | invalid_request_error | No user message provided | Shannon tiers: request haina user text. |
400 | invalid_request_error | <id> does not accept image input | Mufananidzo watumirwa kune hosted open-weight model isina image input. |
400 | invalid_request_error | audio and video input are not supported by any hosted model | Audio kana video part yatumirwa kune hosted open-weight model. |
400 | invalid_request_error | <id> does not accept response_format | Structured output yakakumbirwa kune hosted open-weight model isina. |
400 | invalid_request_error | <id> does not accept response_format json_schema; use json_object | JSON schema yatumirwa kune hosted open-weight model inogamuchira json_object chete. |
400 | invalid_request_error | unknown reasoning effort '<value>'; expected off, low, medium or high | Reasoning effort haisi imwe yema-value ari mu-list. Hosted open-weight models. |
400 | invalid_request_error | count_tokens is available for the hosted open models; unknown model: <id> | Token counting yakakumbirwa ye-model iri kunze kwe-hosted open-weight models. |
401 | authentication_error | Missing authentication | Hapana API key yakatumirwa. |
401 | authentication_error | Invalid API key | Key haizivikanwi, yakatsiviwa nenyowani, kana yabviswa. |
404 | not_found_error | Not Found | Path haipo, semuenzaniso /v1/embeddings. |
405 | api_error | Method Not Allowed | Path iripo asi kwete ne-HTTP method iyi. |
413 | invalid_request_error | Failed to buffer the request body: … | Request body yakakura kupfuura 32 MiB. |
415 | invalid_request_error | Expected request with `Content-Type: application/json` | Content-Type header haisipo kana kuti haisi application/json. |
422 | invalid_request_error | Failed to deserialize the JSON body into the target type: … | Field inodiwa haisipo, sa-messages, kana field ine JSON type isiriyo. |
429 | rate_limit_error | Quota exceeded. Upgrade your plan at shannon-ai.com/plan | Output limit ye-request yakakura kupfuura zvasara mu-balance yako. |
429 | rate_limit_error | Too many requests. Retry in <n>s. | Flood protection: ma-request anopfuura 120 paminiti imwe pa-account yako. <n> ihuwandu hwemasekonzi kusvika miniti yapera. |
429 | rate_limit_error | Shannon Coder call quota reached. Upgrade your plan at shannon-ai.com/plan | shannon-coder-1 pa-/v1/chat/completions ne-/v1/messages: Shannon Coder calls dze-plan yako dzewindow yemaawa 4 yazvino dzapera. |
429 | rate_limit_error | Shannon routes are temporarily busy. Please retry. | Model iri busy panguva ino. |
500 | server_error | The model backend failed to answer. Please retry. | Model haina kugadzira mhinduro. |
500 | server_error | An internal error occurred. Please retry. | Kundikana kwemukati request ichigadzirirwa. |
502 | api_error | The model backend failed to answer. Please retry. | Model haina kugadzira mhinduro. Mhuri ye-Shannon 3 ne-hosted open-weight models. |
503 | api_error | Could not verify your quota right now. Please retry. | Balance yako haina kukwanisa kuverengwa panguva ino. |
503 | api_error | token counting is temporarily unavailable for this model | Token counting haipo ye-model iyi panguva ino. |
504 | api_error | upstream timed out | Hosted open-weight model yakatora nguva yakareba kupfuura time limit ye-request isiri streamed. |
Ma-check anomhanya nenzira iyi: API key, request body, model id, flood protection, balance. Request ine key isiriyo ne-body isiriyo nokudaro inodzosa 401. Request inorambwa ne-4xx status haibhadharwi.
Balance ne-flood protection
Request imwe neimwe inoshandirwa zvakaenzana: hapana rate tiers uye hapana API quota yakasiyana. Zvinhu zviviri zvichiri kugona kupindura 429, zvese zvine type rate_limit_error. Message inosiyanisa.
Balance
Balance yako i-plan allowance yanhasi, inotangazve pa-00:00 UTC, uye mushure mayo purchased credit yako. Chat ne-API zvinotora kubva ku-balance imwechete.
Request imwe neimwe inotanga kuchengeta output limit yayo: max_tokens, kana max_output_tokens pa-/v1/responses, 4,096 kana usina kutumira chero ipi. Mhinduro kana yapera, huwandu hwakachengetwa hunotsiviwa nezvakashandiswa ne-request. Kana huwandu husingakwani mu-balance yasara, request inodzosa Quota exceeded model isati yatanga.
Ma-request anomhanya panguva imwe chete imwe neimwe inochengeta huwandu hwayo. Ma-request akawanda akafanana ane max_tokens yakakwira anogona nokudaro kupedza balance kwechinguva, kunyange mhinduro imwe neimwe ichipfupika. max_tokens yakaderera inochengeta shoma.
Flood protection
Flood protection inobvumira ma-request 120 paminiti imwe pa-account imwe. Inoverenga account, kwete key, pa-/v1/chat/completions, /v1/responses ne-/v1/messages pamwe chete. Miniti inotanga ne-request yako yekutanga.
Request nhamba 121 mukati meminiti iyoyo inodzosa Too many requests. Retry in <n>s. uye haibhadharwi. Ma-request akarambwa anoverengwawo, saka client inotumira zvakare isingamiriri inoramba ichirambwa kusvika miniti yapera. Mirira masekonzi <n> ari mu-message.
Requests dzinotumirwa dzakafanana hadzirambwi nekuda kwekuti dzakafanana. Dzinomirira pamutsara uye dzinopindurwa imwe nemwe.
GET /v1/models ne-token counting endpoints hadziverengwi.
Zvimwe pamusoro pe-limits ne-balance, uye kwekuona balance ne-usage yako: Limits ne-balance Keys & usage
Zvekuedza zvakare
Tumira request zvakare chete kana request imwechete ichigona kubudirira. OpenAI ne-Anthropic SDKs dzinoedza zvakare 429 ne-5xx replies kaviri pachadzo; isa max_retries (maxRetries mu-JavaScript) kuti uchinje izvozvo.
| Error | Tumira zvakare? | Sei |
|---|---|---|
400, 404, 405, 413, 415, 422 | Kwete. Gadzirisa request kutanga. | Message inotaura field, model kana input isiri iyo. |
401 | Kwete. Shandisa key chaiyo. | Gadzira kana tsiva key papeji reKeys & usage. |
429 Too many requests | Hongu, mushure mekumirira. | Mirira huwandu hwemasekonzi hune mu-message, wotumira request imwechete. |
429 Quota exceeded | Kwete sezvairi. | Daisa max_tokens, mirira daily reset pa-00:00 UTC, kana wedzera credit. |
429 Shannon Coder call quota reached | Hongu, mu-window inotevera. | Ma-window anotanga maawa 4 ega ega kubva pa-00:00 UTC. Model imwe inopindura pakarepo. |
429 … temporarily busy | Hongu. | Mirira masekonzi mashoma, wozowedzera pakuedza kwese kunotevera. |
500, 502, 503 | Hongu. | Mirira 1 second, wozoita 2, 4 ne-8. Mira mushure mekuedza kushomanana uye utaure request id. |
504 | Hongu. | Itumire ne-stream yakaiswa ku-true: time limit inoshanda pamhinduro dzisiri streamed. |
Retry loop inotevera tafura iyi:
import re
import time
import openai
from openai import OpenAI
# max_retries=0: this loop does the retrying, the SDK does not add its own.
client = OpenAI(api_key="YOUR_API_KEY", base_url="https://api.shannon-ai.com/v1", max_retries=0)
def create_with_retry(attempts=5, **request):
for attempt in range(attempts):
try:
return client.chat.completions.create(**request)
except openai.RateLimitError as error:
text = str(error)
flood = re.search(r"Retry in (\d+)s", text)
if flood:
time.sleep(int(flood.group(1))) # flood protection: wait out the minute
elif "temporarily busy" in text:
time.sleep(2 ** attempt)
else:
raise # balance: a wait of seconds does not help
except (openai.InternalServerError, openai.APIConnectionError):
time.sleep(2 ** attempt) # 1, 2, 4, 8 seconds
raise RuntimeError("the request failed after all attempts")
response = create_with_retry(
model="shannon-3",
messages=[{"role": "user", "content": "Hello"}],
)
print(response.choices[0].message.content) import OpenAI from "openai";
// maxRetries: 0 — this loop does the retrying, the SDK does not add its own.
const client = new OpenAI({ apiKey: "YOUR_API_KEY", baseURL: "https://api.shannon-ai.com/v1", maxRetries: 0 });
const sleep = (seconds) => new Promise((resolve) => setTimeout(resolve, seconds * 1000));
async function createWithRetry(request, attempts = 5) {
for (let attempt = 0; attempt < attempts; attempt++) {
try {
return await client.chat.completions.create(request);
} catch (error) {
const text = String(error.message);
const flood = text.match(/Retry in (\d+)s/);
if (error.status === 429 && flood) {
await sleep(Number(flood[1])); // flood protection: wait out the minute
} else if (error.status === 429 && text.includes("temporarily busy")) {
await sleep(2 ** attempt);
} else if (error.status >= 500 || error instanceof OpenAI.APIConnectionError) {
await sleep(2 ** attempt); // 1, 2, 4, 8 seconds
} else {
throw error; // wrong request, wrong key or balance
}
}
}
throw new Error("the request failed after all attempts");
}
const response = await createWithRetry({
model: "shannon-3",
messages: [{ role: "user", content: "Hello" }],
});
console.log(response.choices[0].message.content); Errors mukati me-stream
Stream ine status 200 kubva pa-byte yayo yekutanga. Kundikana mushure mazvo kunouya se-event mukati me-stream: chunk ine error member pa-/v1/chat/completions, error event pa-/v1/messages, response.failed kana error event pa-/v1/responses. Ma-event ekupedzisa e-stream achatevera zvakadaro. Tora mhinduro yakadaro seyakundikana uye utumire request zvakare, sezve 5xx status.
Hurukuro yakareba kupfuura context window ye-model inoratidzwa nenzira iyi, ine type invalid_request_error ne-code context_length_exceeded. Pfupisa hurukuro usati watumira zvakare.
Ma-frame chaiwo akatsanangurwa ne-streaming. Kuyerera
Request ids
Mhinduro imwe neimwe, ma-error akaverengwa, ine x-request-id header. Ndiyo value yawakatumira mu-x-request-id header yako pachako, kana hexadecimal characters 12 kana usina kutumira. Inyore mu-log, uye uitaure kana uchikumbira rubatsiro pa-request.