← Blog

How to Add Claude API to an Existing SaaS Product

2026-10-30 · 5 min read · SubToAPI Team

Adding Claude API to an existing SaaS product means deciding where the AI calls sit in your architecture, how you'll authenticate and meter usage, and how you'll roll it out without breaking what already works. The short answer: you don't rebuild your backend around an LLM provider — you add a thin service layer that talks to Claude, wraps it with your own auth and usage tracking, and exposes it to your existing frontend through endpoints you already control.

This matters because most teams get stuck on the wrong problem. They spend days debugging streaming responses or prompt formatting when the real blocker is usage accounting, key management across environments, and billing integration. This article walks through the integration in the order that actually matters for a product that's already live with paying users.

Step 1: Decide where Claude fits in your stack

Before writing any code, map out where the AI feature lives:

Most teams underestimate how different these are operationally. A synchronous call needs timeout handling and retries. A streaming feature needs your backend to proxy the stream without buffering it. A background job needs idempotency keys so a retry doesn't double-charge a user's quota. Decide this up front — it changes which endpoints you build.

Step 2: Keep the Claude integration out of your main API surface

Don't bolt Claude calls directly into existing controllers that handle your core product logic. Instead, create a dedicated internal service — call it ai-service or similar — that is the only part of your codebase making outbound calls to Claude. This gives you:

// ai-service/generate.js
async function generateSummary(customerId, text) {
  const res = await fetch("https://api.subtoapi.app/v1/messages", {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${process.env.SUBTOAPI_KEY}`,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      model: "claude-sonnet-4-5",
      max_tokens: 500,
      messages: [{ role: "user", content: `Summarize: ${text}` }]
    })
  });

  const data = await res.json();
  await logUsage(customerId, "summary", data.usage);
  return data.content;
}

Notice the logUsage call — this is non-optional. If you're charging for the AI feature (directly or as part of a plan tier), you need per-customer usage data from day one, not retrofitted later.

Step 3: Handle authentication and key management properly

If you're calling Claude directly, you're managing API key rotation, rate limits, and billing reconciliation yourself. This is fine for a side project; it gets messy fast in a multi-tenant SaaS where you need per-customer or per-environment visibility into usage and cost.

This is the specific gap SubToAPI is built for: it turns your existing Claude access into a standard HTTPS API with application keys (sub_live_...) that you can issue per environment or per internal team, with usage metadata returned on every response and team seats in one dashboard. Instead of one shared key buried in an environment variable, you get keys scoped to what you're building, and you can see exactly which feature or customer is driving token spend.

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": 300,
    "messages": [{"role": "user", "content": "Draft a release note for v2.3"}]
  }'

Set this up once with a key per environment (dev, staging, prod) so a bug in staging never touches production usage numbers or rate limits. The quickstart docs cover key creation and your first request end to end.

Step 4: Add streaming without rewriting your frontend

If your feature needs streaming (chat, live generation), you don't need to rip out your existing frontend fetch logic. Your backend proxies the stream:

app.post("/api/ai/chat", async (req, res) => {
  res.setHeader("Content-Type", "text/event-stream");

  const stream = await fetch("https://api.subtoapi.app/v1/messages", {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${process.env.SUBTOAPI_KEY}`,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      model: "claude-sonnet-4-5",
      max_tokens: 1024,
      stream: true,
      messages: req.body.messages
    })
  });

  stream.body.pipe(res);
});

Full details on event formats and client-side parsing are in the streaming docs. This pattern lets your existing session/auth middleware stay in front of the endpoint — the AI call is just another route.

Step 5: Gate the feature behind your existing plan tiers

Most SaaS products adding Claude want the feature tied to an existing pricing tier or add-on, not given away unmetered. Use the usage data from Step 2 to:

This is where having clean per-key usage metadata pays off — you're not parsing logs after the fact to figure out who used what.

Step 6: Add tool use once the basic feature is stable

If your AI feature needs to act on your own data — pull a record, update a status, search a database — you'll want Claude's tool use rather than stuffing everything into the prompt. Ship the basic generate/summarize/chat feature first, confirm usage and cost behave as expected, then layer in tools. The tools documentation covers defining function schemas and handling the back-and-forth tool-call loop.

Rollout checklist

Questions

Do I need a new backend service to add Claude to my SaaS? No — you need a thin internal layer (a module or microservice) that owns all outbound Claude calls, logging, and retries. It plugs into your existing API routes and auth; it doesn't replace them.

How do I avoid surprise AI costs when adding this feature? Log token usage per customer and per feature from the first deployment, and gate the feature by plan tier with hard limits. Review pricing against your expected volume before launch, not after.

Can I add streaming AI responses without rewriting my frontend? Yes. Keep your existing fetch/auth logic and add a backend route that proxies the Claude stream as server-sent events, as shown in the streaming example above. See the streaming docs for implementation details.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →