Skip to Content
aicentos
Billing & Management

Errors

HTTP status codes, error response structure, common errors and solutions

Last updated:

aicentos follows the OpenAI error response format exactly. When an SDK throws, just catch the corresponding exception.

Error response structure

Every error response has this shape:

{
  "error": {
    "message": "Your API key does not have access to gpt-5",
    "type": "permission_denied",
    "code": "model_not_allowed",
    "param": "model"
  }
}
FieldMeaning
messageHuman-readable error description
typeError category (see table below)
codeFine-grained error code (for programmatic checks)
paramName of the offending parameter, if any

HTTP status code reference

StatusTypeCommon causes
400invalid_request_errorMalformed request body, invalid parameters, misspelled model name
401authentication_errorAPI key missing / wrong / revoked
402insufficient_quotaInsufficient balance
403permission_deniedKey disabled, model not authorized, IP not on the allowlist
404not_foundWrong endpoint path, wrong model ID
408request_timeoutUpstream timeout (usually no response for over 60s)
413payload_too_largeRequest body too large (images, files)
415unsupported_media_typeWrong Content-Type
422invalid_request_errorRequest body parses but is semantically invalid
429rate_limit_exceededRate limit hit; lower the request rate and retry
500server_errorInternal platform error (rare)
502bad_gatewayUpstream service failure
503service_unavailableUpstream overloaded; retry later
504gateway_timeoutUpstream response timed out

Common errors and fixes

401 — Invalid API key

{ "error": { "message": "Incorrect API key provided", "type": "authentication_error" } }

Checklist:

  • Is the Authorization header in Bearer sk-xxx format (note the space)
  • Did copying the key from the console pick up spaces / newlines
  • Is the key deleted / disabled / expired
  • Did a test key end up in production

402 — Insufficient quota

{ "error": { "message": "Insufficient quota", "type": "insufficient_quota" } }

Top up → Wallet Management in the console. Turn on balance alerts to keep it from happening again.

403 — Model not allowed

{ "error": { "message": "Model gpt-5 not allowed for this key", "code": "model_not_allowed" } }

The token was created with an allowed models allowlist, and the requested model is not on it. Change the token settings or use another key.

404 — Model not found

{ "error": { "message": "The model 'gpt-4-turbo-2024-04-09' does not exist", "code": "model_not_found" } }

The model ID is misspelled or has been retired. Check the model marketplace for currently available IDs.

429 — Rate limit exceeded

The Retry-After response header tells you how many seconds to wait before retrying. Lower your concurrency and request rate to recover.

500 / 502 / 503 — Service errors

Usually upstream turbulence. Retrying 2-3 times automatically usually succeeds. If it lasts more than 5 minutes:

408 / 504 — Timeouts

No response after 60 seconds. Common causes:

  • The prompt is so long that the model "thinks" past the timeout
  • Streaming is not enabled (add stream: true for long responses)

Fixes:

  • Shorten the prompt
  • Enable streaming: { "model": "...", "messages": [...], "stream": true }
  • Switch to a faster model (e.g. from gpt-4o to gpt-4o-mini)

SDK error handling examples

export AICENTOS_API_KEY="sk-your-aicentos-api-key"

Python

import os
from openai import OpenAI, APIError, RateLimitError, AuthenticationError

client = OpenAI(api_key=os.environ["AICENTOS_API_KEY"], base_url="https://aicentos.com/v1")

try:
    resp = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{"role": "user", "content": "hi"}],
    )
except AuthenticationError:
    print("Invalid API key")
except RateLimitError as e:
    print(f"Rate limited, retry in {e.response.headers.get('Retry-After')}s")
except APIError as e:
    print(f"Other API error: {e.status_code} {e.message}")

Node.js

import OpenAI, { APIError } from 'openai';

const client = new OpenAI({
  apiKey: process.env.AICENTOS_API_KEY,
  baseURL: 'https://aicentos.com/v1',
});

try {
  const resp = await client.chat.completions.create({ ... });
} catch (err) {
  if (err instanceof APIError) {
    console.log(err.status, err.code, err.message);
  }
}

Retry and fallback recommendations

Error typeRecommended handling
400 / 401 / 402 / 403 / 404Do not retry — code / config error; debug first
429Retry per Retry-After with exponential backoff
500 / 502 / 503 / 504 / 408Retry 1-3 times immediately, 1-5s apart

The official OpenAI SDKs ship with sensible retry policies by default — use the SDK in production code instead of hand-rolled fetch calls.