Anvil uses API keys for all programmatic access. This page covers how to issue, rotate, and revoke keys safely.
Every API key is a Bearer token scoped to a single tenant. Keys look like this:
anv_live_sk_49kPz9... (production)
anv_test_sk_49kPz9... (sandbox)Treat keys as passwords. Never commit them to Git, never paste them into client-side JavaScript, and never share them over unencrypted channels.
Pass the key in the Authorization header on every request:
curl https://api.anvilhk.com/v1/leads \
-H "Authorization: Bearer anv_live_sk_49kPz9..." \
-H "Content-Type: application/json"Responses include the authenticated tenant on every call via the X-Anvil-Tenant response header, so you can sanity-check you hit the right account.
Keys can be narrowly scoped to reduce blast radius:
Always grant the narrowest scope that covers your use case. A Zapier integration that only creates leads should not carry an admin key.
We recommend rotating production keys every 90 days. To rotate:
Anvil supports overlapping keys so you can rotate with zero downtime.
Navigate to **Settings > API Keys**, click the key, and choose **Revoke**. Revocation takes effect within five seconds globally. Any request made with a revoked key returns HTTP 401 with error.code = "KEY_REVOKED".
If a key is accidentally leaked (e.g. committed to a public repo), revoke it immediately. We automatically scan GitHub for leaked keys via GitHub's secret-scanning partner program and will revoke on detection.
If you are building an app that acts on behalf of multiple Anvil customers, use our OAuth 2.0 flow instead of static API keys. Register your app at **Developer Portal > OAuth Apps**, then redirect users to:
https://api.anvilhk.com/v1/oauth/authorize?client_id=...&scope=read:leads&redirect_uri=...The authorization-code grant returns a refresh token valid for 30 days. See the [OAuth integration guide](/docs/integrations/custom) for the full flow.