# Error Handling

## 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 %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.synthdata.co/getting-started/error-handling.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
