Skip to content

Protect with API keys

The api-key auth mode requires every incoming request to present an API key. Keys are issued by you, scoped to a single application, and checked on the serving device before any request reaches your workload.

Find the access entry you want to protect and update its policy:

app.yml
policies:
auth: { modes: [none] }
auth: { modes: [api-key] }
Terminal window
edgible stack deploy -f app.yml

From this point, requests without a valid key receive 401 Unauthorized. Requests with one are forwarded to your workload.

Terminal window
edgible application api-keys create \
--app <app-id> \
--name "ci-deploy"

Output includes the key value — save it now. It’s not shown again.

Key created.
ID: ak_a1b2c3d4
Name: ci-deploy
Token: sk_d4e5f6a7b8c9... (save this — it will not be shown again)
Expires: never

To set an expiry:

Terminal window
edgible application api-keys create \
--app <app-id> \
--name "vendor-integration" \
--expires 2026-12-31

Send the key as a bearer token in the Authorization header:

Terminal window
curl https://api.example.com/v1/things \
-H "Authorization: Bearer sk_d4e5f6a7b8c9..."

Or in an X-API-Key header:

Terminal window
curl https://api.example.com/v1/things \
-H "X-API-Key: sk_d4e5f6a7b8c9..."

Or as the password in HTTP Basic auth (any username), for tools that only speak Basic auth, such as git and calendar or contact sync apps:

Terminal window
curl -u "any:sk_d4e5f6a7b8c9..." https://api.example.com/v1/things

See Connect git, phone apps and other tools for client-by-client setup. Keys in query strings are not supported.

The serving device checks the key with the platform, then forwards the request to your workload. A missing or wrong key gets 401, with a WWW-Authenticate: Basic header so tools that wait for a login prompt send the key. If the application allows both organization login and API keys, a request with a wrong key still gets 401 (not a redirect to the login page); only a request with no credentials is redirected to login.

A key that passed the check is remembered on the serving device for up to 5 minutes (never past the key’s expiry), so repeat requests do not wait for the platform. A rejected key is never remembered. If the platform cannot be reached once that time is up, requests with the key get 401 until it can be reached again.

Terminal window
# See the keys for an application (token bodies are not shown).
edgible application api-keys list --app <app-id>
# Delete a single key.
edgible application api-keys delete --app <app-id> --key-id ak_a1b2c3d4

Deleting a key tells the application’s serving devices to forget it, so it stops working within seconds. A device that is offline at that moment stops accepting it within 5 minutes.

Rotation is a manual two-step: create a new key, update consumers, delete the old key. There’s no in-place rotation.

A browser sends a “preflight” OPTIONS request, with no credentials, before a cross-origin fetch that carries an Authorization or X-API-Key header. By default the edge refuses it with 403, so the call never happens. If your application already handles CORS, let preflights through to it:

access:
- name: api
type: https
target: { workload: api, port: http }
policies:
auth: { modes: [api-key] }
cors: { mode: passthrough }

Apply it with edgible stack deploy -f app.yml, or from the CLI with edgible application update --app <app-id> --cors passthrough. Real requests still need a valid key. Requires agent 1.4.14 or later on the serving device.

To have the edge answer preflights for you from an allow-list of origins, use mode: managed. See policies.cors.

The --name is what shows up in api-keys list and what you’ll see when auditing. Use names that describe who or what uses the key, not what it does. ci-deploy, monitoring-pinger, vendor-acme-prod are good. production, key1, temp are bad.

If you want to share access with a person for a defined window — a contractor for a week, a client demo for a day — short-code is the better fit. Short codes have built-in expiry and use-count limits, and toggling them off is one CLI call.

Terminal window
edgible application short-codes create \
--app <app-id> \
--name "demo-2026-04" \
--expires 2026-04-30T18:00:00Z \
--max-uses 100

See Authentication modes for the full distinction.