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

# Authentication

> Authenticate with an API key through Authorization: Bearer, x-api-key, or x-goog-api-key headers.

## Authentication methods

AIOHub supports multiple authentication headers for different client types:

| Method                | Header                         | Client                                              |
| --------------------- | ------------------------------ | --------------------------------------------------- |
| Bearer auth           | `Authorization: Bearer sk-xxx` | OpenAI SDK, Codex CLI, most OpenAI-compatible tools |
| Anthropic API Key     | `x-api-key: sk-xxx`            | Anthropic SDK                                       |
| Anthropic bearer auth | `Authorization: Bearer sk-xxx` | Claude Code (`ANTHROPIC_AUTH_TOKEN`)                |
| Google API Key        | `x-goog-api-key: sk-xxx`       | Gemini CLI, Google SDK                              |

All methods use the same `sk-` API key value. AIOHub automatically detects the authentication format.

## Examples

<CodeGroup>
  ```bash cURL (Bearer) theme={"system"}
  curl https://api.aiohub.org/v1/chat/completions \
    -H "Authorization: Bearer sk-your-api-key" \
    -H "Content-Type: application/json" \
    -d '{"model": "gpt-4o", "messages": [{"role": "user", "content": "Hi"}]}'
  ```

  ```bash cURL (x-api-key) theme={"system"}
  curl https://api.aiohub.org/v1/messages \
    -H "x-api-key: sk-your-api-key" \
    -H "Content-Type: application/json" \
    -H "anthropic-version: 2023-06-01" \
    -d '{"model": "claude-sonnet-4-20250514", "max_tokens": 1024, "messages": [{"role": "user", "content": "Hi"}]}'
  ```

  ```python Python (OpenAI SDK) theme={"system"}
  from openai import OpenAI

  client = OpenAI(
      base_url="https://api.aiohub.org/v1",
      api_key="sk-your-api-key"
  )
  ```

  ```python Python (Anthropic SDK) theme={"system"}
  import anthropic

  client = anthropic.Anthropic(
      base_url="https://api.aiohub.org",
      api_key="sk-your-api-key"
  )
  ```

  ```javascript Node.js (OpenAI SDK) theme={"system"}
  import OpenAI from "openai";

  const client = new OpenAI({
    baseURL: "https://api.aiohub.org/v1",
    apiKey: "sk-your-api-key",
  });
  ```
</CodeGroup>

## Common authentication errors

| Status | Cause                                                    | Fix                                                                          |
| ------ | -------------------------------------------------------- | ---------------------------------------------------------------------------- |
| 401    | API key is invalid, expired, or sent in the wrong header | Check that the API key is complete, enabled, and sent in the expected header |
| 403    | API key cannot access the requested model                | Confirm the API key group includes the model and endpoint                    |
| 429    | Rate limit reached                                       | Slow down requests and check console announcements or current limits         |

## Verify your API key

Send a small request to verify the API key:

```bash theme={"system"}
curl https://api.aiohub.org/v1/models \
  -H "Authorization: Bearer sk-your-api-key"
```

A successful response with a model list confirms your API key is valid.
