> For the complete documentation index, see [llms.txt](https://docs.synthdata.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.synthdata.co/getting-started/error-handling.md).

# Error Handling

Handle errors gracefully when using Synth API.

## HTTP Status Codes

| Code | Meaning          | Action                                |
| ---- | ---------------- | ------------------------------------- |
| 200  | Success          | Process response                      |
| 400  | Bad Request      | Check authentication header           |
| 401  | Unauthorized     | Check API key                         |
| 402  | Payment Required | Check subscription or billing status  |
| 404  | Not Found        | Check parameters or data availability |
| 429  | Rate Limited     | Retry after delay                     |
| 500  | Server Error     | Retry later                           |

## Error Response Format

Errors return JSON with a `message` field:

```json
{"message": "Unauthorized"}
```

```json
{"message": "missing key in request header"}
```

Some endpoints return a plain string for data errors:

```
"No prediction available"
```

## Best Practices

{% code title="example.py" %}

```python
import requests
import time

def fetch_percentiles(asset):
    response = requests.get(
        "https://api.synthdata.co/insights/prediction-percentiles",
        headers={"Authorization": "Apikey YOUR_API_KEY"},
        params={"asset": asset}
    )
    
    if response.status_code == 200:
        return response.json()
    elif response.status_code == 401:
        raise Exception("Invalid API key")
    elif response.status_code == 404:
        raise Exception(f"No data available for {asset}")
    elif response.status_code == 429:
        time.sleep(60)
        return fetch_percentiles(asset)  # Retry
    else:
        response.raise_for_status()
```

{% endcode %}
