How to Add the Claude API to Your Existing SaaS
Adding the Claude API to an existing SaaS product usually means solving three problems at once: getting a working integration, handling API keys and billing per customer, and doing it without rewriting your backend. The good news is you don't need to build an LLM platform from scratch — you need an auth layer, a usage model, and a stable endpoint to call.
This guide walks through both paths: wiring Claude directly into your app via Anthropic's API, and using a managed layer like SubToAPI when you want application-level keys, streaming, and usage metadata without building that infrastructure yourself.
What "adding Claude" actually requires
Before writing code, decide on four things, because they shape your architecture more than the model choice does:
- Where keys live. One shared key for your whole app, or a key per customer/tenant?
- Who pays for tokens. Do you absorb the cost in your subscription price, or pass it through with markup?
- What features you need now. Plain completions are easy. Streaming, tool use, and multi-turn context need more plumbing.
- How you'll monitor usage. Without per-request logging, a bug in a prompt loop can burn through your budget in hours.
Most teams get stuck not on the API call itself, but on points two and four — billing and visibility.
Option 1: Direct integration with Anthropic's API
If you're calling Claude from a backend you already control, the raw integration is straightforward. A basic server-side call looks like this:
const response = await fetch("https://api.anthropic.com/v1/messages", {
method: "POST",
headers: {
"x-api-key": process.env.ANTHROPIC_API_KEY,
"anthropic-version": "2023-06-01",
"content-type": "application/json",
},
body: JSON.stringify({
model: "claude-opus-4-1",
max_tokens: 1024,
messages: [{ role: "user", content: "Summarize this ticket: ..." }],
}),
});
This works fine for a single internal feature. It gets harder once you need:
- Separate usage tracking per customer or workspace
- Rate limits that don't affect your whole app when one tenant spikes
- Team members sharing access without sharing one raw key
- Streaming responses to the browser without exposing your Anthropic key client-side
At that point you're building an internal gateway: a proxy service, a key management table, a usage ledger, maybe a billing hook. It's doable, but it's a parallel project, not a feature.
Option 2: Add Claude through a managed API layer
A faster path for SaaS teams is to put a thin, managed layer between your app and Claude. SubToAPI does exactly this: it turns your Claude access into application API keys (sub_live_...) that your SaaS can issue, rotate, and track per customer or per internal service — with streaming, tool use, and usage metadata built in, plus team seats so your whole engineering team can work from one dashboard.
The integration pattern is the same /v1/messages-style call, just pointed at SubToAPI instead of building your own proxy:
curl https://api.subtoapi.app/v1/messages \
-H "Authorization: Bearer $SUBTOAPI_KEY" \
-H "content-type: application/json" \
-d '{
"model": "claude-opus-4-1",
"max_tokens": 1024,
"messages": [
{ "role": "user", "content": "Draft a reply to this support ticket." }
]
}'
Because the key is scoped and trackable, you can issue a distinct sub_live_... key per internal environment (staging, production, a specific feature flag) without touching billing logic in your own database. See the quickstart for the full setup and docs/messages for the request/response shape.
Step-by-step: wiring Claude into an existing SaaS
- Pick the integration point. Usually a single backend service or edge function that already handles your app's authenticated requests — don't call the API directly from the browser.
- Create a key. Generate a key via Anthropic or, if you're using SubToAPI, through the dashboard after signing up. Store it as a server-side environment variable, never in client bundles.
- Wrap the call in your own function. Keep one internal function (
callClaude()or similar) that all features go through. This is where you'll later add retries, logging, and model selection — doing this early saves a rewrite. - Add streaming if your UI needs it. For chat-style features, stream tokens back to the client rather than waiting for the full response. See docs/streaming for the SubToAPI streaming format if you're using that layer.
- Add tool use if the feature needs structured output or external actions. Claude's tool-calling lets the model request a function call (e.g., "look up order #4521") instead of just returning text — see docs/tools.
- Instrument usage before you ship. Log tokens per request, tagged by customer ID, from day one. Retrofitting usage tracking after a billing dispute is painful.
- Gate the feature behind your existing plan logic. Treat Claude-powered features like any other paid capability — check entitlements before making the call, not after.
Billing and team access
If multiple engineers or support staff need to trigger Claude calls (not just your backend), avoid handing out one shared key. A single leaked or misused key is an outage waiting to happen. This is the specific gap SubToAPI's seat-based plans address: Solo at €9 for a single integration, Team at €19/seat when more than one person needs dashboard access and individual keys, and Scale at €49/seat for larger teams needing more headroom. All plans start with a free trial, so you can wire up a feature before committing. Full breakdown on pricing.
Common mistakes to avoid
- Hardcoding the model name everywhere. Put it in one config value so you can upgrade later without a find-and-replace.
- Skipping timeout handling. LLM calls are slower than typical API calls — set client-side timeouts that match reality, not your default 5-second fetch timeout.
- Not separating test and production keys. A test prompt accidentally hitting production billing is a common and avoidable mistake.
- Ignoring context window limits when passing conversation history. Trim or summarize older turns rather than letting requests grow unbounded.
questions
Do I need to rebuild my backend to add Claude? No. In most cases you add one new internal function that calls the Messages API and wire your existing feature flags and billing checks around it. The surrounding architecture of your SaaS doesn't need to change.
Should I give every customer their own API key? If you're passing usage-based costs to customers or need per-tenant rate limits, yes — issue scoped keys per tenant. If Claude usage is just a feature inside a flat subscription, one server-side key with internal usage logging is usually enough.
What's the fastest way to get Claude running without building a gateway myself? Use a managed layer like SubToAPI: sign up, generate a sub_live_... key, and point your existing /v1/messages-style call at it. You get streaming, tool use, and usage metadata without building a proxy service yourself — start from the quickstart.