API Key Management
February 24, 2026 ยท View on GitHub
This guide covers best practices for securely managing your Stratix API keys throughout the development lifecycle.
API Key Security Fundamentals
What Makes API Keys Sensitive
API keys are sensitive credentials that provide access to your Stratix organization and projects. They should be treated with the same level of security as passwords or other authentication tokens.
Risks of compromised API keys:
- Unauthorized access to your evaluations and data
- Unintended usage charges on your account
- Potential data breaches or intellectual property theft
- Abuse of your API quotas and rate limits
API Key Best Practices
- Never hardcode API keys in source code
- Use environment variables or secure credential stores
- Rotate keys regularly
- Use different keys for different environments
- Monitor key usage and access patterns
- Revoke unused or compromised keys immediately
Secure API Key Storage
Environment Variables (Recommended)
โ Good - Using environment variables:
import os
from layerlens import Stratix
# Secure: Load from environment variables
client = Stratix(
api_key=os.getenv('LAYERLENS_STRATIX_API_KEY'),
)
Setting Environment Variables Securely
Linux/macOS:
# Add to your shell profile (.bashrc, .zshrc, etc.)
export LAYERLENS_STRATIX_API_KEY="sk-your-key-here"
# Reload your shell configuration
source ~/.bashrc # or ~/.zshrc
Windows:
# Command Prompt (persistent)
setx LAYERLENS_STRATIX_API_KEY "sk-your-key-here"
# PowerShell (session-only)
$env:LAYERLENS_STRATIX_API_KEY="sk-your-key-here"
Using .env Files
Create a .env file (never commit this to version control):
# .env
LAYERLENS_STRATIX_API_KEY=sk-your-key-here
Load .env file in Python:
from dotenv import load_dotenv
import os
# Load environment variables from .env file
load_dotenv()
from layerlens import Stratix
# Now environment variables are available
client = Stratix()
Important: Add .env to your .gitignore file:
# .gitignore
.env
.env.local
.env.*.local
*.env