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

# Authentication

> Learn how to authenticate your API requests

All API requests to VoidAI require authentication using an API key. Your API key should be included in the `Authorization` header of every request.

## API Key Format

VoidAI API keys follow this format:

```
sk-voidai-xxxxxxxxxxxxxxxxxxxx
```

## Making Authenticated Requests

Include your API key in the `Authorization` header using the Bearer token scheme:

<CodeGroup>
  ```python Python theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key="sk-voidai-your_key_here",
      base_url="https://api.voidai.app/v1"
  )
  ```

  ```typescript TypeScript theme={null}
  import OpenAI from 'openai';

  const client = new OpenAI({
    apiKey: 'sk-voidai-your_key_here',
    baseURL: 'https://api.voidai.app/v1'
  });
  ```

  ```bash cURL theme={null}
  curl https://api.voidai.app/v1/chat/completions \
    -H "Authorization: Bearer sk-voidai-your_key_here" \
    -H "Content-Type: application/json" \
    -d '{"model": "gpt-4", "messages": [{"role": "user", "content": "Hello"}]}'
  ```
</CodeGroup>

## Managing API Keys

You can create and manage multiple API keys from your [dashboard](https://voidai.app). Each key can be:

* **Named** for easy identification (e.g., "Production", "Development")
* **Enabled/Disabled** without deletion
* **Deleted** permanently when no longer needed

<Warning>
  Treat your API keys like passwords. Never commit them to version control, share them publicly, or include them in client-side code.
</Warning>

## Environment Variables

We recommend storing your API key in an environment variable:

<CodeGroup>
  ```bash .env theme={null}
  VOIDAI_API_KEY=sk-voidai-your_key_here
  ```

  ```python Python theme={null}
  import os
  from openai import OpenAI

  client = OpenAI(
      api_key=os.environ.get("VOIDAI_API_KEY"),
      base_url="https://api.voidai.app/v1"
  )
  ```

  ```typescript TypeScript theme={null}
  import OpenAI from 'openai';

  const client = new OpenAI({
    apiKey: process.env.VOIDAI_API_KEY,
    baseURL: 'https://api.voidai.app/v1'
  });
  ```
</CodeGroup>

## Authentication Errors

| Error Code         | Description                                           |
| ------------------ | ----------------------------------------------------- |
| `MISSING_HEADER`   | No `Authorization` header provided                    |
| `INVALID_FORMAT`   | Header format is incorrect (must be `Bearer <token>`) |
| `INVALID_KEY`      | The API key does not exist or is incorrect            |
| `ACCOUNT_DISABLED` | Your account has been disabled                        |
| `IP_ACCESS_DENIED` | Request IP is not in your allowlist                   |

### Example Error Response

```json theme={null}
{
  "error": {
    "message": "Invalid API key provided",
    "type": "api_error",
    "code": "INVALID_KEY",
    "reference_id": "req_1701691200_abc123",
    "timestamp": "2024-12-04T12:00:00.000Z"
  }
}
```

## IP Allowlisting

For enhanced security, you can restrict API access to specific IP addresses from your dashboard. When enabled, requests from non-allowlisted IPs will be rejected.

<Info>
  IP allowlisting is optional. If no IPs are configured, requests from any IP address will be accepted.
</Info>

## Best Practices

<AccordionGroup>
  <Accordion title="Use environment variables">
    Never hardcode API keys in your source code. Use environment variables or secure secret management systems.
  </Accordion>

  <Accordion title="Rotate keys regularly">
    Periodically regenerate your API keys, especially for production environments.
  </Accordion>

  <Accordion title="Use separate keys for environments">
    Create different API keys for development, staging, and production environments.
  </Accordion>

  <Accordion title="Monitor usage">
    Regularly check your dashboard for unusual activity or unexpected usage patterns.
  </Accordion>
</AccordionGroup>
