Skip to main content

API Authentication

SecureAI uses API key authentication for all external API access. Keys are Bearer tokens created and configured by administrators, with per-key controls over models, policies, limits, billing, and security.

Authentication Header

API Key Format:
  • Starts with an sk- prefix (e.g. sk-8cd5253f...).
  • The prefix is followed by a 64-character hexadecimal secret.
  • Only a SHA-256 hash of the key is stored server-side — the full key is shown once, at creation. If it’s lost, rotate/recreate the key.
All API calls require HTTPS.

Creating & configuring API keys

Administrators create keys in Admin → API Keys (API base /api/admin/api-keys, admin-only). The full key is returned once on creation. Each key carries the following configuration:

Ownership & billing

Callers can bill an individual request to a different user with the user_id body parameter (admin-gated).

Limits

Allowlists

Prompt Shield

See Prompt Shield API.

Redundancy defaults

failoverDefaults attaches a default model failover chain to the key: models[] (up to 3), timeout_ms (1000–300000), first_token_timeout_ms (500–60000), and on[] triggers. Callers then get failover without sending a chain on every request.

Idempotency

Completion POSTs accept an Idempotency-Key header. Retrying with the same key returns the original result instead of billing a second time — use it to make network retries safe. See Chat Completion.

Rate limiting

Default ceilings (configurable per key):
  • Per minute: 60 requests
  • Per hour: 1000 requests
  • Daily: 100 requests
  • Monthly: 10,000 requests
A key holder can read its own live quota and limits via GET /usage.

Security features

  • HTTPS only — all API calls require TLS.
  • Hashed at rest — only a SHA-256 hash of each key is stored.
  • Usage tracking & audit logging — every call and authentication event is logged.
  • SMLTP compliance — security policies are enforced on every request.

Error Responses

Authentication error

Rate limit error

Common Error Codes

Next Steps