Authentication
sg-api- keys for the inference API: format, scope, per-key limits, checking a key, revoking it, and keeping it safe.
Every request to the inference API carries an API key. Keys are issued by Safeguard's servers from the Console; nothing in your browser creates or stores them.
Send the key
Put the key in the Authorization header of every request:
curl https://api.safeguard.sh/gpt/v1/models \
-H "Authorization: Bearer $SAFEGUARD_INFERENCE_KEY"A key is sg-api- followed by 64 lowercase hexadecimal characters. The gateway accepts these keys and nothing else: a Safeguard sign-in token, an MCP key or a key made for another purpose is refused with 401 invalid_api_key. With the OpenAI SDKs, pass the key as api_key (Python) or apiKey (Node.js) and the SDK sends the header for you.
The Console's Workbench is the one exception: it runs on your Safeguard sign-in, so you can try models without a key.
Scope
A key created in the Console carries one scope, inference, and no other. It can:
- call
POST /chat/completions; - list models with
GET /modelsandGET /models/{id}; - describe itself with
GET /key.
It cannot call any other Safeguard API. Keys made for other purposes, such as MCP keys, cannot call the inference API.
A key belongs to the person who created it and spends the workspace's credit. It cannot be limited to one organization, project, product or agent.
Create a key
-
In the Console, open API keys and choose Create key.
-
Fill in the form:
Field What it does Name A label, such as production backend. Left empty, the key is calledUntitled key.Monthly spend limit (USD, optional) The most this key may spend in a calendar month (UTC). Empty means no limit for the key; the workspace limit still applies. Requests per minute (optional) A whole number. Empty means the default of 60 requests per minute. The form also explains where your prompts go: when you send a request with the key, the prompt goes to the provider of the model you choose (for example OpenAI, Anthropic or Google) and is processed under that provider's terms. That choice is yours, per request. Safeguard never uses API traffic to train models, and request logs hold metadata only unless an administrator turns on prompt storage. See Privacy and data.
-
Choose Create key, then copy the key from the Copy your key dialog. This is the only time the full key is shown. Clicking outside the dialog does not close it.
Safeguard stores only a SHA-256 hash of the key, plus its start (sg-api- and eight characters) and its last four characters, so the Console can show which key is which. Afterwards the Console shows the key masked, as its start and end: sg-api-1a2b3c4d…9f8e. A key created before the end was stored shows its start only.
- Create key is disabled until the API Platform is on for your workspace.
- Any member of the workspace can create a key, except an auditor account, whose access is read-only.
- Keys created in the Console do not expire. Revoke a key to end it.
- Times on API keys, such as Created and Last used, are shown in your browser's time zone. The server sends them in UTC.
Change a key's limits
On API keys, choose Edit on a key to change its name, its monthly spend limit or its requests per minute. Leave a limit empty for no spend limit, or for the default rate limit.
The gateway reads a key's settings again at most 30 seconds after a change, so a new limit applies within 30 seconds.
| Limit | Range | When it is reached |
|---|---|---|
| Monthly spend limit | In the Console, an amount above zero with up to two decimal places | 402 key_spend_limit_exceeded |
| Requests per minute | 1 to 10,000 (default 60) | 429 rate_limited, with a Retry-After header |
Limits explains how both are counted.
Check a key
GET /key describes the key that calls it:
curl https://api.safeguard.sh/gpt/v1/key \
-H "Authorization: Bearer $SAFEGUARD_INFERENCE_KEY"{
"data": {
"name": "production backend",
"prefix": "sg-api-1a2b3c4d",
"scopes": ["inference"],
"monthly_spend_limit_usd": "50.0",
"rate_limit_rpm": null,
"available_credit_usd": 42.5,
"month_spent_usd": 3.25,
"month": "2026-10"
}
}| Field | Meaning |
|---|---|
name, prefix, scopes | The key's name, its visible start and its scopes. |
monthly_spend_limit_usd | The key's monthly spend limit as a decimal string, or null for none. |
rate_limit_rpm | The key's requests per minute, or null for the default. |
available_credit_usd | The workspace's credit balance minus what requests in flight have reserved. |
month_spent_usd | What this key has spent in the current month. |
month | The current month in UTC, as YYYY-MM. |
The last three fields are left out when the billing service cannot answer at that moment; the request still succeeds.
Revoke a key
On API keys, choose Revoke on the key and confirm. Requests that use the key are refused within 30 seconds, because the gateway remembers a key it has already checked for up to 30 seconds. A revoke cannot be undone. The key moves to the Revoked section of API keys, where it stays listed with when it was revoked and what it spent this month, so its use can still be traced.
A key also stops working when:
- its owner is deactivated in the workspace, which revokes their keys at the same time; reactivating the member does not bring the keys back;
- its owner's account is deleted, suspended or locked.
Keep keys safe
- Keep keys on your servers. Never put one in browser code, a mobile app or a public repository: anyone holding a key can spend your workspace's credit.
- Use one key per application and environment. You can then revoke one without stopping the others, and see usage per key.
- Give every key a monthly spend limit that matches what that application should spend.
- If a key may have been exposed, revoke it and create a new one.
Key management best practices covers storage and rotation in more detail.
Authentication errors
| Status | code | Meaning |
|---|---|---|
| 401 | invalid_api_key | The key is missing, malformed, unknown, revoked or expired, or its owner can no longer use it. |
| 403 | gateway_disabled | The key is valid, but the API Platform is not switched on for the workspace. |
| 503 | auth_unavailable | Safeguard could not check keys at that moment. Retry after a short wait. |
The 401 message reads: Invalid, revoked or expired API key. Keys start with sg-api- and are sent as 'Authorization: Bearer <key>'. It never says which of the reasons applies.
Your own provider keys
Bring your own key: run API Platform requests on your workspace's own OpenAI, Anthropic, Google or other provider key, billed by the provider, with no Safeguard fee.
Models
GET /models and GET /models/{id}: which models your key can call, their prices and limits, how ids match the catalog at safeguard.sh/models, and how a model becomes callable.