Claude API: How to Get a Key, What It Costs, and How to Build a Website Chatbot With It (2026)

Yes, Claude has an API. Here's how to get a Claude API key, what Claude API pricing looks like per model, a working TypeScript example, and when a no-code chatbot builder is the smarter route.

Sanskar Tiwari profile photo
Sanskar TiwariFounder, MagicChat · Amazon author
10 min read

If you've typed "does Claude have an API" into Google, the short answer is yes. Anthropic exposes every Claude model through a REST API, and most people reach for it for one reason: they want a chatbot that answers questions about their business, not the open internet.

This guide covers the three things people actually search for: how to get a Claude API key, what the Claude API costs, and how to wire it into a support chatbot on your website. It ends with an honest comparison against the no-code route, because for a lot of teams the API is the wrong tool.

Does Claude have an API?

Yes. The Claude API lives at https://api.anthropic.com and the main endpoint is the Messages API (POST /v1/messages). You send a conversation, Claude sends back a reply. Everything else, tool use, streaming, PDFs, images, prompt caching, is a feature of that one endpoint rather than a separate product.

Anthropic ships official SDKs for Python, TypeScript, Java, Go, Ruby, C#, and PHP. If you've used the OpenAI SDK, the shape will feel familiar, but it is not a drop-in replacement. The request format and the model names are different.

Three products get confused with each other, so to be clear:

ProductWhat it isWho it's for
Claude.aiThe chat app at claude.aiAnyone chatting with Claude
Claude APIProgrammatic access to the same modelsDevelopers building apps
Claude CodeA terminal coding agent built on the APIDevelopers writing software

A Claude.ai subscription (Pro, Max) does not include API access. The API is billed separately, pay as you go.

How to get a Claude API key

  1. Go to the Claude Console at platform.claude.com and sign up or sign in.
  2. Open API Keys in the left sidebar and click Create Key. Give it a name tied to the project (for example support-bot-prod), not "test".
  3. Copy the key immediately. The Console shows it once. If you close the dialog without copying, delete that key and make a new one. That is the answer to "how do I copy my Claude API key again": you can't, you rotate.
  4. Add credits under Billing. New accounts start with no balance, and requests fail with an authentication or billing error until there is one.
  5. Store the key as an environment variable, never in frontend code:
export ANTHROPIC_API_KEY="sk-ant-..."

Anyone with that key can spend your credits, so keep it on the server. A browser-side fetch to the Claude API with your key in it is the most common way people leak one.

Claude API pricing (per million tokens)

Claude API pricing is per token, split into input (what you send) and output (what Claude writes). Prices below are Anthropic's first-party rates as of this writing. Check the official pricing page before you budget.

ModelModel IDInput / 1M tokensOutput / 1M tokensContext
Claude Opus 5claude-opus-5$5.00$25.001M
Claude Sonnet 5claude-sonnet-5$2.00$10.001M
Claude Haiku 4.5claude-haiku-4-5$1.00$5.00200K

Two things cut the bill significantly:

  • Prompt caching. If every request starts with the same system prompt and knowledge base, you can cache that prefix. Cached reads cost roughly a tenth of normal input tokens. For a support bot this matters more than the model choice.
  • Batch API. Non-urgent work (summarising tickets overnight, classifying leads) runs at 50% off.

What a support chatbot actually costs on the API

Say your bot handles 4,000 conversations a month. Each one sends about 3,000 input tokens (system prompt plus the retrieved help-centre passages) and gets a 300-token reply. Ballpark API spend, before caching:

ModelMonthly API cost
Claude Opus 5~$90
Claude Sonnet 5~$36
Claude Haiku 4.5~$18

That is only the Claude line item. You still need somewhere to host the endpoint, a way to crawl and chunk your website, an embedding model and vector store for retrieval, a chat widget, and someone to keep all of it running. The API bill is usually the smallest part.

Build a website chatbot with the Claude API (TypeScript)

Here is the minimum viable support bot: a Next.js route handler that takes a question, pulls the relevant passages from your docs, and streams Claude's answer back to the widget.

Install the SDK:

npm install @anthropic-ai/sdk

Then the route:

// app/api/support-chat/route.ts
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic(); // reads ANTHROPIC_API_KEY from the environment

const SYSTEM_PROMPT = `You are the support assistant for Acme.
Answer only from the provided context. If the answer is not in the
context, say you don't know and offer to connect the customer to a human.
Keep answers under 120 words.`;

// Replace with your own retrieval: embed the question, search your
// indexed docs, return the top passages as plain text.
async function retrieveContext(question: string): Promise<string> {
  return "…relevant passages from your help centre…";
}

export async function POST(req: Request) {
  const { question, history = [] } = await req.json();
  const context = await retrieveContext(question);

  const stream = client.messages.stream({
    model: "claude-opus-5", // swap to claude-sonnet-5 or claude-haiku-4-5 for high-volume bots
    max_tokens: 1024,
    output_config: { effort: "low" }, // support answers don't need deep reasoning
    system: [
      // Stable prefix first so it can be cached across every request
      { type: "text", text: SYSTEM_PROMPT, cache_control: { type: "ephemeral" } },
    ],
    messages: [
      ...history,
      {
        role: "user",
        content: `Context:\n${context}\n\nCustomer question: ${question}`,
      },
    ],
  });

  // Pipe text deltas straight to the browser as they arrive
  const encoder = new TextEncoder();
  const body = new ReadableStream({
    async start(controller) {
      for await (const event of stream) {
        if (
          event.type === "content_block_delta" &&
          event.delta.type === "text_delta"
        ) {
          controller.enqueue(encoder.encode(event.delta.text));
        }
      }
      controller.close();
    },
  });

  return new Response(body, {
    headers: { "Content-Type": "text/plain; charset=utf-8" },
  });
}

What this gets you:

  • Grounded answers. The system prompt tells Claude to answer only from the retrieved context, which is what keeps a support bot from inventing refund policies.
  • Streaming. The first word appears in under a second instead of the customer staring at a spinner for the whole reply.
  • Caching. The cache_control block on the system prompt means repeated requests pay the cached rate for that prefix.

What it does not get you, and what you'll build next:

  1. Retrieval. retrieveContext is a stub. Real retrieval means crawling your site, splitting pages into chunks, embedding them, storing vectors, and re-indexing when content changes. This is most of the work.
  2. A chat widget. Something customers can open on any page, that keeps history, handles mobile, and matches your brand.
  3. Conversation storage and handoff. Logging what was asked, flagging what the bot couldn't answer, escalating to a human.
  4. Rate limiting and abuse protection. Your endpoint is public. Without limits, someone will run a script against it and spend your credits.
  5. Lead capture, analytics, and the Claude API error handling (429 rate limits, 529 overloaded) that production traffic will hit.

If you want to build all of that, go for it, it's a solid weekend-plus project. If you'd rather not, keep reading. (For what a finished support agent should do, see what an AI customer support agent is.)

API vs. no-code: which should you pick?

The Claude API is the right call when the chatbot is your product, or when you need behaviour nobody's builder offers: custom tools, multi-step agents, your own data pipeline.

For the common case, "answer customer questions from my website and docs", a no-code builder does the retrieval, widget, storage, and handoff for you, and the monthly fee is often less than the DIY API bill once you add hosting and a vector database.

Claude API (DIY)MagicChat (no-code)
Time to a live botDays to weeksUnder 10 minutes
Crawling and indexing your siteYou build itPaste a URL
Chat widgetYou build itOne script tag
Keeps up with content changesYou re-indexRefresh from the dashboard
Unanswered-question reportsYou build itBuilt in
Monthly cost at ~4,000 chatsAPI ~$36–90 + hosting + vector DB + your timeStarter plan, $59/mo
Custom tools, agents, your own pipelineFull controlNot the use case

The no-code route in three steps

With MagicChat the flow for the same support bot is:

  1. Add sources. Paste your website URL, upload PDFs, or drop in a YouTube link. It crawls, chunks, and indexes everything.
  2. Set the voice. Tone, fallback message, and when to hand off to a human.
  3. Embed. One tag on your site:
<script async
  src="https://www.magicchat.ai/widgets/loader.js"
  data-bot-id="YOUR_BOT_ID"
  data-color="#111827"
  data-position="right"></script>

The free plan gives you one chatbot, 100 messages a month, and up to 50 indexed pages, with no card. That's enough to test it against your real FAQs before paying anything.

Skip the retrieval pipeline. Turn your docs into a support bot in minutes.

Build your chatbot free

Already living in Claude? Manage the bot from there

If your team works inside Claude.ai, MagicChat ships as a Claude connector. Add it once and you can ask Claude things like "what did customers ask my support bot this week?", see the questions it couldn't answer, and train it from the chat. Setup takes under a minute: MagicChat in Claude.

FAQ

Is the Claude API free? No. There is no free tier, you prepay credits and pay per token. MagicChat's free plan is free, if you just want a working bot.

How do I get a Claude API key? Sign in at platform.claude.com, open API Keys, click Create Key, and copy it before closing the dialog. Add billing credits or requests will fail.

I lost my Claude API key. How do I copy it again? You can't. The Console only shows a key once. Delete the old one and create a new key.

Claude API vs. ChatGPT API, which is cheaper? It depends on the model tier you compare. Claude Haiku 4.5 and Sonnet 5 are competitive with OpenAI's mid-tier models on price. For a grounded support bot, the model matters less than retrieval quality and prompt caching, so benchmark on your own questions rather than on list price.

Why does Claude Code say "API Error"? Usually one of three things: an expired or wrong API key, a zero credit balance, or a 429 rate limit. Check the Console's Billing and API Keys pages first, then retry.

Can I use the Claude API in the browser? Technically, but don't. Your API key would be visible to anyone who opens dev tools. Call the API from a server route (like the example above) and have the browser talk to that.

Does MagicChat use the Claude API? MagicChat runs its own model stack tuned for grounded Q&A over your content, and plugs into Claude.ai as a connector so you can manage your bot from Claude. You don't need an Anthropic account or API key to use it.

Share: