← Blog

Claude Integration Guide: From API Key to Production

2026-09-09 · 5 min read · SubToAPI Team

Integrating Claude into a product usually means one of three things: calling Anthropic's API directly from your backend, going through a cloud provider like Bedrock or Vertex, or wrapping access behind a gateway that gives you API keys, usage tracking, and team management out of the box. This guide walks through the actual steps of each approach so you can pick the right one and get a working integration today.

Most teams get stuck not on the AI part but on the plumbing: authentication, streaming responses to a UI, handling tool calls, tracking who used how many tokens, and rotating keys when someone leaves the team. This guide covers all of that, not just the "send a prompt, get a response" happy path.

Decide where your Claude access comes from

Before writing any code, pick your access path:

The integration code is nearly identical across all three — you're sending JSON to a /messages endpoint and reading a JSON or streamed response. The difference is where the key comes from and how usage is billed and tracked.

Step 1: Authentication

Every integration starts with a bearer token in an Authorization header. Store it in an environment variable, never in client-side code:

export SUBTOAPI_KEY="sub_live_xxxxxxxxxxxx"
curl https://api.subtoapi.app/v1/messages \
  -H "Authorization: Bearer $SUBTOAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-3-5-sonnet-20241022",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Summarize this ticket in one sentence."}]
  }'

If your key ever leaks — pushed to a public repo, exposed in a mobile app bundle — treat it like a leaked database password: revoke it immediately from your dashboard and issue a new one.

Step 2: Sending and receiving messages

The core of any Claude integration is the messages endpoint. Requests take a model, max_tokens, and an array of messages with alternating user/assistant roles. The response includes the generated content, a stop_reason, and token usage:

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-3-5-sonnet-20241022",
    max_tokens: 512,
    messages: [
      { role: "user", content: "Draft a changelog entry for a new dark mode setting." }
    ]
  })
});

const data = await res.json();
console.log(data.content[0].text, data.usage);

Keep the message history yourself — the API is stateless per request. Each call needs the full conversation context if you want multi-turn behavior. Full parameters and response shapes are documented at /docs/messages.

Step 3: Streaming for responsive UIs

If Claude output is shown live in a chat interface, streaming matters more than any other integration detail — a 5-second wait for a full response feels broken, while the same response streamed token-by-token feels instant. Set "stream": true and read server-sent events as they arrive:

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-3-5-sonnet-20241022",
    max_tokens: 512,
    stream: true,
    messages: [{ role: "user", content: "Explain event loops in one paragraph." }]
  })
});

const reader = res.body.getReader();
// read chunks and parse SSE events as they arrive

Details on event types and reconnect handling are in /docs/streaming.

Step 4: Tool use for real actions

Most useful integrations go beyond text generation — Claude needs to look up a record, call an internal API, or run a calculation. Tool use lets you define functions with a JSON schema; Claude decides when to call them and returns structured arguments instead of guessing at answers:

{
  "name": "get_order_status",
  "description": "Look up the current status of a customer order",
  "input_schema": {
    "type": "object",
    "properties": { "order_id": { "type": "string" } },
    "required": ["order_id"]
  }
}

Your backend executes the actual function, sends the result back in the conversation, and Claude incorporates it into its final answer. This is the pattern behind most "Claude-powered" support bots and internal assistants. Full request/response examples are at /docs/tools.

Step 5: Handle errors and rate limits

Production integrations need to handle three failure modes explicitly:

Log stop_reason and token usage on every call. When something looks wrong in production, usage data tells you whether the model hit a token limit, was cut off, or completed normally.

Step 6: Give your team controlled access

Once the integration works, the next problem is usually access control: multiple developers, a staging key and a production key, and visibility into who's consuming tokens. Rather than sharing one key in a shared .env file, issue separate keys per environment or per team member, and review usage in a dashboard instead of guessing from a bill. If you're building on top of an existing Claude subscription, SubToAPI handles this with per-seat keys and usage metadata across Solo, Team, and Scale plans, so scaling from one developer to a full team doesn't mean re-architecting your integration.

Start with a working call, add streaming once the UI needs it, add tool use once you need Claude to act rather than just respond, and add key management once more than one person touches the code. The quickstart covers the first working request in under five minutes if you want to skip straight to code, and /signup gets you a key if you're integrating against SubToAPI directly.

FAQ

Do I need Anthropic API access to integrate Claude, or does a Claude subscription work? A direct Anthropic API key is one path, but if you already pay for a Claude subscription, a service like SubToAPI can expose that access as a standard HTTPS API without a separate API billing account.

What's the minimum I need to build a working integration? An API key, a POST request to a messages endpoint with a model name and message array, and a way to read the JSON response — that's a complete, if basic, integration.

When should I add streaming instead of waiting for the full response? Add streaming as soon as output is shown live to a user, such as in a chat UI. For background jobs, reports, or batch processing, a single non-streamed response is simpler and sufficient.

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 →