Skip to content
Sign in Create account

Authentication

Every gateway call carries an API key in the Authorization: Bearer cloak_… header. Create a key in the portal, or with one curl call as shown below. For organization settings and account routes, see Test accounts.

Get an API key without a browser

One unauthenticated POST returns a free-tier key that works immediately with the SDKs, the gateway API and the MCP server. It suits CI, containers and scripts.

# Without an email address:
curl -sS -X POST https://api.cloakapi.io/api/v1/self-service/key \
-H 'Content-Type: application/json' -d '{}'
# With an email address, so you can verify it later and manage the key in the portal.
# Eligible accounts may receive $2 of trial credit after email verification. The credit works on any priced model until it is used up.
curl -sS -X POST https://api.cloakapi.io/api/v1/self-service/key \
-H 'Content-Type: application/json' \
-d '{"email":"you@example.com","name":"my-ci-key"}'

Response (201). The strings are the gateway’s own text, shown as it returns them:

{
"api_key": "cloak_live_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"key_prefix": "cloak_live_XXXXXX",
"tier": "free",
"limits": {
"rate_limit_rpm": 20,
"on_device": "On-device tokenise / detokenise / detect / device-receipts (SDK + MCP) work immediately with this key — they never leave the machine.",
"relay": "Content-blind LLM relay (POST /api/v1/chat/completions, /api/v1/messages) requires a positive wallet balance. Verify your email to see whether you qualify for a $2 trial credit; the credit works on any priced model until it is used up. You can also add funds at https://app.cloakapi.io. Free-tier keys with a $0 balance return HTTP 402 on relay."
},
"account": {
"anonymous": false,
"email": "you@example.com",
"claim": "A verification email was sent. Verify it to see whether you qualify for a $2 trial credit, and manage keys at https://app.cloakapi.io."
},
"usage": {
"sdk": "export CLOAKAPI_API_KEY=<your api_key>",
"mcp": "Set CLOAKAPI_API_KEY in the MCP server env; key-gated tools (get_balance, private_completion) then authenticate.",
"api": "Authorization: Bearer $CLOAKAPI_API_KEY"
},
"docs": "https://docs.cloakapi.io/gateway/auth/",
"warning": "This key is shown ONCE and is not recoverable. Store it securely."
}

Use it straight away:

export CLOAKAPI_API_KEY=cloak_live_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
# Most SDKs + MCP read this; TypeScript takes apiKey in CloakAPI options.
# API: Authorization: Bearer $CLOAKAPI_API_KEY

What a free-tier key can do

  • On-device work is free and unlimited. detect_pii, tokenize, detokenize and device receipts in the SDK, and the MCP tokenise tools, run on your machine; the key only authenticates and attributes usage.
  • Requests are limited to 20 per minute per key.
  • The model relay needs credit. The prepaid balance belongs to your account. For prepaid calls, the relay (POST /api/v1/chat/completions, /api/v1/messages) returns 402 insufficient_balance when the account has no usable credit. Eligible accounts may receive $2 of trial credit after email verification. The credit works on any priced model until it is used up. You can also top up at app.cloakapi.io/billing.

Limits on key issuance

The endpoint accepts at most 5 requests per hour and 20 per day from one network (an IP address, or an IPv6 /64). It refuses to create a key for an email address that already has an account (409 account_exists; sign in to the portal instead). It does not grant a paid tier or change another account.

Key format, rotation and revocation

  • Format: cloak_live_<base64url>, generated from 32 random bytes (256 bits of entropy). Treat the whole value as a secret.
  • Header: Authorization: Bearer cloak_…
  • Ownership: keys belong to an organization. Sub-organizations (partner mode) get their own keys, with their own quotas, rate limits and balances.
  • Rotation: rotate a key at any time under API keys in the portal, with Rotate. The previous key is deactivated immediately, so deploy the new key right away. See Key rotation policy.
  • Revocation takes effect immediately. A revoked key gets 401 with a structured error.code: "key_revoked" payload.

Per-request scoping

Inside the gateway, each request is scoped by:

  • Tenant, derived from the API key.
  • Sub-organization, for partner and white-label flows.
  • Capability: a fine-grained model allowlist (gpt-5.4-mini, claude-haiku-5-5, …), enforced before provider routing.
  • Quota: hourly and daily token budgets for configured segments. The default configuration enables none.
  • Rate limit: fixed 60-second buckets per API key, organization and source IP. See Quotas and rate limits for the defaults and response headers.

An API key’s IP allowlist is enforced on every endpoint that accepts an API key.

Per-key scope allowlist (permissions)

Each cloak_* API key carries a permissions array. The enforced vocabulary is published at GET /api/v1/keys/scopes and contains:

ScopeWhat it grants
messagesPOST /api/v1/messages (Anthropic-format chat)
completionsPOST /api/v1/chat/completions (OpenAI-format chat)
bufferRead buffered responses with an explicit API-key permission or Sanctum PAT ability

How the gateway applies it:

  • On API-key routes that use legacy permission handling, an empty or null permissions array allows the request, for backward compatibility. Buffered response reads are the exception: they need an explicit buffer permission.

  • When permissions is not empty and does not contain the scope a route requires, the gateway returns HTTP 403 with this envelope:

    {
    "error": {
    "type": "permission_error",
    "code": "insufficient_scope",
    "message": "This API key is not authorised for the 'completions' capability.",
    "required": ["completions"],
    "granted": ["messages"]
    }
    }

Portal personal access tokens

Portal personal access tokens (Sanctum PATs) are a separate system. The dashboard uses them, as do /api/v1/keys, /api/v1/billing/*, /api/v1/webhooks* and the admin-session/* console. Their vocabulary is published in the UI and includes abilities:write, ability:keys.read, ability:keys.write, ability:billing.read, ability:billing.write, ability:byok.write and ability:admin. A cloak_* gateway key is not valid for those portal routes, and a Sanctum PAT is not valid for /api/v1/messages or /api/v1/chat/completions.

OIDC provider endpoints

The gateway is an OIDC provider for CloakAPI accounts, with a standard discovery surface:

EndpointPath
Discovery/.well-known/openid-configuration
JWKS/oauth/jwks
Userinfo/oauth/userinfo
Token/oauth/token (standard OAuth2)
Authorize/oauth/authorize

Laravel Passport backs these endpoints today. An Authentik identity provider is live at auth.cloakapi.io; portal password login stays Laravel-native.

Single sign-on from your own identity provider

SAML 2.0 and OIDC single sign-on into an organization, and SCIM 2.0 provisioning, are available through the SSO configuration API for verified owners and admins (see GET and PUT /api/sso/config). The portal has no form for setting up an identity provider.

By default, OIDC sign-in requires the ID token’s email_verified claim to be the Boolean true, including for identity providers without a known preset. The per-IdP setting accept_signins_without_email_verified is off by default. When an owner or admin turns it on, a missing claim is accepted; a present false or a non-Boolean value is still rejected. Microsoft Entra ID usually omits this claim, so turn the setting on only if your provider confirms that it verifies email addresses itself.

Only a verified tenant owner or admin can change this setting, with a Sanctum token that has the write ability and the sso.config-write permission. The configuration endpoint updates that administrator’s own IdP configuration.

When an ID token omits email_verified and the setting is on, the token’s OIDC issuer and subject are bound to the first account. An unbound subject cannot use an existing account’s email address, and a later email change for a bound subject is rejected. Tokens with a Boolean email_verified: true keep the verified-email sign-in path for the first account link; later sign-ins stay bound to that issuer and subject.

Removing the member who owns an organization’s SSO configuration does not delete the configuration. SAML ACS and OIDC sign-in callbacks check that its owner is still a member of the organization, so sign-ins are rejected while the owner is not a member.