Skip to main content

Documentation Index

Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt

Use this file to discover all available pages before exploring further.

Handle CometAPI errors by deciding whether the request should be fixed or retried. Retry 429, timeout-class failures, and temporary server failures with backoff; do not retry malformed requests or authentication failures.

Retry only retryable failures

Status or signalRetry?Action
400NoFix the request body or parameters.
401NoFix the API key and Authorization header.
403Usually noRemove unsupported fields and verify model access.
429YesRetry with exponential backoff and jitter.
500 with invalid_requestNoFix the request shape.
500, 503, 504, 524YesRetry with backoff and keep the request ID.

Add backoff

The following Python example retries only retryable failures:
import os
import random
import time
from openai import APIError, OpenAI, RateLimitError

client = OpenAI(
    api_key=os.environ["COMETAPI_KEY"],
    base_url="https://api.cometapi.com/v1",
)

for attempt in range(5):
    try:
        response = client.chat.completions.create(
            model="your-model-id",
            messages=[{"role": "user", "content": "Say hello."}],
        )
        print(response.choices[0].message.content)
        break
    except RateLimitError:
        delay = min(30, 2**attempt) + random.random()
        time.sleep(delay)
    except APIError as error:
        status_code = getattr(error, "status_code", None)
        if status_code in {500, 503, 504, 524}:
            delay = min(30, 2**attempt) + random.random()
            time.sleep(delay)
            continue
        raise
else:
    raise RuntimeError("The request failed after retries.")
The successful response includes the model output:
{
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": "Hello."
      }
    }
  ],
  "usage": {
    "total_tokens": 9
  }
}

Log useful context

The following JSON shape is safe to store after you remove user secrets and large files:
{
  "method": "POST",
  "path": "/v1/chat/completions",
  "model": "your-model-id",
  "status": 429,
  "request_id": "request_id_from_error_message",
  "retryable": true
}

Common errors

ErrorFix
Retrying 401Stop retries and rotate or reload the API key.
Retrying invalid JSONValidate the request body before sending another request.
No request ID in logsCapture the exact error body before your SDK wraps it.
Immediate retry after 429Add jitter and reduce concurrency.
Last updated: May 27, 2026