# API Keys

> Authenticate requests to Sendable with session-scoped API keys.

Source: https://wav1.recrav.com/docs/api-keys

## Creating an API Key [#creating-an-api-key]

1. Navigate to your [Dashboard](/dashboard)
2. Select the session you want to use
3. Go to the "API Keys" tab
4. Click "Generate New Key"
5. Copy the key immediately (it's only shown once)

## Using API Keys [#using-api-keys]

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

```bash
curl -X POST "https://api.sendable.dev/messages/send" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"to":"6281234567890","text":"Hello"}'
```

## Best Practices [#best-practices]

### Store Keys Securely [#store-keys-securely]

Never commit API keys to version control. Use environment variables:

```bash
## .env
SENDABLE_API_KEY=your_api_key_here
```

```typescript
// config.ts
export const SENDABLE_API_KEY = process.env.SENDABLE_API_KEY

if (!SENDABLE_API_KEY) {
  throw new Error('SENDABLE_API_KEY is required')
}
```

### Use Separate Keys for Different Environments [#use-separate-keys-for-different-environments]

Create different keys for development, staging, and production:

| Environment | Session         | API Key        |
| ----------- | --------------- | -------------- |
| Development | dev-session     | sk_dev_xxx     |
| Staging     | staging-session | sk_staging_xxx |
| Production  | prod-session    | sk_prod_xxx    |

### Rotate Keys Regularly [#rotate-keys-regularly]

Rotate your API keys every 90 days:

1. Generate a new key
2. Update your application configuration
3. Revoke the old key
4. Monitor for any errors

### Revoke Compromised Keys [#revoke-compromised-keys]

If you suspect a key has been compromised:

1. Revoke the key immediately in the dashboard
2. Generate a new key
3. Update your application
4. Review API logs for unauthorized usage

## Key Permissions [#key-permissions]

API keys inherit permissions from their associated session:

* Send messages
* Receive webhooks
* Access session status
* Manage webhooks

## Error Handling [#error-handling]

Invalid or expired keys return a `401 Unauthorized` error:

```json
{
  "success": false,
  "error": {
    "code": "UNAUTHORIZED",
    "message": "Invalid or expired API key"
  }
}
```

See [Error Handling](/docs/errors) for more details.
