Anthropic

Claude API (Anthropic)

Send messages to Claude, stream, use tools, read images and PDFs, cache prompts, upload files and run batches: ready-to-send requests.

AI & machine learningGuided#claude#llm#anthropic#chat#tool-use#vision

Fork copies the collection into your workspace, without the publisher's secrets, so you can add your own key and send requests. Star saves it to your starred APIs (Account › Marketplace) and helps others find it.

Overview

The Claude API gives your application the same Claude models people use in the Claude apps: chat and writing, reasoning, coding, document and image understanding, structured data extraction and agents that call your own tools. Everything runs through one main endpoint, POST /v1/messages, plus supporting endpoints for models, token counting, files and batches. This collection walks you through all of them with requests you can send as they are.

Get an API key

  1. Sign in to the Claude Console at platform.claude.com (create an organisation if asked).
  2. Add billing or credits under Settings > Billing: requests fail with a billing error until there is a payment method or credit balance.
  3. Open Settings > API keys and choose Create key. Copy it immediately; it starts with sk-ant- and is shown only once.
  4. In this collection, paste it into the apiKey variable (it is marked secret, so it is never shown or shared when you fork or publish).

Authentication and headers

Every request carries your key in the x-api-key header (this collection sets it for you) and the API version in anthropic-version. This collection uses version 2026-10-21; on it, temperature, top_p and top_k are rejected, so leave them out. Beta features add an anthropic-beta header with the feature's name. Requests with a body use content-type: application/json.

Base URL: https://api.anthropic.com.

Models

The model variable defaults to claude-opus-5-5, Anthropic's current default model. claude-sonnet-5-5 balances speed and capability for everyday work, claude-haiku-5-5 is the fastest and lowest-cost choice for simple, high-volume tasks, and claude-fable-5-2 is the most capable model for the hardest reasoning. Use List models to see exactly which IDs your key can use, with each model's context window and output limit.

How to use this collection

  • Run 1. Start here: list models, send a first message, count tokens.
  • 2. Conversations covers system prompts, chat history, streaming, thinking and effort, and JSON output that matches a schema.
  • 3. Tool use is a two-step round trip: Claude asks for a tool, you return the result.
  • 4. Images and documents, 5. Prompt caching, 6. Files and 7. Message Batches cover the rest. Upload and batch requests save the IDs they return into variables, so the follow-up requests work without copying anything.

Common errors

StatusTypeWhat to do
400invalid_request_errorCheck the body: required fields are model, max_tokens and messages; read the message field for the exact problem.
401authentication_errorThe API key is missing, wrong or revoked.
402billing_errorAdd a payment method or credits in the Console.
403permission_errorThe key is not allowed to use this model or feature.
404not_found_errorWrong path, or a model ID your organisation cannot use.
413request_too_largeThe request is over the size limit; send large files through the Files API.
429rate_limit_errorSlow down and retry after the number of seconds in the retry-after header.
500 / 529api_error / overloaded_errorTemporary; retry with exponential backoff.

Responses with stop_reason: "refusal" are an HTTP 200: check stop_reason before reading the answer.

Limits and pricing

Usage is billed per input and output token, with different rates per model; cached input is much cheaper and batches cost half. Rate limits depend on your usage tier and are shown in the Console and in response headers. See Pricing, Rate limits and the API reference.

Endpoints 27

1. Start here

  • GETList models/v1/modelsLists the models your API key can use, newest first. Each entry has the exact id to put in the model field, a display_name, the context window…
  • GETGet one model/v1/models/{{model}}Returns one model by its ID (here the {{model}} variable). Handy to confirm a model exists for your key and to read its context window and output limit before…
  • POSTSend your first message/v1/messagesThe core call. Every Claude request is POST /v1/messages with three required fields: model, max_tokens (the most tokens Claude may write; keep it generous,…
  • POSTCount tokens before sending/v1/messages/count_tokensCounts the input tokens a request would use without running it, with the same body shape as /v1/messages (model, system, messages, tools) minus max_tokens.…

2. Conversations

  • POSTSystem prompt: give Claude a role/v1/messagessystem sets instructions that apply to the whole conversation: a role, the audience, the tone, the output format, rules. It is a top-level field, not a…
  • POSTMulti-turn conversation/v1/messagesThe API is stateless: to continue a chat you send the whole history every time, alternating user and assistant turns, ending with the new user message. Append…
  • POSTStream the answer (SSE)/v1/messagesSet "stream": true to receive the answer as Server-Sent Events while it is written, instead of one JSON at the end. Use it for chat UIs and for long outputs…
  • POSTThinking and effort/v1/messagesCurrent Claude models think before answering when it helps (adaptive thinking). On Claude Opus 5.5 thinking is always on: you control how hard Claude works…
  • POSTStructured JSON output/v1/messagesAsk for JSON that matches a schema with output_config.format = {type: "json_schema", schema: {...}}. The text block then contains JSON that fits your schema,…

3. Tool use

  • POST1) Offer a tool/v1/messagesTools let Claude ask your code to do something (look up data, call another API). You describe each tool with a name, a description (say when to use it) and a…
  • POST2) Send the tool result back/v1/messagesContinue the conversation: repeat the history, add Claude's previous reply as the assistant turn (including its tool_use block, unchanged), then a user turn…
  • POSTWeb search (server tool)/v1/messagesServer tools run on Anthropic's side: you only declare them, and the results come back in the same response. With web search Claude searches the web and cites…

4. Images and documents

  • POSTImage from a URL/v1/messagesClaude can read images (photos, screenshots, charts, scanned documents). Put an image block before your question, with source.type: "url" for a public image…
  • POSTImage as base64/v1/messagesFor images you have locally, send the bytes as base64: source: {type: "base64", media_type: "image/png", data: "..."}. The data must be plain base64 with no…
  • POSTRead a PDF from a URL (with citations)/v1/messagesClaude reads PDFs page by page, including tables and charts. Add a document block with source.type: "url" (or base64, or file with a Files API ID). With…
  • POSTUse an uploaded file/v1/messagesReference a file you uploaded with the Files API (folder 6) instead of sending its bytes again: source: {type: "file", file_id: "{{fileId}}"}. Use a document…

5. Prompt caching

  • POSTCache a long system prompt/v1/messagesPrompt caching stores the stable start of a request (tools, then system, then earlier messages) so repeated requests read it from cache: faster and much…
  • POSTAutomatic caching (top-level)/v1/messagesThe simplest form: put cache_control at the top level of the request and the API places the cache marker on the last cacheable block for you. Good for…

6. Files

  • POSTUpload a file/v1/filesUploads a file once (PDF, plain text, images, and more) and returns a file_id to reference in later messages. Send it as multipart/form-data with one field…
  • GETList files/v1/filesLists the files in your workspace, newest first, with their IDs, names, types and sizes. Paginate with limit, after_id and before_id.
  • GETGet file details/v1/files/{{fileId}}Returns the metadata of one file ({{fileId}}): name, MIME type, size, creation time and whether it can be downloaded. Files you upload yourself are not…
  • DELETEDelete a file/v1/files/{{fileId}}Deletes a file permanently. Messages that already used it are not affected, but new requests referencing this file_id fail with 404. Delete files you no…

7. Message Batches

  • POSTCreate a batch/v1/messages/batchesMessage Batches run many independent requests asynchronously at half the price, usually finishing well within 24 hours. Each entry has your own custom_id and…
  • GETCheck a batch/v1/messages/batches/{{batchId}}Polls a batch: processing_status is in_progress, canceling or ended, and request_counts shows how many requests succeeded, errored, were canceled or expired.…
  • GETGet batch results/v1/messages/batches/{{batchId}}/resultsDownloads the results as JSON Lines: one line per request with its custom_id and a result whose type is succeeded (with the full message), errored, canceled…
  • GETList batches/v1/messages/batchesLists your recent batches with their status and counts, newest first. Paginate with limit, after_id and before_id.
  • POSTCancel a batch/v1/messages/batches/{{batchId}}/cancelStops a running batch. Requests already processing may still finish; the rest are marked canceled, and you are billed only for completed requests. The status…

API details

Base URL
https://api.anthropic.com
Authentication
An API key in the x-api-key header
Operations
27 operations on 27 pathsPOST 19GET 7DELETE 1
Main resources
1. Start here 42. Conversations 53. Tool use 34. Images and documents 45. Prompt caching 26. Files 47. Message Batches 5
Description format
Swastik Codes guided collection, API version checked against the docs on 2026-11-17

How to test the Claude API (Anthropic) in Swastik Codes

  1. Open the APISelect “Fork & run in Swastik Codes” on this page. Sign in or create a free account if asked.
  2. Fork it into your workspaceChoose a workspace. You get your own copy of the Claude API (Anthropic) collection, without the publisher's secrets.
  3. Add your credentialsThis API uses an API key in the x-api-key header. Add yours in the collection's variables or an environment; the requests already reference it.
  4. Send a requestPick an endpoint, for example “List models” (GET /v1/models), and press Send. Check the response, add tests and run the whole collection with the runner.

Frequently asked questions

What is the Claude API (Anthropic)?

Send messages to Claude, stream, use tools, read images and PDFs, cache prompts, upload files and run batches: ready-to-send requests. It is listed under AI & machine learning and has 27 endpoints.

Who publishes the Claude API (Anthropic)?

It is listed from Anthropic's public API description (an OpenAPI document), not published by Anthropic on Swastik Codes. Anyone who controls anthropic.com can claim the profile by adding a DNS TXT record.

What is the base URL of the Claude API (Anthropic)?

Requests go to https://api.anthropic.com. Endpoint paths are added to this base URL.

How do I authenticate with the Claude API (Anthropic)?

With an API key in the x-api-key header.

How many endpoints does the Claude API (Anthropic) have?

27 operations on 27 paths (19 POST, 7 GET, 1 DELETE). The largest groups are 1. Start here, 2. Conversations, 3. Tool use, 4. Images and documents.

Is forking the Claude API (Anthropic) free?

Yes. Forking copies the collection into your workspace for free. It has been starred 0 times and forked 0 times.

Suggest an API

Tell us which public API is missing. We check it, then add it here with its endpoints when it has an OpenAPI (Swagger) description.