# Error Handling (old)

## HTTP Status Codes

| Code | Meaning      | Action                                |
| ---- | ------------ | ------------------------------------- |
| 200  | Success      | Process response                      |
| 400  | Bad Request  | Check authentication header           |
| 401  | Unauthorized | Check API key                         |
| 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:

```json
"No prediction available"
```

## Common Errors

<details>

<summary>Missing Authorization Header — Status: 400</summary>

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

{% hint style="info" %}
Solution: Add the `Authorization: Apikey YOUR_API_KEY` header.
{% endhint %}

</details>

<details>

<summary>Invalid API Key — Status: 401</summary>

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

{% hint style="info" %}
Solution: Verify your API key in the dashboard.
{% endhint %}

</details>

<details>

<summary>No Data Available — Status: 404</summary>

```json
"No prediction available"
```

{% hint style="info" %}
Solution: Check that:

* Asset is valid (`BTC`, `ETH`, `SOL`, `XAU`, `SPYX`, `NVDAX`)
* Required parameters are provided
* For `/v2/prediction/latest`: miner UIDs are valid
  {% endhint %}

</details>

## Best Practices

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

```python
import requests
import time

def fetch_predictions(asset):
    response = requests.get(
        "https://api.synthdata.co/v2/prediction/best",
        headers={"Authorization": "Apikey YOUR_API_KEY"},
        params={"asset": asset, "time_increment": 300, "time_length": 86400}
    )
    
    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_predictions(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-old.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.
