---
title: Scoped Per-Tenant AI API Keys | APIkit
description: Create and manage tenant-scoped AI API keys with granular endpoint permissions and environment prefixes.
canonical: "https://apikit.ai/j/issue-scoped-tenant-api-keys"
modified: 2026-11-14
author: apikit.ai editorial team
source: "https://apikit.ai"
category: API Key Auth, Scopes & Quotas
category_url: "https://apikit.ai/j#group-api-auth-permissions"
---

# 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.

## Prepared starting prompt

We give B2B customers direct API access to two of our five AI endpoints. I need prefixed API keys scoped strictly per tenant and allowed route.

### Quick scenarios
- **Endpoint-level scopes:** Restrict partner keys to POST /v1/classify while blocking admin or eval endpoints.
- **Recognizable prefixes:** Issue clear prefixes like ak_live_ and ak_test_ so secret scanners catch accidental Git commits.
- **Programmatic provisioning:** Create and revoke customer API keys via management API during workspace onboarding.

- [Request early access](https://apikit.ai/#waitlist-f73a0d)

## Checklist for scoped tenant API key design

1. **Follow least-privilege scoping** — Grant each customer or microservice key access strictly to the endpoints it actually calls.
2. **Embed distinct key prefixes** — Use separate prefixes for live vs test keys so developers and secret scanners recognize leaks fast.
3. **Attach tenant ID metadata** — Bind workspace_id and plan tier inside key metadata on creation rather than trusting request body IDs.
4. **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.

## Frequently Asked 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

- [Meter and cap monthly token quotas per tenant](https://apikit.ai/j/enforce-monthly-token-quotas-tenants.md)
- [Rotate API keys smoothly with overlapping grace windows](https://apikit.ai/j/rotate-compromised-keys-grace-window.md)
- [Verify end-user JWT claims directly at your AI endpoint](https://apikit.ai/j/validate-end-user-jwt-tokens.md)
- [Lock internal AI endpoints to approved IP and CIDR ranges](https://apikit.ai/j/restrict-endpoint-access-ip-allowlist.md)
- [Configure exact CORS origin policies for browser clients](https://apikit.ai/j/configure-cors-origins-browser-calls.md)
- [Shield public unauthenticated AI forms from bot abuse](https://apikit.ai/j/protect-public-forms-abuse-shields.md)

---

*Published by **Wondel.ai sp. z o.o.** · [apikit.ai](https://apikit.ai) · [About](https://apikit.ai/about) · [Editorial Guidelines](https://apikit.ai/editorial) · [Contact](https://apikit.ai/contact) · [Wondel.ai Products](https://wondel.ai/products)*