Issue scoped API keys per customer and environment
Generate prefixed keys restricted to specific endpoints, read-only routes, or workspaces—no custom auth database required.
Checklist for scoped tenant API key design
- 01
Follow least-privilege scoping
Grant each customer or microservice key access strictly to the endpoints it actually calls.
- 02
Embed distinct key prefixes
Use separate prefixes for live vs test keys so developers and secret scanners recognize leaks fast.
- 03
Attach tenant ID metadata
Bind workspace_id and plan tier inside key metadata on creation rather than trusting request body IDs.
- 04
Verify cross-tenant isolation
Test that a key scoped to workspace A receives HTTP 403 when probing workspace B resources.
How it works in practice
Provisioned Tenant Key Policy
Prefix: ak_live_acme_ Tenant Metadata: { workspace_id: "ws_918", plan: "pro" } Allowed Endpoints: ["POST /v1/extract-sku", "GET /v1/jobs/*"] Denied: ["POST /v1/evals/*", "DELETE *"]
Gateway Enforcement
POST /v1/extract-sku -> 200 OK (tagged workspace=ws_918) POST /v1/evals/run -> 403 Forbidden {"error":"insufficient_key_scope"}
Every customer integration runs under least-privilege boundaries with zero custom auth tables or middleware.
Common questions
How do I avoid trusting a tenant_id sent inside the JSON body?
APIkit injects verified metadata stored on the API key itself directly into rate limits, logs, and connectors—ignoring spoofed body IDs.
Can I issue keys dynamically when a user signs up?
Yes. Call the key management endpoint from your signup flow to mint and display a scoped key automatically.
What format do generated API keys use?
Keys use high-entropy random tokens with distinct environment prefixes compatible with GitHub secret scanning.
Related tasks in this category
See all in API Key Auth, Scopes & Quotas-
Meter and cap monthly token quotas per tenant
Track exact prompt and completion token usage per workspace, warn at 80%, and enforce clean monthly caps without building Stripe metering pipelines.
-
Rotate API keys smoothly with overlapping grace windows
Issue replacement API keys with a configurable 24-hour or 7-day overlap window so mobile workers and cron jobs migrate without outages.
-
Verify end-user JWT claims directly at your AI endpoint
Let web or mobile apps pass Auth0, Clerk, or Supabase JWTs straight to APIkit—verifying signatures and claims without a proxy server.
-
Lock internal AI endpoints to approved IP and CIDR ranges
Ensure B2B partner integrations and internal admin pipelines only accept traffic from static VPN, VPC NAT, or enterprise IP blocks.
-
Configure exact CORS origin policies for browser clients
Allow your production domains and preview deployments to call endpoints cleanly while blocking unauthorized third-party sites.
-
Shield public unauthenticated AI forms from bot abuse
Keep interactive landing-page demos and public lead widgets safe from scripted prompt drain using origin checks, payload caps, and Turnstile tokens.