Skip to main content

Overview

This guide covers two types of API keys in Dakora:
  1. LLM Provider Keys - For executing templates with external AI models (OpenAI, Anthropic, etc.)
  2. Dakora API Keys - For authenticating programmatic access to Dakora APIs (see Authentication Guide)

Dakora API Keys

For authentication and API access, see the Authentication Guide.

Management API (Project‑Scoped)

Use these endpoints to manage project API keys. Creating and revoking keys typically requires a JWT (user context) or an admin API key.
# Create a key
PROJECT_ID="<project-uuid>"
ACCESS_TOKEN="<clerk-jwt>"
curl -s -X POST "http://localhost:8000/api/projects/$PROJECT_ID/api-keys" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name": "CI Key", "expires_in_days": 90}'

# List keys (JWT or API key)
curl -s "http://localhost:8000/api/projects/$PROJECT_ID/api-keys" \
  -H "Authorization: Bearer $ACCESS_TOKEN"

# Get a key by ID
curl -s "http://localhost:8000/api/projects/$PROJECT_ID/api-keys/$KEY_ID" \
  -H "Authorization: Bearer $ACCESS_TOKEN"

# Revoke a key
curl -s -X DELETE "http://localhost:8000/api/projects/$PROJECT_ID/api-keys/$KEY_ID" \
  -H "Authorization: Bearer $ACCESS_TOKEN"
Response fields include id, name, key (only on creation), key_prefix, created_at, expires_at, and masked key_preview values for reads. Dakora API keys allow you to:
  • Authenticate API requests without browser login
  • Access Dakora APIs from external services
  • Implement service-to-service communication
  • Control access at the project level

LLM Provider API Keys

Dakora uses LiteLLM to execute templates against 100+ LLM providers. Each provider requires an API key.

Getting API Keys

1

Choose Your Provider

Select from popular providers:
2

Create API Key

Follow your provider’s documentation to create an API key. Keep it secure!
3

Set Environment Variable

Configure the key as an environment variable (see methods below)

Configuration Methods

  • macOS/Linux
  • Windows
Add to your ~/.bashrc, ~/.zshrc, or ~/.bash_profile:
export OPENAI_API_KEY="sk-..."
export ANTHROPIC_API_KEY="sk-ant-..."
export GOOGLE_API_KEY="AIza..."
Then reload:
source ~/.zshrc  # or ~/.bashrc

Method 2: .env File (Development)

Create .env in your project root:
OPENAI_API_KEY="sk-..."
ANTHROPIC_API_KEY="sk-ant-..."
GOOGLE_API_KEY="AIza..."
Load in your Python code:
from dotenv import load_dotenv
import os

# Load environment variables from .env file
load_dotenv()

# Use Dakora normally
from dakora import Vault
vault = Vault("dakora.yaml")
Never commit .env to version control!Add to your .gitignore:
echo ".env" >> .gitignore
For testing only:
import os

os.environ["OPENAI_API_KEY"] = "sk-..."

from dakora import Vault
vault = Vault("dakora.yaml")
Don’t hardcode API keys in your source code. Use environment variables or .env files instead.

Verify Configuration

Check which API keys are configured:
# Check all providers
dakora config

# Check specific provider
dakora config --provider openai
Output:
✓ OPENAI_API_KEY found
✗ ANTHROPIC_API_KEY not set
✗ GOOGLE_API_KEY not set

Provider-Specific Keys

OpenAI

OPENAI_API_KEY="sk-..."
Models: gpt-4, gpt-4-turbo, gpt-3.5-turbo

Anthropic

ANTHROPIC_API_KEY="sk-ant-..."
Models: claude-3-opus, claude-3-sonnet, claude-3-haiku

Google

GOOGLE_API_KEY="AIza..."
Models: gemini-pro, gemini-1.5-pro

Azure OpenAI

AZURE_API_KEY="..."
AZURE_API_BASE="https://your-resource.openai.azure.com"
AZURE_API_VERSION="2023-05-15"
Models: azure/gpt-4, azure/gpt-35-turbo

Local Models (Ollama)

No API key required:
result = template.execute(
    model="ollama/llama3",
    input_text="..."
)

Security Best Practices

Store API keys in environment variables, not in code
Never commit .env files to version control
Rotate API keys periodically for security
Use different API keys for development and production environments
Track API usage to detect unauthorized access

Troubleshooting

Error: AuthenticationError: Invalid API keySolution:
  1. Verify your API key is correct
  2. Check the environment variable name matches the provider
  3. Ensure the key hasn’t expired
Error: API key not found for providerSolution:
  1. Run dakora config --provider openai to verify
  2. Check environment variable is set: echo $OPENAI_API_KEY
  3. Restart your terminal/IDE after setting variables
Error: Keys in .env file not being readSolution:
  1. Install python-dotenv: pip install python-dotenv
  2. Add load_dotenv() before importing Dakora
  3. Ensure .env is in the current working directory

Next Steps