Skip to main content

Error Codes

Complete reference for all API error responses and how to handle them.

Error Response Format

All API errors are returned in OpenAI-compatible format:

json
{
  "error": {
    "message": "Human-readable error message",
    "type": "invalid_request_error",
    "code": "error_code",
    "details": {}
  }
}

HTTP Status Codes

Description

StatusNameDescription
400Bad RequestInvalid request body or parameters
401UnauthorizedMissing or invalid authentication
402Payment RequiredInsufficient balance
403ForbiddenValid auth but lacking permissions, or security verification failed
404Not FoundResource doesn't exist
409ConflictResource already exists or state conflict
429Too Many RequestsRate limit exceeded
500Internal Server ErrorUnexpected server error
503Service UnavailableTemporary service issue
504Gateway TimeoutRequest took too long

Common Error Codes

Click any error code to see detailed causes, resolutions, and example responses.

HTTP Status Codes

All possible API error responses with their meanings.

Error Handling

Implement proper error handling to provide a good user experience. Here's a comprehensive error handler:

error_handling.py
import openai
import time

client = openai.OpenAI(
    api_key="your-gonkagate-api-key",
    base_url="https://api.gonkagate.com/v1"
)

def chat_with_retry(messages, max_retries=3):
    """Make API request with exponential backoff retry logic."""
    for attempt in range(max_retries):
        try:
            response = client.chat.completions.create(
                model="Qwen/Qwen3-32B-FP8",
                messages=messages
            )
            return response.choices[0].message.content

        except openai.RateLimitError as e:
            # 429: Wait and retry with exponential backoff
            wait_time = 2 ** attempt
            print(f"Rate limited. Waiting {wait_time}s...")
            time.sleep(wait_time)

        except openai.AuthenticationError as e:
            # 401: Invalid API key - don't retry
            print(f"Auth error: {e.message}")
            raise

        except openai.BadRequestError as e:
            # 400: Invalid request - don't retry
            print(f"Bad request: {e.message}")
            raise

        except openai.APIStatusError as e:
            # 5xx: Server error - retry with backoff
            if e.status_code >= 500:
                wait_time = 2 ** attempt
                print(f"Server error {e.status_code}. Retrying in {wait_time}s...")
                time.sleep(wait_time)
            else:
                raise

    raise Exception("Max retries exceeded")

# Usage
result = chat_with_retry([{"role": "user", "content": "Hello!"}])
print(result)
Was this page helpful?