API Key Management
Learn how to create, manage, and secure your Alprina API keys for CLI and programmatic access.
Overview
API keys allow you to authenticate with the Alprina API and CLI without using your password. Each key can be:
- Named for easy identification
- Individually revoked
- Tracked with last-used timestamps
- Scoped to specific permissions (coming soon)
Creating API Keys
From Dashboard
-
Login to Dashboard
- Visit alprina.com/dashboard
- Sign in with GitHub or email
-
Navigate to API Keys
- Click on your profile in the top right
- Select “API Keys” from the dropdown
- Or go directly to Settings → API Keys
-
Generate New Key
- Click “Generate New API Key”
- Enter a descriptive name (e.g., “Production Server”, “CI/CD Pipeline”)
- Click “Create”
-
Copy and Store Key
- ⚠️ Important: Copy the key immediately
- The full key is only shown once
- Store it securely (password manager, secrets vault)
Example:
Key Name: Production Server
API Key: sk_live_abc123def456ghi789jkl012mno345pqr678stu901vwx234yz
Created: January 5, 2025
Last Used: NeverFrom CLI
You can also generate keys using the CLI:
# Login first (uses GitHub OAuth)
alprina auth login
# Generate new API key
alprina auth api-key create --name "My CLI Key"
# Output:
# ✓ API key created successfully
# Name: My CLI Key
# Key: sk_live_...
# ⚠️ Save this key securely. It won't be shown again.Using API Keys
CLI Authentication
Method 1: Environment Variable (Recommended)
# Set environment variable
export ALPRINA_API_KEY="sk_live_your_key_here"
# Use CLI normally
alprina scan ./src
alprina chatAdd to your shell profile for persistence:
# ~/.bashrc or ~/.zshrc
export ALPRINA_API_KEY="sk_live_your_key_here"Method 2: CLI Login
# Login with API key
alprina auth login --api-key sk_live_your_key_here
# Key is stored in ~/.alprina/config.json
# Future commands use this key automatically
alprina scan ./srcMethod 3: Per-Command
# Use key for single command
alprina scan ./src --api-key sk_live_your_key_hereAPI Requests
Include your API key in the Authorization header:
curl -X POST https://api.alprina.com/v1/scan/code \
-H "Authorization: Bearer sk_live_your_key_here" \
-H "Content-Type: application/json" \
-d '{
"target": "./src",
"language": "python"
}'Python SDK
import alprina
# Set API key
client = alprina.Client(api_key="sk_live_your_key_here")
# Or use environment variable
import os
client = alprina.Client(api_key=os.getenv("ALPRINA_API_KEY"))
# Run scan
result = client.scan("./src", scan_type="code")JavaScript/Node.js
import Alprina from 'alprina-sdk';
// Initialize client
const alprina = new Alprina({
apiKey: process.env.ALPRINA_API_KEY
});
// Run scan
const result = await alprina.scan({
target: './src',
scanType: 'code'
});Managing API Keys
Viewing Keys
Dashboard:
- Navigate to Settings → API Keys
- View all keys with:
- Name
- Prefix (first 8 characters)
- Created date
- Last used timestamp
- Status (active/revoked)
CLI:
# List all API keys
alprina auth api-key list
# Output:
# ID Name Created Last Used
# key_abc123 Production Server Jan 1, 2025 2 hours ago
# key_def456 CI/CD Pipeline Jan 3, 2025 5 minutes ago
# key_ghi789 Development Jan 5, 2025 NeverRenaming Keys
# Rename via CLI
alprina auth api-key rename key_abc123 --name "New Production Key"
# Or via dashboard
# Settings → API Keys → Click key → Edit nameRevoking Keys
When to Revoke:
- Key accidentally exposed
- No longer needed
- Rotating keys for security
- Team member leaves
Dashboard:
- Go to Settings → API Keys
- Find the key to revoke
- Click “Revoke” button
- Confirm revocation
CLI:
# Revoke specific key
alprina auth api-key revoke key_abc123
# Confirm:
# ⚠️ Are you sure you want to revoke "Production Server"?
# This action cannot be undone. (y/N): y
# ✓ API key revoked successfullyAPI:
curl -X DELETE https://api.alprina.com/v1/auth/api-keys/key_abc123 \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"Rotating Keys
Best practice: Rotate keys every 90 days
# Step 1: Create new key
alprina auth api-key create --name "Production Server v2"
# Step 2: Update systems with new key
# (update environment variables, secrets managers, etc.)
# Step 3: Verify new key works
ALPRINA_API_KEY=new_key alprina scan ./test
# Step 4: Revoke old key
alprina auth api-key revoke key_old123Security Best Practices
DO ✅
-
Use Environment Variables
# Good export ALPRINA_API_KEY="sk_live_..." alprina scan ./src -
Store in Secrets Manager
- AWS Secrets Manager
- HashiCorp Vault
- GitHub Secrets
- Azure Key Vault
-
Use Descriptive Names
Good: "Production API Server", "GitHub Actions CI" Bad: "Key 1", "test", "my key" -
Rotate Regularly
- Every 90 days minimum
- After team member departure
- If exposure suspected
-
Use Separate Keys per Environment
production-key: For production systems staging-key: For staging environment ci-key: For CI/CD pipelines dev-key: For local development -
Monitor Usage
- Check “Last Used” timestamps
- Revoke unused keys
- Review API key list monthly
DON’T ❌
-
Hardcode in Source Code
# BAD - Never do this! api_key = "sk_live_abc123..." client = Alprina(api_key=api_key) -
Commit to Version Control
# Add to .gitignore echo ".env" >> .gitignore echo "*.key" >> .gitignore echo "alprina-config.json" >> .gitignore -
Share via Email/Slack
- Use secure sharing tools
- Or regenerate key for recipient
-
Use Same Key Everywhere
- Create separate keys per use case
- Easier to track and revoke
-
Ignore Security Warnings
# If you see this, take action! ⚠️ Warning: API key exposed in git history
CI/CD Integration
GitHub Actions
# .github/workflows/security-scan.yml
name: Security Scan
on: [push, pull_request]
jobs:
scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run Alprina Scan
run: alprina scan ./src --fail-on high
env:
ALPRINA_API_KEY: ${{ secrets.ALPRINA_API_KEY }}Setup:
- Generate API key: “GitHub Actions CI”
- Add to repository secrets: Settings → Secrets → New secret
- Name:
ALPRINA_API_KEY - Value: Your API key
GitLab CI
# .gitlab-ci.yml
security_scan:
script:
- pip install alprina-cli
- alprina scan ./src
variables:
ALPRINA_API_KEY: $ALPRINA_API_KEYSetup:
- Generate API key: “GitLab CI”
- Add to CI/CD variables: Settings → CI/CD → Variables
- Key:
ALPRINA_API_KEY - Value: Your API key
- Check “Mask variable” and “Protect variable”
Jenkins
pipeline {
agent any
environment {
ALPRINA_API_KEY = credentials('alprina-api-key')
}
stages {
stage('Security Scan') {
steps {
sh 'alprina scan ./src'
}
}
}
}Setup:
- Generate API key: “Jenkins Pipeline”
- Add credentials: Jenkins → Credentials → Add
- Kind: Secret text
- Secret: Your API key
- ID:
alprina-api-key
Troubleshooting
Invalid API Key
Error:
Error: Invalid API key
Status: 401 UnauthorizedSolutions:
- Verify key is correct (no extra spaces)
- Check key hasn’t been revoked
- Ensure using latest key if rotated
- Generate new key if lost
API Key Not Found
Error:
Error: ALPRINA_API_KEY environment variable not setSolutions:
# Check if set
echo $ALPRINA_API_KEY
# Set it
export ALPRINA_API_KEY="sk_live_..."
# Or login
alprina auth login --api-key sk_live_...Permission Denied
Error:
Error: 403 Forbidden
Insufficient permissions for this operationSolutions:
- Check your subscription tier
- Verify API key has required scopes
- Contact support if issue persists
Rate Limit Exceeded
Error:
Error: 429 Too Many Requests
Rate limit: 60 requests/minute exceededSolutions:
- Wait 1 minute before retrying
- Implement exponential backoff
- Upgrade tier for higher limits
- Use separate keys for different services
API Key Formats
Key Structure
sk_live_abc123def456ghi789jkl012mno345pqr678stu901vwx234yz
│ │ └────────────────────────────────────────────────────┘
│ │ │
│ │ Random string (48 chars)
│ │
│ └─ Environment (live/test)
│
└─ Prefix (secret key)- Prefix:
sk_(secret key) - Environment:
live_ortest_ - Random: 48 character random string
- Total length: 56 characters
Test vs Live Keys
Test Keys (sk_test_...):
- For development and testing
- Limited features
- Separate quota
- Free tier only
Live Keys (sk_live_...):
- For production use
- Full features
- Production quota
- All tiers
Scoped API Keys (Coming Soon)
Future enhancement: Create keys with limited scopes
# Read-only key (planned)
alprina auth api-key create \
--name "Monitoring Service" \
--scopes "scans:read"
# Scan-only key (planned)
alprina auth api-key create \
--name "CI/CD Scanner" \
--scopes "scans:write,scans:read"FAQ
Q: How many API keys can I create? A: No limit. Create as many as needed for different services.
Q: Do API keys expire? A: No, but we recommend rotating every 90 days.
Q: Can I recover a revoked key? A: No, revocation is permanent. Generate a new key.
Q: What if I lose my API key? A: Revoke the lost key and generate a new one.
Q: Can I see my full API key after creation? A: No, it’s only shown once for security. Save it immediately.
Q: How do I know which key to revoke? A: Use descriptive names and check “Last Used” timestamps.