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.

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:

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:

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?