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

# Handling errors

> Catch and respond to invalid requests, authentication issues and more.

When using our API, it is crucial to anticipate and handle errors effectively.

To aid in this process, our API utilizes a standardized format for returning error messages.

These error responses provide detailed information on the nature of the error, by adhering to this format, developers can easily identify and resolve issues when they arise, improving the overall reliability and efficiency of the API integration.

## Errors in responses

<Info>
  Rated API's errors will always be returned as JSON
</Info>

Errors will always come in a dictionary containing a `detail` key and its value can be either a list of dictionaries or a string describing the error message.

### 400 Bad Request

<CodeGroup>
  ```json Wrong body theme={null}
  {
    "detail": [
      {
        "loc": ["body", "email"],
        "msg": "value is not a valid email address",
        "type": "value_error.email",
      }
    ]
  }
  ```

  ```json Wrong query parameters theme={null}
  {
    "detail": [
      {
        "loc": [
          "query",
          "pubkeys",
          0
        ],
        "msg": "Invalid public key",
        "type": "value_error"
      }
    ]
  }
  ```
</CodeGroup>

### 401 Unauthorized

<Tabs>
  <Tab title="No token given">
    ```json theme={null}
    {"detail": "Not authenticated"}
    ```

    **Reason:** You forgot to send the `Authorization` header with a `Bearer` token.
  </Tab>

  <Tab title="Invalid token">
    ```json theme={null}
    {"detail": "Could not validate access token."}
    ```

    **Reason:** The token you are using is not from us. You need to get and use valid token.
  </Tab>

  <Tab title="Expired token">
    ```json theme={null}
    {"detail": "Expired token."}
    ```

    **Reason:** Self-explanatory, you need to get a new token at [console.rated.network/apiKeys](https://console.rated.network/apiKeys).
  </Tab>

  <Tab title="Unknown token">
    ```json theme={null}
    {"detail": "Unknown token."}
    ```

    **Reason:** The token might be valid before but we don't know it anymore. Most likely, it was invalidated after a password reset.
  </Tab>
</Tabs>

### 403 Forbidden

```json theme={null}
{"detail": "You don't have permission to do that."}
```

**Reason:** The token you are using does not have enough permission to perform the request.

### 404 Not Found

```json theme={null}
{"detail": "Not found."}
```

**Reason:** The resource you requested was not found. Double check the [API Reference](/rated-api/api-reference/introduction).

### 429 Too many requests

```json theme={null}
{"detail": "Too many requests"}
```

**Reason:** You have hit too quick too many times the API. Back-off and retry later.

### 500, 502, 504 Server errors

```json theme={null}
{"detail": "Internal server error."}
```

**Reason:** Something went wrong on our side, these are rare. In case you need assistance contact us and provide the [Request ID](/rated-api/interacting-with-api/request-ids) and we will gladly help you.
