API Keys
API keys give programmatic access to Ostrakon without having to manage user sessions.
When to use an API Key
Section titled “When to use an API Key”- Server applications (Node.js, Python, Go, etc.)
- Automation scripts
- CI/CD integrations
- IoT and embedded systems
Create an API key
Section titled “Create an API key”From the web interface
Section titled “From the web interface”- Log in to your account
- Go to Settings > Developer > API keys
- Click New key
- Give it a descriptive name and select the permissions (scopes)
From the API
Section titled “From the API”curl -X POST https://ostrakon.example.com/api/v1/keys \ -H "Authorization: Bearer VOTRE_ACCESS_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "name": "production-server", "scopes": ["trigger:read:*", "trigger:hit:*"] }'Response:
{ "id": "sk_abc123XY", "name": "production-server", "key": "sk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "scopes": ["trigger:read:*", "trigger:hit:*"], "created_at": "2024-01-15T10:30:00Z"}Important: The full key (
sk_...) is shown only once. Save it!
Use an API Key
Section titled “Use an API Key”Add the key to the X-API-Key header:
curl https://ostrakon.example.com/api/v1/triggers \ -H "X-API-Key: sk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"Available scopes
Section titled “Available scopes”| Scope | Description |
|---|---|
trigger:hit:* |
Send events to all triggers (trigger:hit:<id> for a single one) |
trigger:read:* |
List and read triggers |
trigger:stats:* |
Read events, statistics, metadata and SSE streams (includes read) |
trigger:create:* |
Create triggers (and nothing else, wildcard target only) |
trigger:manage:* |
Create, edit, delete and share triggers (includes all trigger:* rights, hit included) |
group:read:* |
Read groups and their triggers |
group:stats:* |
Read group statistics (includes read) |
group:manage:* |
Create, edit and delete groups |
tenant:read:* |
Read organizations |
To send events, you need trigger:hit (or trigger:manage) on the target trigger: trigger:read and trigger:stats are not enough (403 error, whose message names the missing scope). Conversely, trigger:hit alone allows neither reading nor creating. trigger:create alone only allows POST /triggers: no listing, editing, deleting or sending events. trigger:manage includes it.
trigger:write and trigger:delete exist but open neither PATCH nor DELETE: those routes require trigger:manage. The key:manage scope opens nothing either: creating, listing and revoking keys requires a JWT (a key cannot manage keys). The same goes for trigger transfer, sessions and OSP rotation.
Key for a plugin or a script that creates its triggers
Section titled “Key for a plugin or a script that creates its triggers”A plugin or a script that creates its own triggers, then sends events to them, does not need trigger:manage:* (which also allows deleting, sharing and transferring every trigger of the account). Give it these three scopes:
{ "name": "my-plugin", "scopes": ["trigger:create:*", "trigger:hit:*", "trigger:read:*"]}trigger:create:*: create triggers (POST /triggers). Only the*target is accepted.trigger:hit:*: send events to the triggers. It also covers the triggers shared with the account with the hit right.trigger:read:*: list and read triggers, to find the ones that already exist.
This key cannot edit, delete, share or transfer a trigger, nor read events or statistics (trigger:stats:*). Creating a trigger still counts against the plan limit, and a tenant-owned trigger also needs tenant:write:<id>.
Best practices
Section titled “Best practices”1. Use separate keys per environment
Section titled “1. Use separate keys per environment”# Developmentcurl -X POST https://ostrakon.example.com/api/v1/keys \ -H "Authorization: Bearer VOTRE_ACCESS_TOKEN" \ -H "Content-Type: application/json" \ -d '{"name": "dev-server", "scopes": ["trigger:hit:*"]}'
# Productioncurl -X POST https://ostrakon.example.com/api/v1/keys \ -H "Authorization: Bearer VOTRE_ACCESS_TOKEN" \ -H "Content-Type: application/json" \ -d '{"name": "prod-server", "scopes": ["trigger:hit:*"]}'2. Apply the principle of least privilege
Section titled “2. Apply the principle of least privilege”Grant only the scopes you need:
{ "name": "event-collector", "scopes": ["trigger:hit:*"] // No need for read}3. Store keys securely
Section titled “3. Store keys securely”# Environment variablesexport OSTRAKON_API_KEY="sk_xxx"
# In your codeconst apiKey = process.env.OSTRAKON_API_KEY;4. Rotate regularly
Section titled “4. Rotate regularly”Renew your keys periodically:
- Create a new key
- Update your applications
- Delete the old key
List your keys
Section titled “List your keys”curl https://ostrakon.example.com/api/v1/keys \ -H "Authorization: Bearer VOTRE_ACCESS_TOKEN"Revoke a key
Section titled “Revoke a key”curl -X DELETE https://ostrakon.example.com/api/v1/keys/{keyId} \ -H "Authorization: Bearer VOTRE_ACCESS_TOKEN"{keyId} is the key's id (sk_ followed by 8 characters, visible in the list), not the full key. 204 response.
Integration examples
Section titled “Integration examples”Node.js
Section titled “Node.js”const OSTRAKON_API_KEY = process.env.OSTRAKON_API_KEY;
async function trackEvent(triggerId, metadata) { const response = await fetch( `https://ostrakon.example.com/api/v1/triggers/${triggerId}/events`, { method: 'POST', headers: { 'X-API-Key': OSTRAKON_API_KEY, 'Content-Type': 'application/json', }, body: JSON.stringify({ metadata }), } ); return response.json();}Python
Section titled “Python”import osimport requests
API_KEY = os.environ['OSTRAKON_API_KEY']
def track_event(trigger_id, metadata): response = requests.post( f'https://ostrakon.example.com/api/v1/triggers/{trigger_id}/events', headers={'X-API-Key': API_KEY}, json={'metadata': metadata} ) return response.json()