# Authentication

The Bizora Integration API uses API keys for authentication. All requests must include a valid API key.

## API Key Format

API keys start with `sk_live_` followed by a random string:

```
sk_live_abc123def456ghi789...
```

## How to Authenticate

### Option 1: Authorization Header (Recommended)

```bash
Authorization: Bearer sk_live_YOUR_API_KEY
```

### Option 2: X-Api-Key Header

```bash
X-Api-Key: sk_live_YOUR_API_KEY
```

## Examples

### SDK Examples

```python
import openai

client = openai.OpenAI(
    api_key="sk_live_YOUR_API_KEY",  # Your API key
    base_url="https://api-bizora.ai"
)
```

```javascript
import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: 'sk_live_YOUR_API_KEY',
  baseURL: 'https://api-bizora.ai'
});
```

```bash
curl -X POST https://api-bizora.ai/chat/completions \
  -H "Authorization: Bearer sk_live_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "bizora-1.0", "messages": [...]}'
```

## Managing API Keys

### Creating a Key

1. Go to https://platform.bizora.ai
2. Navigate to **API Keys** section
3. Click **Create New Key**
4. Give it a descriptive name
5. Copy the key (shown only once!)

### Revoking a Key

If your API key is compromised:

1. Go to **API Keys** section
2. Find the key you want to revoke
3. Click **Revoke Key**
4. Create a new key to replace it

## Security Best Practices

:::danger Keep Your API Key Secret
Never share your API key or commit it to version control!
:::

### ✅ Do's

- Store API keys in environment variables
- Use different keys for development and production
- Rotate keys regularly
- Revoke unused keys

### ❌ Don'ts

- Don't commit API keys to Git
- Don't share keys in public forums
- Don't use the same key across multiple projects
- Don't expose keys in client-side code

## Environment Variables

Store your API key securely:

```bash
# .env file
BIZORA_API_KEY=sk_live_YOUR_API_KEY
```

```python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.getenv("BIZORA_API_KEY"),
    base_url="https://api-bizora.ai"
)
```

```javascript
import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: process.env.BIZORA_API_KEY,
  baseURL: 'https://api-bizora.ai'
});
```

## Error Responses

### 401 Unauthorized

Missing or invalid API key:

```json
{
  "error": {
    "message": "Invalid API key",
    "type": "authentication_error",
    "code": null
  }
}
```

### 402 Payment Required

Insufficient balance:

```json
{
  "error": {
    "type": "insufficient_balance",
    "message": "Your API balance is insufficient...",
    "details": {
      "balance_before_cents": 50,
      "cost_cents": 100
    }
  }
}
```

## Next Steps

- Learn about [Rate Limits](./chat-completions/rate-limits)
- Explore the [API Reference](./chat-completions/overview)
- Check [Error Handling](./chat-completions/error-handling)
