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

# Authentication

> How to authenticate requests to the Prezio API using Bearer tokens and API keys

Prezio API uses Bearer token authentication as the standard method for both environments. API keys are available as a convenience option in sandbox.

## Authentication Methods

<CardGroup cols={2}>
  <Card title="Bearer Tokens" icon="shield-check" color="#83b5ab">
    **Standard Method**: For both production and sandbox

    ```bash theme={null}
    Authorization: Bearer YOUR_ACCESS_TOKEN
    ```
  </Card>

  <Card title="API Keys" icon="key" color="#c7beff">
    **Sandbox Convenience**: Additional option for quick testing

    ```bash theme={null}
    Authorization: Token YOUR_API_KEY
    ```
  </Card>
</CardGroup>

## Bearer Token Authentication

<Steps>
  <Step title="Obtain Bearer tokens">
    ```bash theme={null}
    curl -X POST "https://api.prezio.eu/api/auth/token/" \
      -H "Content-Type: application/json" \
      -d '{"username": "your_username", "password": "your_password"}'
    ```
  </Step>

  <Step title="Use in requests">
    ```bash theme={null}
    Authorization: Bearer YOUR_ACCESS_TOKEN
    ```
  </Step>

  <Step title="Refresh when needed">
    ```bash theme={null}
    curl -X POST "https://api.prezio.eu/api/auth/token/refresh/" \
      -H "Content-Type: application/json" \
      -d '{"refresh": "YOUR_REFRESH_TOKEN"}'
    ```
  </Step>
</Steps>

## API Key Authentication (Sandbox)

Get API keys from [dashboard.prezio.eu](https://dashboard.prezio.eu) or contact [support@prezio.eu](mailto:support@prezio.eu).

```bash theme={null}
Authorization: Token YOUR_API_KEY
```

<Note>
  API keys are a sandbox convenience feature. Bearer tokens are the standard method for both environments.
</Note>

## Example Usage

<CodeGroup>
  ```bash Production theme={null}
  curl -X GET "https://api.prezio.eu/api/live/?country=DK&tariff_id=tar_123" \
    -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
  ```

  ```bash Sandbox (Bearer) theme={null}
  curl -X GET "https://sandbox.prezio.eu/api/live/?country=DK&tariff_id=tar_123" \
    -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
  ```

  ```bash Sandbox (API Key) theme={null}
  curl -X GET "https://sandbox.prezio.eu/api/live/?country=DK&tariff_id=tar_123" \
    -H "Authorization: Token YOUR_API_KEY"
  ```
</CodeGroup>

## Security Best Practices

* Store tokens securely, never expose in client-side code
* Implement token refresh logic before expiration
* Use HTTPS for all requests
* Rotate API keys periodically

## Common Errors

| Status | Error             | Solution                                   |
| ------ | ----------------- | ------------------------------------------ |
| 401    | Invalid token     | Refresh your Bearer token or check API key |
| 403    | Permission denied | Contact support for access permissions     |

<Warning>
  Authentication failures count toward rate limits. Implement proper error handling.
</Warning>

Need help? Contact [support@prezio.eu](mailto:support@prezio.eu).
