> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kymaapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Error Handling

> Handle errors and rate limits gracefully.

## Error codes

| Status | Meaning             | What to do                                 |
| ------ | ------------------- | ------------------------------------------ |
| `401`  | Invalid API key     | Check your key starts with `ky-`           |
| `404`  | Model not found     | Check model ID with `GET /v1/models`       |
| `429`  | Rate limit exceeded | Wait until midnight UTC or reduce requests |
| `500`  | Provider error      | Retry or try a different model             |

## Rate limits

Rate limits are tier-based: Tier 0 = **30 RPM**, Tier 1 = **60 RPM**, up to Tier 4 = **300 RPM**. See [Rate Limits](/pricing#rate-limits) for details.

Check your remaining quota:

```bash theme={null}
curl https://kymaapi.com/v1/auth/limits \
  -H "Authorization: Bearer ky-your-api-key"
```

Response:

```json theme={null}
{
  "rpm_limit": 200,
  "used_today": 15,
  "remaining": 85,
  "resets_at": "2026-04-06T00:00:00.000Z"
}
```

## Python error handling

```python theme={null}
from openai import OpenAI, APIError, RateLimitError, AuthenticationError

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

try:
    response = client.chat.completions.create(
        model="llama-3.3-70b",
        messages=[{"role": "user", "content": "Hello"}]
    )
except AuthenticationError:
    print("Invalid API key")
except RateLimitError:
    print("Daily limit reached. Try again tomorrow.")
except APIError as e:
    print(f"API error: {e.message}")
```

## Retry with fallback model

```python theme={null}
models = ["qwen-3.6-plus", "qwen-3-32b", "llama-3.3-70b"]

for model in models:
    try:
        response = client.chat.completions.create(
            model=model,
            messages=[{"role": "user", "content": "Hello"}]
        )
        print(f"Success with {model}")
        break
    except Exception:
        continue
```
