메인 콘텐츠로 건너뛰기

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.

요청을 수정해야 하는지 재시도해야 하는지 판단하여 CometAPI 오류를 처리하세요. 429, 타임아웃 계열 실패, 일시적인 서버 실패는 backoff와 함께 재시도하고, 잘못된 요청이나 인증 실패는 재시도하지 마세요.

재시도 가능한 실패만 재시도하기

상태 또는 신호재시도 여부조치
400아니요요청 본문 또는 매개변수를 수정하세요.
401아니요API 키와 Authorization 헤더를 수정하세요.
403보통 아니요지원되지 않는 필드를 제거하고 model 접근 권한을 확인하세요.
429지수형 backoff와 jitter를 사용해 재시도하세요.
500 with invalid_request아니요요청 형태를 수정하세요.
500, 503, 504, 524backoff와 함께 재시도하고 request ID를 유지하세요.

Backoff 추가하기

다음 Python 예제는 재시도 가능한 실패만 재시도합니다:
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.")
성공한 응답에는 model 출력이 포함됩니다:
{
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": "Hello."
      }
    }
  ],
  "usage": {
    "total_tokens": 9
  }
}

유용한 컨텍스트 기록하기

다음 JSON 형태는 사용자 비밀 정보와 대용량 파일을 제거한 후 안전하게 저장할 수 있습니다:
{
  "method": "POST",
  "path": "/v1/chat/completions",
  "model": "your-model-id",
  "status": 429,
  "request_id": "request_id_from_error_message",
  "retryable": true
}

일반적인 오류

오류수정 방법
401 재시도재시도를 중단하고 API 키를 교체하거나 다시 로드하세요.
잘못된 JSON 재시도다른 요청을 보내기 전에 요청 본문을 검증하세요.
로그에 request ID 없음SDK가 감싸기 전에 정확한 오류 본문을 캡처하세요.
429 직후 재시도jitter를 추가하고 동시성을 줄이세요.

관련 링크

Last modified on May 28, 2026