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

# Authentication

> Learn how to authenticate with the Babou API using API keys

## Overview

Every API request needs an API key in the `Authorization` header. Get your key from the dashboard, add it to requests as a Bearer token, start building.

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

## Getting Your API Key

1. Sign up or log in at [babou.ai](https://babou.ai)
2. Navigate to your **Dashboard**
3. Go to **Settings** → **API Keys**
4. Click **Create New API Key**
5. Copy your key immediately (it won't be shown again)

<Note>
  API keys follow the format: `sk-bab-[random-string]`
</Note>

## Making Authenticated Requests

Include your API key in the `Authorization` header of every request:

```bash theme={null}
Authorization: Bearer sk-bab-your-api-key-here
```

### Examples

<CodeGroup>
  ```bash curl theme={null}
  curl https://api.babou.ai/api/v1/projects \
    -H "Authorization: Bearer sk-bab-your-api-key-here" \
    -H "Content-Type: application/json"
  ```

  ```typescript TypeScript theme={null}
  const BABOU_API_KEY = process.env.BABOU_API_KEY;

  const response = await fetch('https://api.babou.ai/api/v1/projects', {
    method: 'GET',
    headers: {
      'Authorization': `Bearer ${BABOU_API_KEY}`,
      'Content-Type': 'application/json'
    }
  });

  const data = await response.json();
  console.log(data);
  ```

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

  BABOU_API_KEY = os.environ.get('BABOU_API_KEY')

  response = requests.get(
      'https://api.babou.ai/api/v1/projects',
      headers={
          'Authorization': f'Bearer {BABOU_API_KEY}',
          'Content-Type': 'application/json'
      }
  )

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

## API Key Management

### Security Best Practices

<AccordionGroup>
  <Accordion title="Store keys in environment variables">
    Never hardcode API keys in your source code. Use environment variables:

    ```bash theme={null}
    export BABOU_API_KEY=sk-bab-your-api-key-here
    ```

    Or use a `.env` file (and add it to `.gitignore`):

    ```bash theme={null}
    BABOU_API_KEY=sk-bab-your-api-key-here
    ```
  </Accordion>

  <Accordion title="Rotate keys regularly">
    Create new API keys periodically and delete old ones from your dashboard to maintain security.
  </Accordion>

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

  <Accordion title="Monitor key usage">
    Check your dashboard regularly for unexpected API usage that might indicate a compromised key.
  </Accordion>
</AccordionGroup>

### Key Expiration

API keys can have expiration dates. You'll receive a `401 Unauthorized` error if your key has expired:

```json theme={null}
{
  "error": "API key has expired",
  "code": "API_KEY_EXPIRED"
}
```

## Authentication Errors

### Common Error Responses

<ResponseField name="UNAUTHORIZED" type="401">
  Invalid or missing API key

  ```json theme={null}
  {
    "error": "Unauthorized - Invalid API key",
    "code": "UNAUTHORIZED"
  }
  ```
</ResponseField>

<ResponseField name="INVALID_API_KEY_FORMAT" type="401">
  API key doesn't match expected format (`sk-bab-*`)

  ```json theme={null}
  {
    "error": "Invalid API key format",
    "code": "INVALID_API_KEY_FORMAT"
  }
  ```
</ResponseField>

<ResponseField name="API_KEY_EXPIRED" type="401">
  The API key has expired

  ```json theme={null}
  {
    "error": "API key has expired",
    "code": "API_KEY_EXPIRED"
  }
  ```
</ResponseField>

## Testing Your Authentication

Use this simple request to verify your API key is working:

<CodeGroup>
  ```bash curl theme={null}
  curl https://api.babou.ai/api/v1/projects \
    -H "Authorization: Bearer sk-bab-your-api-key-here"
  ```

  ```typescript TypeScript theme={null}
  async function testAuth() {
    const response = await fetch('https://api.babou.ai/api/v1/projects', {
      headers: {
        'Authorization': `Bearer ${process.env.BABOU_API_KEY}`
      }
    });

    if (response.ok) {
      console.log('✓ Authentication successful!');
    } else {
      console.error('✗ Authentication failed:', await response.json());
    }
  }

  testAuth();
  ```

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

  def test_auth():
      response = requests.get(
          'https://api.babou.ai/api/v1/projects',
          headers={'Authorization': f'Bearer {os.environ["BABOU_API_KEY"]}'}
      )

      if response.ok:
          print('✓ Authentication successful!')
      else:
          print('✗ Authentication failed:', response.json())

  test_auth()
  ```
</CodeGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Quickstart Guide" icon="rocket" href="/quickstart">
    Create your first video project
  </Card>

  <Card title="API Reference" icon="book" href="/api-reference/overview">
    Explore all available endpoints
  </Card>
</CardGroup>
