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

# Authentication & API Keys

> Learn how to authenticate with the CAMB.AI API

All CAMB.AI API requests require authentication using an API key. This guide explains how to obtain and use your API key.

## Getting Your API Key

1. Go to [CAMB.AI Studio](https://studio.camb.ai)
2. Sign in or create an account
3. Navigate to your account settings
4. Generate or copy your API key

<Warning>
  Keep your API key secure. Never expose it in client-side code or public repositories.
</Warning>

## Using Your API Key

Include your API key in the `x-api-key` header of every request.

### Header Format

```
x-api-key: your_camb_api_key
```

### Example Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://client.camb.ai/apis/tts-stream" \
    -H "x-api-key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "text": "Hello world!",
      "voice_id": 147320
    }'
  ```

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

  headers = {
      "x-api-key": "YOUR_API_KEY",
      "Content-Type": "application/json"
  }

  response = requests.post(
      "https://client.camb.ai/apis/tts-stream",
      headers=headers,
      json={"text": "Hello world!", "voice_id": 147320}
  )
  ```

  ```typescript TypeScript theme={null}
  const response = await fetch("https://client.camb.ai/apis/tts-stream", {
    method: "POST",
    headers: {
      "x-api-key": "YOUR_API_KEY",
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      text: "Hello world!",
      voice_id: 147320
    })
  });
  ```
</CodeGroup>

## SDK Authentication

When using the official SDKs, pass your API key during client initialization.

<CodeGroup>
  ```python Python SDK theme={null}
  from camb.client import CambAI

  client = CambAI(api_key="your_api_key")
  # Or use environment variable
  client = CambAI(api_key=os.getenv("CAMB_API_KEY"))
  ```

  ```typescript TypeScript SDK theme={null}
  import { CambClient } from '@camb-ai/sdk';

  const client = new CambClient({ apiKey: "YOUR_API_KEY" });
  // Or use environment variable
  const client = new CambClient({ apiKey: process.env.CAMB_API_KEY });
  ```
</CodeGroup>

## Error Responses

| Status Code | Meaning                                           |
| ----------- | ------------------------------------------------- |
| `401`       | Invalid or missing API key                        |
| `403`       | API key doesn't have permission for this resource |
| `429`       | Rate limit exceeded                               |

### Example Error Response

```json theme={null}
{
  "error": "Invalid API key",
  "status": 401
}
```

## Best Practices

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

  <Accordion title="Rotate keys periodically">
    Generate new API keys regularly and revoke old ones.
  </Accordion>

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

  <Accordion title="Monitor usage">
    Check your API usage in CAMB.AI Studio to detect unauthorized access.
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Quick Start" icon="rocket" href="/getting-started/quickstart">
    Make your first API call
  </Card>

  <Card title="SDK Guide" icon="code" href="/sdk-guides/general-guide">
    Use our official SDKs
  </Card>
</CardGroup>
