
The Claude API lets developers use Anthropic's Claude models inside their own apps, websites and workflows. You can build chatbots, summarize documents, write and review code, extract data from files and run AI agents, all with the same models people use in the Claude app. If you have used the OpenAI API before, you will find it familiar, but there are some important differences.
In this guide I explain what the API is, how to get an API key, how a request works, which models to choose, what it costs, how streaming and tools work, how Claude Code fits in and what to do when the API has problems. I keep it simple enough for beginners, with tips that experienced developers will also find useful.
What Is the Claude API?
The API is Anthropic's official developer platform for its Claude models. You send text, images or documents to Claude over HTTPS and get a response back. It is billed per token, separate from any Claude chat subscription like Pro or Max.
Is the API you found official? Only the endpoints at api.anthropic.com, the Claude Console, and Claude models on approved cloud platforms are official. Many third-party sites resell access to Claude through their own APIs. They may work, but you are trusting another company with your data and billing, so read their terms carefully.
You can also use Claude models through cloud providers: Amazon Bedrock, Google Cloud Vertex AI and Microsoft Foundry. These are useful if your company already uses one of those clouds and wants billing and security in one place.
How to Get an Anthropic API Key

Create a Claude Console account: sign up on Anthropic's developer console.
Add billing: buy credits or add a payment method. The API is pay-as-you-go.
Create an API key: in the Console, open API keys and create a new key. Copy it once and store it safely.
Set spend limits: add monthly limits so a bug cannot run up a huge bill.
Use environment variables: keep the key in a variable like ANTHROPIC_API_KEY, never in your code or Git repository.
Never put your API key in browser code or a public GitHub repo. Anyone who finds it can use your credits. If a key leaks, delete it in the Console right away and create a new one.
How a Request Works: The Messages Endpoint
The main endpoint is the Messages API, using the Anthropic format: POST https://api.anthropic.com/v1/messages. Every request needs a few things:
Authentication headers: your key in the x-api-key header, an anthropic-version header and a JSON content type. Note that Anthropic uses x-api-key, not the "Authorization: Bearer" header used by many other APIs.
Model: the model ID, for example claude-sonnet-5-5.
max_tokens: the maximum length of the response.
messages: a list of turns with a role (user or assistant) and content.
system (optional): instructions that set Claude's behavior for the whole conversation.
The response contains Claude's answer as content blocks, plus usage data showing how many input and output tokens you used. That usage number is what you pay for.
Anthropic offers official SDKs for Python and TypeScript, plus other languages. With the Python SDK, you install the anthropic package, create a client and call the messages create method with your model, max_tokens and messages. The SDK handles headers, retries and streaming for you, so most developers should use it instead of raw HTTP.
Test a Request With curl
Before writing any application code, many developers test the API from the terminal with curl. The request goes to the https URL for the Messages endpoint, https://api.anthropic.com/v1/messages, with three headers: x-api-key with your key, anthropic-version with the version date from the docs, and content-type set to application/json. The JSON body includes the model, max_tokens and a messages list with one user message, such as a request for a short poem.
If authentication works, you get a JSON response with Claude's reply and token usage. If you see a 401 error, your key is wrong or missing. A 400 error usually means a typo in the JSON body. Once curl works, move the same request into your code with the SDK.
From Dev to Deployment: A Simple Checklist
Dev keys and production keys: use separate API keys for your dev environment and your live app, so a test script cannot use up production credits.
Input validation: check user input length and type before sending it, and reject anything your app should not process.
Robust error handling: handle authentication errors, rate limits and timeouts with clear messages and automated retries.
Real-time feedback: stream responses so users see progress instantly.
Model choice per feature: use Opus where deep reasoning matters and Haiku where speed matters. The same code implements both by changing one model string.
Monitoring: track errors, latency and cost after deployment.
Following this list keeps your app's functionality stable as you add new capabilities, like tools or commands that let Claude act inside your product. Check the v1 endpoint docs whenever you upgrade, because new features often add optional fields to the same API endpoints.
Planning Your App Architecture
For a real application, think about where each component lives. A simple and safe architecture looks like this: your web or mobile interface talks to your own backend, and only the backend calls the Anthropic API endpoints. That keeps your key secret and lets you add logging, rate limits and error handling in one place.
For larger systems, add a queue for long jobs, a cache for repeated questions, and a database to store conversations if users need history. Good integration also means handling timeouts and partial streams gracefully, so a slow response does not freeze your user interface.
Anthropic Messages vs OpenAI Chat Completions
If you are moving from OpenAI, the biggest difference is the request format. OpenAI uses the Chat Completions endpoint, and Claude uses the Messages endpoint. The ideas are similar, but field names and the response shape differ. For example, Claude takes the system prompt as a separate field instead of a "system" message in the list.
Anthropic also provides an OpenAI SDK compatibility layer, so you can test Claude by changing the base URL and model in existing OpenAI-style code that calls v1 chat completions. It is handy for quick comparisons, but for full features like prompt caching and extended thinking, the native Messages API is the better choice.
Claude Models Available to Developers
The current Claude models on the API are:
Claude Fable 5.2 (claude-fable-5-2): Anthropic's most capable model, built for long-running agents and the hardest tasks.
Claude Opus 5.5 (claude-opus-5-5): a powerful daily driver for agentic coding and enterprise work.
Claude Sonnet 5.5 (claude-sonnet-5-5): high performance for coding and agents at a lower price.
Claude Haiku 5.5 (claude-haiku-5-5): the fastest and most cost-efficient model for simple, high-volume tasks.
Older models remain available for a while for existing apps, but new projects should start with the latest ones. A good rule: start with Sonnet, drop to Haiku for simple jobs, and move up to Opus or Fable only where quality really needs it.
Claude API Pricing

The API is billed per million tokens. From the official Claude pricing page:
Haiku 5.5: $0.10 input and $0.50 output per million tokens for prompts up to 100K tokens.
Sonnet 5.5: $2 input and $10 output.
Opus 5.5: $4 input and $20 output.
Fable 5.2: $8 input and $40 output.
Batch processing saves 50% for jobs that do not need instant answers, and prompt caching makes repeated context much cheaper. Web search costs extra per 1,000 searches, and code execution includes free daily hours. For a deeper breakdown, read our Claude pricing guide.
Can you try the Claude models before topping up? You can test them in the Claude app on a free plan. Max and Ultra subscribers also get monthly API credits to build on the Claude Platform.
Streaming, Tools and Extended Thinking
The API supports the features modern apps need:
Streaming: set stream to true and Claude sends the answer piece by piece using server-sent events. Users see text appear right away instead of waiting for the full response.
Tool use: describe functions your app can run, like "get_weather" or "search_orders", and Claude decides when to call them with the right arguments.
Extended thinking: let Claude think step by step before answering hard questions, with a thinking budget you control.
Vision and PDFs: send images and documents for Claude to analyze.
Prompt caching: mark long, repeated parts of your prompt for caching to save money and time.
Batches: submit many requests at once and get results later at half the price.
Claude Code and the API
Claude Code is Anthropic's coding agent for the terminal, IDE and desktop. You can install it, open a project folder or clone a Git repo (for example with git clone), and ask Claude to read the code, plan changes, edit files and run tests. It is included in paid Claude plans, and it can also run on API credits through a Console account for teams that prefer pay-as-you-go billing.
For developers building their own agents, Anthropic offers the Agent SDK, which uses the same building blocks as Claude Code: tools, file access, memory and long-running workflows. Many teams connect Claude to their own tools with MCP, the Model Context Protocol.
Incidents: Is Claude Down Right Now?
Like any cloud service, the API sometimes has incidents, such as elevated errors on claude.ai, the API and Claude Code at the same time. When your app starts failing, check Anthropic's official status page first. It shows current incidents and history for each service.
Build a simple incident playbook for your app:
Retry with backoff: retry failed requests after a short, growing delay. The official SDKs do this for common errors.
Handle rate limits: a 429 error means you are sending too many requests. Slow down or request higher limits.
Handle overload: during busy periods, the API may return overloaded errors. Queue work and try again.
Have a fallback: switch to a smaller Claude model or show a friendly message while the service recovers.
Watch your credits: running out of credits looks like an outage to users. Set alerts before your balance is low.
Best Practices for Developers

Keep API keys on the server, never in the browser or mobile app.
Choose the smallest model that does the job well.
Write clear system prompts and give examples of good output.
Keep prompts focused, because every token costs money.
Use streaming for long answers so users are not left waiting.
Log usage per feature so you know where your money goes.
Make sure the organization, not one person, owns the Console account and billing, so the project does not stop if someone leaves.
API Access vs a Claude Subscription
The API and the Claude app are separate products. A Pro, Max or Ultra subscription lets you chat with Claude and use Claude Code under your plan's limits. The API is for building your own software and is billed per token. If you only want to use Claude yourself for writing, research or coding, a subscription is usually cheaper and simpler.
For personal use on a budget, GroupBuyServices offers shared access to Claude and ChatGPT in our bundles, which you can compare on our plans page. To be clear, this is chat access through a shared account, not API access, so it cannot be used to build apps. Do not paste private code or client data into a shared account. Our plans are non-refundable, so start with the 1 Day Trial if you want to test. You may also like our comparison of Claude vs ChatGPT.
Frequently Asked Questions
Is the API free to use?
No. The API is pay-as-you-go per token. You can try Claude for free in the Claude app, and Max and Ultra plans include monthly API credits.
How do I authenticate my requests?
Send your API key in the x-api-key header along with the anthropic-version header on every request.
Do extended thinking, tools and streaming work?
Yes. The Messages API supports streaming, tool use, extended thinking, vision, PDFs, prompt caching and batches.
Can I use Claude models on Google Cloud?
Yes. Claude models are available on Google Cloud Vertex AI, as well as Amazon Bedrock and Microsoft Foundry.
Which Claude model should I start with?
Start with Sonnet 5.5 for a good balance of quality and cost, use Haiku 5.5 for simple tasks and Opus or Fable for the hardest work.
Final Thoughts
The API is a powerful and developer-friendly way to add Claude's intelligence to your own products. Create a Console account, protect your API key, start with Sonnet, use streaming and caching, and plan for incidents with retries and fallbacks. Whether you build a simple chatbot or a full coding agent, the same Messages API is the foundation.