Skip to content

API Keys

API keys give programmatic access to Ostrakon without having to manage user sessions.

  • Server applications (Node.js, Python, Go, etc.)
  • Automation scripts
  • CI/CD integrations
  • IoT and embedded systems
  1. Log in to your account
  2. Go to Settings > Developer > API keys
  3. Click New key
  4. Give it a descriptive name and select the permissions (scopes)
Terminal window
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!

Add the key to the X-API-Key header:

Terminal window
curl https://ostrakon.example.com/api/v1/triggers \
-H "X-API-Key: sk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
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>.

Terminal window
# Development
curl -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:*"]}'
# Production
curl -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:*"]}'

Grant only the scopes you need:

{
"name": "event-collector",
"scopes": ["trigger:hit:*"] // No need for read
}
Terminal window
# Environment variables
export OSTRAKON_API_KEY="sk_xxx"
# In your code
const apiKey = process.env.OSTRAKON_API_KEY;

Renew your keys periodically:

  1. Create a new key
  2. Update your applications
  3. Delete the old key
Terminal window
curl https://ostrakon.example.com/api/v1/keys \
-H "Authorization: Bearer VOTRE_ACCESS_TOKEN"
Terminal window
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.

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();
}
import os
import 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()