Keys
API key management with granular permissions. Manage authentication credentials with fine-grained access controls, allowing you to issue keys with specific scopes and resource restrictions.
Methods​
| Method (TypeScript) | Method (Python) | Description | HTTP |
|---|---|---|---|
create(options) | create(options) | Create new API key | POST /keys |
list(options?) | list(options=None) | List API keys | GET /keys |
revoke(keyId) | revoke(key_id) | Revoke API key | POST /keys/{id}/revoke |
Example​
- TypeScript
- Python
import { OptropicClient } from 'optropic';
const client = new OptropicClient({ apiKey: 'optr_live_...' });
// Create an API key with scoped permissions
const key = await client.keys.create({
name: 'CI/CD Pipeline',
scopes: ['assets:read', 'assets:create', 'documents:read'],
expiresIn: '90d'
});
console.log(`API Key: ${key.secret}`);
console.log(`Keep this safe - it cannot be retrieved again!`);
from optropic import Optropic
client = Optropic(api_key="optr_live_...")
# Create an API key with scoped permissions
key = client.keys.create({
'name': 'CI/CD Pipeline',
'scopes': ['assets:read', 'assets:create', 'documents:read'],
'expiresIn': '90d'
})
print(f"API Key: {key['secret']}")
print("Keep this safe - it cannot be retrieved again!")