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

# Create an API Key

AI Guard uses OneTrust API keys for authentication and authorization. You need to create an API key with the **Data Discovery** scope to use with the SDK.

## Steps

### 1. Navigate to API Key Management

1. Log in to your OneTrust account
2. Navigate to **Settings** > **API Keys** (or access via the OneTrust Admin Console)

> 📘 Detailed Instructions
>
> For full step-by-step instructions on creating API keys, refer to the [OneTrust API Key Management documentation](https://my.onetrust.com/s/article/UUID-76f55697-ba16-d000-849a-d33e3d217f41).

### 2. Create a New API Key

1. Click **Create API Key**
2. Provide a descriptive name (e.g., "AI Guard SDK - Production")
3. Under **Scope**, select **Data Discovery**

> ⚠️ Important
>
> The API key **must** have the **Data Discovery** scope enabled. Without this scope, the SDK will receive `401 Unauthorized` errors when making classification requests.

### 3. Copy and Store the API Key

1. After creation, copy the generated API key immediately
2. Store the key securely — it will be used as the `token` parameter when initializing the `AIGuardClient`

> 🚧 Security Best Practice
>
> Never hard-code API keys in your source code. Use environment variables or a secrets manager to store and retrieve the key at runtime.

## Using the API Key

The API key is passed as the `token` parameter when initializing the AI Guard client:

```python
from ai_guard import AIGuardClient
from ai_guard.api import AIPlatform

client = AIGuardClient(
    "https://ai-guard.example.com:4443",
    token="your-api-key-here",  # Use an environment variable in production
    agent_id="my-agent",
    platform=AIPlatform.AMAZON_BEDROCK,
)
```

**Recommended pattern using environment variables:**

```python
import os
from ai_guard import AIGuardClient
from ai_guard.api import AIPlatform

client = AIGuardClient(
    os.environ["AI_GUARD_URL"],
    token=os.environ["AI_GUARD_TOKEN"],
    agent_id="my-agent",
    platform=AIPlatform.AMAZON_BEDROCK,
)
```

## What's Next?

* [Deploy the Light Worker Node](https://developer.onetrust.com/onetrust/docs/ai-guard-deploy-worker-node) — Set up the AI Guard classification service
* [Install the SDK](https://developer.onetrust.com/onetrust/docs/ai-guard-install-sdk) — Download and install the Python SDK