---
title: "API Keys & Bearer Auth: Create, Cap & Rotate Keys | Straitly Docs"
description: "Authenticate with Authorization: Bearer $STRAITLY_API_KEY on OpenAI and Anthropic endpoints. Set daily USD caps, wait 15s for activation, and rotate keys."
url: https://straitly.ai/docs/authentication
updated: 2026-11-26
publisher: Straitly (https://straitly.ai)
---

Docs

Get started

# API keys & authentication

Copy docs

**On this page**

Authenticate every request with Authorization: Bearer $STRAITLY\_API\_KEY against https://api.straitly.ai/v1 (or the Anthropic SDK root URL). New keys activate in about 15 seconds; keep account keys on your server, set optional UTC daily spend caps, and use child keys or team roles when sharing access.

### Create a key

- Sign in, verify your email, and open API keys. Your account role must allow key creation.
- Give the key a descriptive name such as prod-api or local-dev. Set a daily spend cap if appropriate.
- Store the raw key securely when it is returned. The console stores a hash rather than a recoverable plaintext copy.
- New keys can take about 15 seconds to activate. If a newly created key returns 401, wait briefly and check again before replacing it.

[Manage API keys](https://straitly.ai/app/keys) [Teams & roles](https://straitly.ai/docs/teams)

### Send your key

Set the environment variable in the same terminal or server process that runs your application. The example below lists available models without sending an inference request.

Terminal

Copy Copied Failed

export STRAITLY_API_KEY="YOUR_STRAITLY_API_KEY"

curl https://api.straitly.ai/v1/models \
  -H "Authorization: Bearer $STRAITLY_API_KEY"

PowerShell uses $env:STRAITLY\_API\_KEY="YOUR\_STRAITLY\_API\_KEY". Never place the key in a URL query string.

### Store it safely

- Use your hosting provider's secret store in production. A local .env file should be excluded from version control.
- Do not expose an account key in frontend JavaScript, screenshots, support messages, or public repositories.
- A key can authorize more than inference, including account tools such as MCP. Only give it to clients you trust.
- Use distinct keys for environments and applications so a revoked development key does not interrupt production.

### Replace or revoke a key

For a planned replacement, create a new key, wait for activation, update the application secret, and verify a request. Revoke the old key after confirming consumers have switched.

For a leaked key, revoke it immediately and investigate Activity. Removing it from a repository or chat does not invalidate copies someone may already have.

Child keys have a separate rotation API with an optional grace period. Do not assume ordinary account-key replacement has the same API contract.

[Child-key rotation](https://straitly.ai/docs/child-keys#rotate) [Request activity](https://straitly.ai/app/activity)

### Troubleshoot authentication

- 401: check the active key, bearer header, and server environment. Remove accidental whitespace and confirm the key is not revoked.
- 403 while creating keys: verify your email and account permissions. Partner-key minting requires separate account enablement.
- 402: authentication may be valid but credits or a spending cap are exhausted. Replacing the key is not the right fix for an account balance issue.

[Errors & limits](https://straitly.ai/docs/errors) [Billing & invoices](https://straitly.ai/docs/billing) [Account & sign-in](https://straitly.ai/docs/account) [Child keys](https://straitly.ai/docs/child-keys) [Production checklist](https://straitly.ai/docs/production) [Help & community](https://straitly.ai/docs/support)

### Common questions

**How do I authenticate requests to Straitly?**

Send Authorization: Bearer $STRAITLY\_API\_KEY in the request header to https://api.straitly.ai/v1 (or pass the same key to the Anthropic SDK with base URL https://api.straitly.ai). Never put an API key in a URL query string or frontend code.

**Why does a brand new API key return 401?**

New keys can take about 15 seconds to activate across the gateway. Wait briefly and retry before creating another key, and check for accidental whitespace or newlines in your environment variable.

**How do I rotate a leaked or production API key safely?**

For a planned rotation, create a new key, wait about 15 seconds for activation, update your secret store, verify a call, and then revoke the old key. For a leaked key, revoke it immediately in the console and inspect Activity; child keys also support grace-period rotation via POST /v1/admin/keys/{key\_hash}/rotate.

**Can I put a spend limit on an API key?**

Yes. Standard account keys support an optional UTC daily spend cap set in API keys, and child keys support both daily\_cap\_usd and lifetime total\_cap\_usd budgets plus per-key RPM and concurrency limits.

[Quickstart](https://straitly.ai/docs/quickstart) [Endpoints](https://straitly.ai/docs/endpoints)

---
Markdown version of https://straitly.ai/docs/authentication.
