Claude API Multi-Tenant SaaS Architecture Guide
If you're building a SaaS product on top of Claude and need to serve multiple customers — each with their own usage limits, billing, and data boundaries — you're dealing with a multi-tenant architecture problem, not just an API integration problem. The Claude API itself is tenant-agnostic: it just processes requests. The multi-tenancy has to be built in your application layer, between your users and the model.
This article walks through the concrete decisions you need to make: how to structure API keys per tenant, how to isolate data and prompts, how to meter usage for billing, and how to enforce per-tenant rate limits without building a metering system from scratch.
What "multi-tenant" actually means here
In a Claude-powered SaaS, multi-tenancy usually means three things need to happen independently for every customer (tenant):
- Authentication and authorization — each tenant's end users can only access their own tenant's data and conversations.
- Usage accounting — tokens consumed by tenant A must never be billed to tenant B, and you need visibility into per-tenant cost.
- Rate and quota enforcement — one noisy tenant shouldn't be able to exhaust your shared Anthropic quota and degrade service for everyone else.
None of this is handled by calling the Claude API directly with a single API key. A single shared key gives you one bucket of usage, one rate limit, and no built-in way to attribute cost to a tenant. That's the core architectural problem you need to solve.
Shared key vs. per-tenant key
There are two common patterns:
Pattern 1: Single upstream key, application-level metering. You hold one Claude API key, and your backend logs every request with a tenant_id, then aggregates token usage from the response metadata into your own billing database. This is cheap to start but means you're maintaining metering, quota logic, and rate limiting code yourself — and it gets more fragile as you add streaming, tool use, and retries.
Pattern 2: Per-tenant application keys. Each tenant (or each app/environment) gets its own scoped API key that maps back to a single underlying Claude account. This is the pattern SubToAPI is built around: you connect your existing Claude access once, then issue sub_live_... keys per tenant or per project from the dashboard. Usage, rate limits, and cost are tracked per key automatically, so "tenant B burned through 2M tokens this month" is a query against your dashboard, not a query against your own logging pipeline.
If you're building the metering system yourself, budget real engineering time for it — it's not a side feature, it's close to half the architecture.
Designing the tenant isolation layer
Request routing and context injection
Every inbound request to your backend should resolve to a tenant before it touches Claude. A typical middleware shape:
async function resolveTenant(req, res, next) {
const tenant = await db.tenants.findByApiKey(req.headers['x-app-key']);
if (!tenant) return res.status(401).json({ error: 'invalid_tenant' });
req.tenant = tenant;
next();
}
Once resolved, inject tenant-scoped context into the Claude request — system prompt constraints, allowed tools, and any tenant-specific knowledge base references. Never let tenant A's conversation history or documents leak into tenant B's request, even accidentally through a shared cache key or shared vector store namespace.
Data isolation and prompt isolation
Keep conversation history, uploaded documents, and tool outputs partitioned by tenant_id at the database level — row-level security if you're on Postgres, separate collections if you're on a document store. If you cache prompts or responses for cost savings, key the cache by tenant, not just by prompt hash, unless the content is genuinely tenant-independent (e.g. a shared public knowledge base).
Usage metering and billing per tenant
Whatever upstream pattern you pick, you need per-tenant visibility into:
- Input and output tokens per request
- Number of requests per billing period
- Tool-use calls, if you're billing those separately
- Streaming vs. non-streaming usage (some teams price these differently)
If you're calling the Claude API directly, you'll parse usage from each response and write it to your own ledger table, keyed by tenant_id and timestamp. If you're using SubToAPI, this is already surfaced per application key in the dashboard — each tenant's key shows its own usage, so you can either pass that through to your billing system or just read it when reconciling invoices.
curl https://api.subtoapi.app/v1/messages \
-H "Authorization: Bearer $SUBTOAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-4-5",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Summarize this contract clause."}]
}'
Issue one key per tenant and the usage returned here is automatically scoped to that tenant — no extra token-counting logic needed on your side. See /docs/messages for the full request/response shape.
Rate limiting and quota enforcement
Per-tenant rate limits protect your margins and your reliability. At minimum, enforce:
- Requests per minute per tenant, to prevent a single customer from monopolizing throughput
- Monthly token quota tied to the tenant's subscription tier
- Burst protection on streaming connections, since a tenant opening dozens of concurrent streams can exhaust connection pools fast
If you manage this yourself, a token-bucket algorithm per tenant_id in Redis is the standard approach. If you're using per-tenant application keys through a platform like SubToAccount, plan quotas can be enforced at the key level — Solo, Team, and Scale plans (see /pricing) map naturally onto per-tenant or per-seat limits without you building a second rate limiter on top of Anthropic's own.
Streaming and tool use across tenants
Streaming responses (see /docs/streaming) add a wrinkle: you need to track partial token usage as the stream progresses, not just at completion, in case a tenant disconnects mid-stream. Tool use (see /docs/tools) adds another: make sure tool definitions and permissions are scoped per tenant, so tenant A's custom function isn't accidentally available to tenant B's conversation. Keep the tool registry tenant-aware at the point where you build the tools array for each request, not as an afterthought.
A reference architecture
A reasonable shape for most SaaS products:
- Tenant resolves via your auth layer (API key, JWT, or session).
- Backend builds the Claude request with tenant-scoped system prompt, history, and tools.
- Request goes out through a tenant-specific application key (via SubToAPI or your own key-management layer).
- Response usage is logged against the tenant, either automatically (dashboard) or manually (your ledger table).
- A nightly job reconciles usage against each tenant's plan and flags overages.
Getting started with a working setup takes minutes if you're not building the key-management layer yourself — see /docs/quickstart and /signup.
Questions
Do I need a separate Claude API key per tenant? Not strictly, but it's the simplest way to get accurate per-tenant cost attribution and isolated rate limits without writing custom metering code. Per-tenant application keys are the recommended pattern for anything beyond a handful of customers.
How do I prevent one tenant from affecting another's performance? Enforce per-tenant request-rate and token quotas independently of your overall Anthropic quota. Token-bucket rate limiting keyed by tenant_id, or per-tenant application keys with built-in limits, both work — the key requirement is that one tenant's burst never shares a bucket with another's.
Can I bill tenants based on actual Claude usage? Yes — pull per-tenant token counts from the usage field on each response (or from your key dashboard if using per-tenant keys) and map them to your pricing tiers. This is more accurate than flat per-seat pricing if your tenants have highly variable usage patterns.