# FAQ

## API errors

The AI Model Hub is designed primarily as an API-first solution. While this approach enables seamless integration into existing codebases, it also presents a challenge: errors and problems that occur may not always be immediately visible or diagnosable. This FAQ addresses the most common problems and guides on their resolution:

### How do I fix an unauthorized, incorrect, or no API key error?

Our [<mark style="color:blue;">How-Tos</mark>](https://docs.ionos.com/sections-test/guides/ai/ai-model-hub/how-tos) documentation assume you have an environment variable called **IONOS\_API\_TOKEN**. The value of this environment variable needs to be a valid **Authentication Token**. If you get the described error, two reasons are possible:

* **IONOS\_API\_TOKEN** is not set: Check whether your system's environment variable is set. The simplest way to do this is by adding the line

  ```python
  import os
  print(os.environ.get("IONOS_API_TOKEN"))
  ```

  to your code. If nothing is shown, the environment variable is not set. Please set it.
* Your **Authentication Token** is not valid: If the **IONOS\_API\_TOKEN** environment variable is set, but you still see this error, your authentication token might not be valid. Create a new **Authentication Token** as described in [<mark style="color:blue;">Access Management</mark>](https://docs.ionos.com/sections-test/guides/ai/ai-model-hub/how-tos/access-management).

### How do I fix a `404 Not Found` error?

Communication with the AI Model Hub is by API endpoints. These endpoints often contain IDs, like the **Collection ID**, a **Model ID** or some similar ID. One typical example of such an API endpoint is the endpoint to see all uploaded documents in a specific document collection:

```python
f"https://inference.de-txl.ionos.com/collections/{COLLECTION_ID}/documents"
```

Notice that the variable `COLLECTION_ID` is part of the API endpoint URL. If you, for example, have previously deleted this endpoint, a request to it will return a '404 Not Found' error.

To ensure the ID exists, invoke the higher-level endpoint with a get request. This will return a list of all entries, and you can choose one of the existing **IDs**. In the above example, the Python command could be:

```python
import requests
HEADERS = {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
    'Authorization': f'Bearer {IONOS_API_TOKEN}',
}
print(requests.get(f"https://inference.de-txl.ionos.com/collections", headers=HEADERS).json())
```

An entry **item** exists in the resulting JSON document, which gathers all available document collections.

### How do I fix a `500 Internal Server` error?

We do our best to ensure our service is operational 24 hours, 7 days a week. If `500 Internal Server` errors occur, it may be due to too much traffic on the AI Model Hub or an urgent infrastructure fix. Please retry your request. If the problem persists, contact [<mark style="color:blue;">IONOS Cloud Support</mark>](https://docs.ionos.com/cloud/support/general-information/contact-information).

## Cost & Usage

### How can I monitor the costs incurred through usage of the AI Model Hub?

You can monitor your AI Model Hub costs and usage for your contract in the [<mark style="color:blue;">Costs & Usage</mark>](https://docs.ionos.com/cloud/set-up-ionos-cloud/management/usage/cost-and-usage) section of the DCD. Usage data is broken down by model and token type, whether input or output tokens, to give you detailed insight into your consumption. It is displayed in blocks of one million tokens for embedding and large language models, and by image count for image-based models.

**Prerequisites:** You must be one of the following to access the **Cost & Usage** view:

| **Contract Type**  | **Contract Users**                                | **Accessible?** |
| ------------------ | ------------------------------------------------- | --------------- |
| Regular contracts  | <p>Contract administrators<br>Contract owners</p> | <p>✅<br>✅</p>   |
| Reseller contracts | Contract owners                                   | ✅               |
