Skip to main content

API Keys

API keys are required to access Enclava's public API endpoints.

Creating an API Key

Via Web Interface

  1. Navigate to API Keys in the sidebar

  2. Click Create API Key

  3. Fill in the configuration form:

    Basic Settings:

    • Name: Descriptive name (e.g., "Production App", "Dev Bot")
    • Description: Optional additional information
    • Prefix: Auto-generated prefix (default: en_)

    Model Access:

    • Allowed Models: Leave empty for all models, or specify (e.g., gpt-4,gpt-3.5-turbo)
    • Purpose: Restrict key to specific use cases

    Budget Limits:

    • Daily Spend Limit: Maximum spend per day (e.g., 10.00)
    • Monthly Spend Limit: Maximum spend per month (e.g., 300.00)
    • Daily Token Limit: Maximum tokens per day (e.g., 100000)
    • Alert Threshold: Percentage at which to send alerts (e.g., 0.8 for 80%)
  4. Click Create to generate the key

Via API

import requests

response = requests.post(
"http://localhost/api-internal/v1/api-keys",
headers={
"Authorization": "Bearer YOUR_JWT_TOKEN"
},
json={
"name": "Production App",
"description": "API key for production application",
"allowed_models": ["gpt-4", "gpt-3.5-turbo"],
"daily_spend_limit": 50.00,
"monthly_spend_limit": 1500.00,
"daily_token_limit": 500000
}
)

api_key = response.json()["api_key"]
print(f"Your API key: {api_key}")

⚠️ Important: Copy the API key immediately - you won't see it again!

API Key Format

Enclava API keys follow this format:

en_<random-string>

Example: en_8f3d4e2a9b1c6d5f7e8a3b4c9d2f1e6a

The prefix en_ identifies Enclava keys and helps with organization.

Naming Best Practices

Use descriptive names to identify keys easily:

PurposeExample Name
Development environmentdev-app-v1
Production web appprod-web-app
Chatbot widgetchatbot-widget-frontend
Internal toolinternal-data-processor
Testingtest-script-automation

Setting Model Access

All Models (Default)

Leave "Allowed Models" empty:

{
"name": "Full Access Key",
"allowed_models": []
}

This key can access all models available on your platform.

Specific Models

Specify models explicitly:

{
"name": "GPT-4 Only Key",
"allowed_models": ["gpt-4"]
}

This key can only use gpt-4, useful for cost control.

Multiple Models

Specify comma-separated list:

{
"name": "Production Models",
"allowed_models": ["gpt-4", "gpt-3.5-turbo"]
}

Setting Budget Limits

Daily Spend Limit

Prevents unexpected costs on a daily basis:

{
"daily_spend_limit": 25.00
}

After $25 of usage in a day, requests using this key will be rejected.

Monthly Spend Limit

Controls overall monthly spending:

{
"monthly_spend_limit": 750.00
}

Good for predictable monthly budgets.

Token Limits

Control usage by token count:

{
"daily_token_limit": 250000
}

Useful when costs vary by model (e.g., cheaper models can use more tokens).

Alert Threshold

Get notified before limits are reached:

{
"daily_spend_limit": 100.00,
"alert_threshold": 0.8
}

You'll be notified when you reach 80% of your daily limit.

Testing Your New Key

Verify Key Works

import requests

response = requests.get(
"http://localhost/api/v1/models",
headers={"Authorization": "Bearer en_xxxxxxxxxxxxxxx"}
)

if response.status_code == 200:
print("✓ API key is working")
models = response.json()["data"]
print(f"Available models: {[m['id'] for m in models]}")
else:
print(f"✗ Error: {response.status_code}")
print(response.json())

Test Model Access

response = requests.post(
"http://localhost/api/v1/chat/completions",
headers={"Authorization": "Bearer en_xxxxxxxxxxxxxxx"},
json={
"model": "gpt-4",
"messages": [{"role": "user", "content": "Test"}]
}
)

print(response.json()["choices"][0]["message"]["content"])

Common Creation Issues

Key Not Generated

Problem: No API key shown after creation

Solution:

  • Refresh the page and check API Keys list
  • Keys are only shown once during creation
  • If missed, delete and create a new key

Budget Too Low

Problem: Requests fail immediately

Solution:

  • Verify budget limits are reasonable
  • Start with higher limits for testing
  • Monitor usage to set appropriate limits

Model Access Error

Problem: "Model not allowed" error

Solution:

  • Check allowed_models list
  • Verify model name matches exactly (case-sensitive)
  • Try without model restrictions to test

Next Steps

After creating your API key: