Skip to main content
The Deepshi API uses standard HTTP status codes. Errors return a JSON body with an error object describing what went wrong.
{
  "error": {
    "message": "budget exceeded",
    "type": "insufficient_quota",
    "code": "402"
  }
}

Status codes

StatusMeaningWhat to do
200 OKSuccessNothing to do.
400 Bad RequestMalformed request, or a model id that doesn’t exist in the catalogCheck your JSON body and that model is a valid catalog id.
401 UnauthorizedMissing, malformed, or unknown API keyVerify the Authorization: Bearer sk-bf-... header.
402 Payment RequiredOut of creditsTop up your balance.
403 ForbiddenKey revoked, or not allowed to use the requested modelUse an active key and a model your account can access.
429 Too Many RequestsRate limit exceededBack off and retry with exponential backoff.
5xxTemporary server errorRetry with backoff.
A real model your key isn’t permitted to use returns 403. A model id that doesn’t exist in the catalog returns 400, not 403 or 404.

Handling errors in code

Retry transient failures (429 and 5xx) with exponential backoff, and surface the others to the user:
import time
from openai import OpenAI, APIStatusError

client = OpenAI(base_url="https://api.deepshi.ai/v1", api_key="sk-bf-...")

def chat_with_retry(messages, retries=3):
    for attempt in range(retries):
        try:
            return client.chat.completions.create(
                model="deepshi-3.0", messages=messages,
            )
        except APIStatusError as e:
            if e.status_code in (429, 500, 502, 503) and attempt < retries - 1:
                time.sleep(2 ** attempt)   # backoff
                continue
            raise
Don’t retry 400, 401, 402, or 403. They won’t succeed on retry. Fix the request, key, balance, or model access instead.