> ## Documentation Index
> Fetch the complete documentation index at: https://api-docs-beta-7agmae.voicedub.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication

> Learn how to authenticate your requests to the VoiceDub API using API keys

The VoiceDub API uses API keys for authentication. All API requests must include your API key in the `Authorization` header.

## Getting Your API Key

<Steps>
  <Step title="Create an account">
    Sign up for a VoiceDub account at [voicedub.ai](https://voicedub.ai) if you haven't already.
  </Step>

  <Step title="Navigate to developer dashboard">
    Go to the [Developer Dashboard](https://voicedub.ai/developer/dashboard) after logging in.
  </Step>

  <Step title="Generate an API key">
    Click "Create API Key" and give it a descriptive name for easy identification.

    <Warning>
      Store your API key securely. It won't be shown again after creation.
    </Warning>
  </Step>

  <Step title="Add credits to your account">
    Purchase API credits from the [Billing Dashboard](https://voicedub.ai/developer/billing) to start using the API.
  </Step>
</Steps>

## Making Authenticated Requests

Include your API key in the `Authorization` header with the format `Api-Key YOUR_API_KEY`:

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET 'https://api.voicedub.ai/v1/me' \
    -H 'Authorization: Api-Key YOUR_API_KEY'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://api.voicedub.ai/v1/me', {
    headers: {
      'Authorization': 'Api-Key YOUR_API_KEY'
    }
  });
  ```

  ```python Python theme={null}
  import requests

  headers = {
      'Authorization': 'Api-Key YOUR_API_KEY'
  }

  response = requests.get('https://api.voicedub.ai/v1/me', headers=headers)
  ```
</CodeGroup>

## API Key Management

### Best Practices

<Tip>
  Follow these security best practices when working with API keys:
</Tip>

* **Never commit API keys to version control** - Use environment variables instead
* **Use different API keys for different environments** (development, staging, production)
* **Rotate API keys regularly** for enhanced security
* **Monitor API key usage** in your developer dashboard
* **Delete unused API keys** to minimize security risk

### Environment Variables

Store your API key as an environment variable:

<Tabs>
  <Tab title="macOS/Linux">
    ```bash theme={null}
    export VOICEDUB_API_KEY="your_api_key_here"
    ```
  </Tab>

  <Tab title="Windows">
    ```powershell theme={null}
    $env:VOICEDUB_API_KEY="your_api_key_here"
    ```
  </Tab>

  <Tab title=".env file">
    ```bash theme={null}
    VOICEDUB_API_KEY=your_api_key_here
    ```
  </Tab>
</Tabs>

Then reference it in your code:

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET 'https://api.voicedub.ai/v1/me' \
    -H "Authorization: Api-Key $VOICEDUB_API_KEY"
  ```

  ```javascript Node.js theme={null}
  const apiKey = process.env.VOICEDUB_API_KEY;

  const response = await fetch('https://api.voicedub.ai/v1/me', {
    headers: {
      'Authorization': `Api-Key ${apiKey}`
    }
  });
  ```

  ```python Python theme={null}
  import os
  import requests

  api_key = os.getenv('VOICEDUB_API_KEY')

  headers = {
      'Authorization': f'Api-Key {api_key}'
  }

  response = requests.get('https://api.voicedub.ai/v1/me', headers=headers)
  ```
</CodeGroup>

## Error Responses

### 401 Unauthorized

This error occurs when your API key is missing, invalid, or malformed:

**401 Unauthorized:**

```json theme={null}
{
  "code": "unauthorized",
  "message": "Invalid API key"
}
```

**Common causes:**

* Missing `Authorization` header
* Incorrect API key format (should be `Api-Key YOUR_KEY`)
* Using a deleted or invalid API key
* API key not properly URL-encoded

### 403 Insufficient Credits

This error occurs when you don't have enough API credits:

**403 Insufficient Credits:**

```json theme={null}
{
  "code": "not_enough_credits",
  "message": "Looks like you don't have enough credits! Purchase more at https://voicedub.ai/developer/billing"
}
```

**Solution:** [Purchase more credits](https://voicedub.ai/developer/billing) or check your credit balance using the `/v1/me` endpoint.

## Rate Limits

The VoiceDub API implements rate limiting to ensure fair usage:

* **100 requests per minute** per API key
* **1,000 requests per hour** per API key

When you exceed the rate limit, you'll receive a `429 Too Many Requests` response:

**429 Too Many Requests:**

```json theme={null}
{
  "code": "rate_limit_exceeded", 
  "message": "Rate limit exceeded. Please wait before making more requests."
}
```

<Info>
  Rate limits are enforced per API key, so you can use multiple keys to increase your throughput if needed.
</Info>

## Testing Your Authentication

Verify your API key is working correctly by making a test request:

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET 'https://api.voicedub.ai/v1/me' \
    -H 'Authorization: Api-Key YOUR_API_KEY'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://api.voicedub.ai/v1/me', {
    headers: {
      'Authorization': 'Api-Key YOUR_API_KEY'
    }
  });

  const data = await response.json();
  console.log('Credits available:', data.user.apiCredits);
  ```

  ```python Python theme={null}
  import requests

  headers = {
      'Authorization': 'Api-Key YOUR_API_KEY'
  }

  response = requests.get('https://api.voicedub.ai/v1/me', headers=headers)
  data = response.json()
  print('Credits available:', data['user']['apiCredits'])
  ```
</CodeGroup>

<Accordion title="Show Response">
  ```json theme={null}
  {
    "user": {
      "apiCredits": 1000
    }
  }
  ```
</Accordion>

This endpoint returns your current API credit balance and confirms your authentication is working properly.

<Check>
  If you receive your credit balance, your API key is configured correctly!
</Check>
