Documentation menu

Authentication

The two kinds of key, what each can do, and how to create, rotate and revoke them.

Both APIs authenticate your server with a key sent as a bearer token:

Authorization: Bearer hx_sk_…

The gateway also accepts its key as x-api-key, where the Anthropic SDK sends it. The management API accepts only Authorization: Bearer.

Two kinds of key#

KeyPrefixBelongs toUsed for
Environment keyhx_sk_, hx_sk_test_One environmentThe gateway (inference scope), and the management API of its own environment (management scope)
Project keyhx_proj_One projectThe management API of the project and of every environment in it. Never the gateway

Each prefix is followed by 43 letters and digits. Hixel stores only a hash of a key and its last four characters, so the full key is shown once, when you create it, and never again.

Which key do I need#

To…Use
Send inference requests through the gatewayAn environment key with the inference scope
Manage one environment's customers, wallets, credits, usage, webhooks, payments, keysAn environment key with the management scope, or a project key
Change an environment's gateway settings (PATCH /v1/gateway)A project key with the admin role
Create, rename or archive environments; manage project keys; read the audit logA project key
Read what the project's usage cost (/v1/billing)A project key with the admin role
Change the organization, its members and invitations, create or archive a projectNeither: these are done by a person in the dashboard

Environment keys#

An environment key belongs to one environment of one project, and acts only there.

PrefixEnvironment
hx_sk_Production: calls real providers
hx_sk_test_A test environment, such as Staging: answered by the mock

Scopes#

ScopeAllows
inferenceThe gateway: chat, the endpoints beside chat, GET /v1/models, minting client tokens
managementThe management API of the key's own environment

A new key has inference only unless you choose otherwise. Give a key both scopes only if the same service needs both; a key that only sends requests should not be able to change customers or credit wallets.

A management key can do everything in its environment that the dashboard can, except change the environment's gateway settings: that takes a project key with the admin role (project_key_required otherwise). It reads the settings like everything else.

Restricting a key#

When you create a key you can narrow it further:

  • customer: pin it to one customer. Its requests act for that customer only (see Sending requests). A pinned key cannot have the management scope.
  • member: pin it to one member as well.
  • allowed_models: the models it may call, within the environment's allowlist.
  • expires_at: when it stops working.
  • tags: labels recorded on every request it makes (key_tags in usage).

Managing environment keys#

Create them in the dashboard under Developers → API keys, or with a management key (or a project key, for any environment of its project):

curl https://api.hixel.dev/v1/keys \
  -H "Authorization: Bearer $HIXEL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Support bot",
    "scopes": ["inference"],
    "allowed_models": ["claude-haiku-5-5"],
    "tags": ["support-bot"]
  }'
{
  "key": {
    "id": "key_…",
    "name": "Support bot",
    "last_four": "a9Zq",
    "status": "active",
    "scopes": ["inference"],
    "customer": null,
    "member": null,
    "allowed_models": ["claude-haiku-5-5"],
    "tags": ["support-bot"],
    "expires_at": null,
    "revoked_at": null,
    "created_by_user_id": null,
    …
  },
  "secret": "hx_sk_test_…"
}

A key created through the API can never reach further than the key that created it: no scope, model or later expiry it lacks itself (403 key_reach_exceeded).

CallWhat it does
GET /v1/keysThe environment's keys, a page, newest first, revoked and expired ones included. Never a secret
GET /v1/keys/{id}One key
PATCH /v1/keys/{id}Change name, scopes, allowed_models, tags or expires_at (null clears a limit)
POST /v1/keys/{id}/revokeRevoke it
POST /v1/keys/{id}/rotateReplace it with a new key and secret; grace_period_seconds keeps the old one working (default none, at most 30 days)

status is active, expired or revoked. Each change sends a key.created, key.revoked or key.rotated webhook.

Project keys#

A project key (hx_proj_…) manages one project from code: the project itself, its environments, its project keys, its audit log and billing, and everything inside each environment. It has a role:

RoleCan
adminManage the project, its environments and everything in them, including gateway settings and keys
memberRead them, except the audit log and the project's billing

A project key never reaches the organization (its settings, members, invitations, other projects) and never works on the gateway. It may expire and can be revoked; its secret is shown once.

Precisely: a member key may call every read (every GET) of the project and its environments, except GET /v1/audit_log and the project billing reads (/v1/billing/…), which need admin. Every write (POST, PUT, PATCH, DELETE) needs admin. Each operation in the API reference states the role it needs.

The first project key is created by a person who may change the project.

In the dashboard, open Settings (at the foot of the main sidebar) › Project › Project keys, and create a key with a name, a role (Admin or Member) and, optionally, an expiry. Its secret is shown once. The same page lists the project's keys and edits, rotates and revokes them.

After that, an admin project key manages keys with the API too: POST /v1/project/keys creates one, PATCH /v1/project/keys/{id} renames it or changes its expiry, POST …/rotate replaces its secret (the old one can keep working for grace_period_seconds), and POST …/revoke revokes it. A key never creates one with more reach than its own: not the admin role from a member key, and not a later expiry, or none, where it has one.

Naming the environment#

A project key calls the project's own endpoints (/v1/project, /v1/project/keys, /v1/environments, /v1/audit_log, /v1/billing/…) directly. For any environment endpoint (customers, wallets, usage, keys, gateway settings…), it names the environment in a header:

curl https://api.hixel.dev/v1/customers \
  -H "Authorization: Bearer $HIXEL_PROJECT_KEY" \
  -H "x-hixel-environment: env_k3j9x2m8q1w7e4r5t6y0u2i3"
  • Without the header, an environment endpoint is 400 environment_required.
  • An environment that is unknown, archived, or of another project reads as 404 environment_not_found.
  • Called for one environment, the key reaches nothing in another: a key id of another environment is simply not found.

An environment key may send the header too, naming its own environment only.

Dashboard only#

These are done by a person signed in to the dashboard, never by a key: the organization's settings, its members and invitations, creating a project and archiving one, and creating a project's first project key (Settings › Project › Project keys). The API has no operations for them.

How fast a change takes effect#

The gateway caches keys at the edge so that requests never wait on a database. A revoked key, or a changed allowlist, can keep working for about 90 seconds while the change spreads (longer only during an outage of the edge's storage, up to five minutes). To replace a leaked key, revoke it at once and accept that short window; to replace a key without downtime, rotate it with a grace period and deploy the new secret within it.

Failures#

StatuscodeWhen
401api_key_requiredManagement API: no bearer token
401missing_api_keyGateway: no key or client token
401invalid_api_keyUnknown, revoked, or of an archived project or environment
401expired_api_keyThe key is past its expires_at
400environment_requiredA project key on an environment endpoint without x-hixel-environment
404environment_not_foundx-hixel-environment names no live environment of the key's project
403management_scope_requiredManagement API with a key without management, or one pinned to a customer
403project_key_requiredAn environment key on the project's own endpoints, or on PATCH /v1/gateway
403role_not_allowedA member project key on a call that changes something, or needs admin
403key_reach_exceededCreating a key with more reach than the key creating it
403key_scope_insufficientGateway with a key without inference

Keep keys in your secret manager, never in source control, logs or client-side code. For browsers and apps, mint client tokens.