API Keys
API keys are the primary authentication method for dialektai's API. They provide secure, token-based access to your databases and organization resources.
Creating API Keys
All API keys are created through the dialektai portal. Navigate to your organization settings or database settings to create new API keys.
Types of API Keys
Organization-Level Keys
Organization-level API keys grant access to all databases within your organization. These are secret keys (prefixed with sk_) intended for server-side use only.
Use Cases:
- Backend services that need access to multiple databases
- Administrative tools and scripts
- Multi-database analytics platforms
To create an organization-level key:
- Log in to the dialektai portal
- Click API Keys in the sidebar
- Click Create API Key
- Provide a name
- Copy the generated key immediately (secret keys are only shown once)
Database-Level Keys
Database-level API keys are scoped to a single database connection. These are public keys (prefixed with pk_) designed for client-side embedding. Security is enforced through CORS allowed origins, not by keeping the key secret.
Use Cases:
- Widget integrations (recommended)
- Customer-facing applications
- Client-side JavaScript applications
- Embedded chat widgets
To create a database-level key:
- Log in to the dialektai portal
- Navigate to Databases → Select your database
- Scroll to the Widget Integration section
- In the API Keys panel, click Create New API Key
- Provide a name
- The key will be displayed and can be copied anytime (public keys remain visible)
Using API Keys
Authentication Methods
dialektai supports two distinct authentication methods:
JWT Tokens (Web Portal):
- Format:
Authorization: Bearer <JWT_TOKEN> - Use case: Authenticated user sessions from the web portal
- Used for: Creating API keys, managing organization settings
- Format:
API Keys (Programmatic Access):
- Format:
X-API-Key: <API_KEY> - Use case: Widget integrations, backend services, automated scripts
- Used for: Querying databases, sending chat messages
- Format:
HTTP Header Format
Include your API key in the X-API-Key header:
X-API-Key: YOUR_API_KEY
Example Requests
cURL:
curl -X POST https://api.dialektai.com/api/v1/chat/message \
-H "X-API-Key: sk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"message": "Show me sales data",
"conversation_id": "conv-abc"
}'
Python:
import requests
headers = {
'X-API-Key': api_key,
'Content-Type': 'application/json'
}
response = requests.post(
'https://api.dialektai.com/api/v1/chat/message',
headers=headers,
json={
'message': 'Show me sales data',
'conversation_id': 'conv-abc'
}
)
JavaScript/TypeScript:
const apiKey = process.env.DIALEKTAI_API_KEY;
const response = await fetch('https://api.dialektai.com/api/v1/chat/message', {
method: 'POST',
headers: {
'X-API-Key': apiKey,
'Content-Type': 'application/json'
},
body: JSON.stringify({
message: 'Show me sales data',
conversation_id: 'conv-abc'
})
});
Key Management
Viewing Your Keys
- Log in to the dialektai portal
- Navigate to:
- API Keys in the sidebar (for organization-level secret keys)
- Databases → Select database → Widget Integration section (for database-level public keys)
- View key metadata: name, scope, creation date, last used, usage count
Key Visibility:
- Secret keys (sk_*): Only the prefix is shown (e.g.,
sk_abc123...). The full key was shown once at creation. - Public keys (pk_*): Full key is always visible and can be copied anytime.
Revoking Keys
- Navigate to the API Keys section in the portal (as above)
- Click the delete/revoke button next to the key you want to revoke
- Confirm the revocation
Best Practices
1. Use Environment Variables
Never hardcode API keys in your source code. Use environment variables:
# .env file
DIALEKTAI_API_KEY=sk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
import os
api_key = os.getenv('DIALEKTAI_API_KEY')
2. Rotate Keys Regularly
Rotate your API keys every 90 days to minimize security risks:
- Create a new API key
- Update your applications with the new key
- Verify the new key works
- Revoke the old key
3. Use Least Privilege
- Use database-level keys for widget integrations (not organization keys)
- Create separate keys for different environments (dev, staging, production)
- Revoke unused keys immediately
4. Monitor Usage
Track API key usage in the dialektai dashboard:
- Last used timestamp
- Request counts
- Error rates
- Unusual activity
5. Secure Storage
- Store keys in secrets managers (AWS Secrets Manager, HashiCorp Vault, etc.)
- Never commit keys to version control
- Use
.gitignoreto exclude.envfiles - Rotate keys if they're accidentally exposed
Key Prefixes
dialektai uses prefixes to identify key types and their intended use:
| Prefix | Type | Scope | Intended Use | Security Model |
|---|---|---|---|---|
sk_ |
Secret Key | Organization | Server-side only | Keep secret, never expose client-side |
pk_ |
Public Key | Database | Client-side safe | Public, protected by CORS |
Key Format:
- Secret keys:
sk_+ 64 random characters (~67 chars total) - Public keys:
pk_+ 64 random characters (~67 chars total)
Security Guidelines:
- Secret keys (sk_): Store in environment variables, secrets managers, never commit to version control
- Public keys (pk_): Safe to embed in client-side code, security enforced via CORS allowed origins
Rate Limiting
API keys are subject to rate limits based on your plan:
| Plan | Requests/Minute | Requests/Day |
|---|---|---|
| Free | 10 | 1,000 |
| Starter | 60 | 10,000 |
| Pro | 600 | 100,000 |
| Enterprise | Custom | Custom |
Rate limit headers are included in every response:
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 45
X-RateLimit-Reset: 1697654400
Error Responses
401 Unauthorized
{
"error": "unauthorized",
"message": "Invalid or missing API key",
"code": "INVALID_API_KEY"
}
Causes:
- Missing
X-API-Keyheader - Invalid API key format
- Revoked or expired key
403 Forbidden
{
"error": "forbidden",
"message": "API key does not have access to this resource",
"code": "INSUFFICIENT_PERMISSIONS"
}
Causes:
- Database-level key trying to access a different database
- Attempting to access organization resources with a database-level key
429 Too Many Requests
{
"error": "rate_limit_exceeded",
"message": "Rate limit exceeded. Try again in 60 seconds.",
"code": "RATE_LIMIT_EXCEEDED",
"retry_after": 60
}
Solution: Implement exponential backoff and respect the Retry-After header.
Next Steps
- Widget Integration - Using API keys in the widget
- Tenant Filtering - Multi-tenant security model