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

# Authentication

> How to authenticate requests to the Prezio API

Prezio API uses key-based authentication for all requests. We support both standard API keys and JSON Web Tokens (JWT). This guide explains how to obtain and use API keys effectively.

## Authentication Flow

<Steps>
  <Step title="Obtain an API key">
    Get your unique API key through the Prezio customer dashboard or by contacting support.
  </Step>

  <Step title="Include the key in requests">
    Add your key to the Authorization header with prefix `Token` for all API requests.
  </Step>

  <Step title="Access API resources">
    Make authenticated requests to any Prezio API endpoint you have permission to access.
  </Step>
</Steps>

## Obtaining API Keys

<CardGroup cols={2}>
  <Card title="Customer Dashboard" icon="gauge" color="#83b5ab">
    1. Sign up and log in to the [Prezio Customer Dashboard](https://dashboard.prezio.eu)
    2. Navigate to the API section
    3. Find your API key with appropriate permissions
    4. Copy the key securely for use in your applications
  </Card>

  <Card title="Contact Support" icon="headset" color="#c7beff">
    For enterprise access or if you don't have dashboard access, contact:

    [support@prezio.eu](mailto:support@prezio.eu)

    Include your account details and required access level.
  </Card>
</CardGroup>

<Note>
  Upon initial registration, users receive a sandbox API key valid for a limited period of time to test the API. Our team will contact you to discuss extending access and support your integration based on your needs.
</Note>

## Using API Keys

Include your API key in the HTTP Authorization header with the prefix `Token`:

```bash
Authorization: Token YOUR_API_KEY
```

### Example Requests

<CodeGroup>
  ```bash cURL
  curl -X GET "https://api.prezio.eu/api/live/?country=DK&tariff_id=tar_123" \
    -H "Authorization: Token YOUR_API_KEY"
  ```

  ```javascript JavaScript
  fetch('https://api.prezio.eu/api/live/?country=DK&tariff_id=tar_123', {
    headers: {
      'Authorization': 'Token YOUR_API_KEY'
    }
  })
  .then(response => response.json())
  .then(data => console.log(data));
  ```

  ```python Python
  import requests

  headers = {
      'Authorization': 'Token YOUR_API_KEY'
  }

  response = requests.get(
      'https://api.prezio.eu/api/live/',
      headers=headers,
      params={'country': 'DK', 'tariff_id': 'tar_123'}
  )

  data = response.json()
  ```
</CodeGroup>

## Security Best Practices

<AccordionGroup>
  <Accordion title="API Key Storage" defaultOpen icon="lock">
    * Use environment variables or secure vaults
    * Never hardcode API keys in application code
    * Keep API keys out of client-side code
    * Use the same API key for both sandbox and production environments
  </Accordion>

  <Accordion title="API Key Lifecycle" icon="arrows-rotate">
    * API keys do not expire automatically
    * Rotate API keys periodically as a security measure
    * Revoke compromised API keys immediately
    * Consider using separate API keys for different applications if needed
  </Accordion>
</AccordionGroup>

## Handling Authentication Errors

<CardGroup cols={2}>
  <Card title="401 Unauthorized" icon="circle-exclamation" color="#ffb07c">
    ```json
    {
      "detail": "Invalid token."
    }
    ```

    The API key is invalid, expired, or missing. Verify you're using the correct API key with the "Token" prefix.
  </Card>

  <Card title="403 Forbidden" icon="ban" color="#f4867e">
    ```json
    {
      "detail": "You do not have permission to perform this action."
    }
    ```

    Your API key lacks permission for the requested resource. Contact support to adjust permissions.
  </Card>
</CardGroup>

<Warning>
  Authentication failures count toward your rate limits. Implement proper error handling to avoid excessive authentication attempts.
</Warning>

## Environment-Specific Access

Use the same API key for both environments, but make requests to different base URLs:

```bash
# Sandbox environment (open access)
curl -X GET "https://sandbox.prezio.eu/api/live/..." \
  -H "Authorization: Token YOUR_API_KEY"

# Production environment (requires contract)
curl -X GET "https://api.prezio.eu/api/live/..." \
  -H "Authorization: Token YOUR_API_KEY"
```

<Note>
  **Sandbox access** is available to all registered users. **Production access** depends on your contract - contact our support team at [support@prezio.eu](mailto:support@prezio.eu) to enable production access.
</Note>

For questions regarding authentication or API key management, contact our support team at [support@prezio.eu](mailto:support@prezio.eu).
