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

# AI API authentication

> How to authenticate with the Livepeer AI Gateway API: API key types, CORS configuration, rotation strategy, and security patterns.

> [!TIP]
>
> Backend API keys have full API access and must never appear in client-side code. CORS-enabled keys are scoped and safe for browser use.

***

Every request to the Livepeer AI Gateway API requires a Bearer token. Obtain one from [Livepeer Studio](https://livepeer.studio) under **Settings > API Keys**. Two key types exist -- choose based on where your code runs.

Key Types

## API key types

<table>
  <thead>
    <tr>
      Type

      Where to use

      Scope

      Risk if leaked
    </tr>
  </thead>

  <tbody>
    <tr>
      **Backend API key**

      Server-side code, scripts, CI/CD pipelines

      Full access to all Studio API resources

      Full account access -- rotate immediately
    </tr>

    <tr>
      **CORS-enabled key**

      Browser JavaScript, frontend applications

      Scoped to specific asset and stream IDs

      Limited to scoped resources only
    </tr>
  </tbody>
</table>

A backend key in client-side code is a critical security vulnerability. Use the correct type for the deployment context.

Usage

## Using a backend API key

Pass the key as a Bearer token in the `Authorization` header:

```bash theme={null}
curl -X POST https://livepeer.studio/api/beta/generate/text-to-image \
  -H "Authorization: Bearer $LIVEPEER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"prompt": "a mountain at dawn", "model_id": "SG161222/RealVisXL_V4.0_Lightning"}'
```

In environment variables:

```bash theme={null}
# .env (never commit this file)
LIVEPEER_API_KEY=your-api-key-here
```

```typescript theme={null}
// Never hardcode -- always read from environment
const client = new Livepeer({ apiKey: process.env.LIVEPEER_API_KEY });
```

CORS Keys

## CORS-enabled keys for browser applications

When your frontend makes direct API calls, create a CORS-enabled key in Studio. The Studio dashboard scopes the key to specific asset or stream IDs -- a leaked CORS key cannot access other resources in your account.

Create in Studio: **Settings > API Keys > Create Key > Enable CORS**.

```typescript theme={null}
// Safe to bundle in a React or Next.js frontend
const client = new Livepeer({
  apiKey: process.env.NEXT_PUBLIC_LIVEPEER_CORS_KEY, // CORS-enabled key
});
```

The NEXT\_PUBLIC\_ prefix makes the variable available client-side in Next.js. Do not use this prefix for backend API keys.

Key Management

## Key rotation

Rotate API keys on a schedule and immediately if a key is exposed. Studio lets you create multiple active keys and delete compromised ones without downtime.

Recommended rotation schedule:

* Production backend keys: every 90 days
* After any team member offboarding
* Immediately after any suspected exposure

Keep API keys out of version control. If a key appears in a commit, treat it as compromised and rotate immediately -- git history is permanent and public repositories are indexed.

Common Errors

## Authentication errors

A `401 Unauthorized` response means the key is missing, malformed, or invalid:

```json theme={null}
{"error": "Unauthorized", "message": "Invalid API key"}
```

Check:

1. The `Authorization` header is present and formatted as `Bearer <key>` (not `Bearer: <key>`)
2. The key value has no leading or trailing whitespace
3. The key has not been deleted or expired in Studio
4. You are using a backend key for a server-side request, not a CORS key

## Related pages

> [card] [SDK Integration Guide](/v2/developers/build/sdk-gateway.md)
>
> Full SDK setup with authentication patterns for TypeScript, Python, and Go.

> [card] [Video Access Control](/v2/developers/guides/video/access-control.md)
>
> JWT and webhook-based access control for gating streams and assets.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.