Skip to content

Quick Reference: API Commands ​

Updated: 2026-05-26

Base URL and Headers ​

ItemValue
Base URLhttps://api.anthropic.com/v1
API Key Headerx-api-key: $ANTHROPIC_API_KEY
Version Headeranthropic-version: 2023-06-01
Content Typeapplication/json

Core Endpoints ​

EndpointMethodPurpose
/messagesPOSTSend a message to Claude
/messages/count_tokensPOSTCount tokens for a message
/modelsGETList available models
/beta/skillsPOSTCreate a skill
/beta/skills/versionsPOSTCreate a skill version
/beta/filesGETList files
/beta/filesPOSTUpload a file

Key Parameters ​

ParameterTypeRequiredDefaultDescription
modelstringYes-Model ID (e.g., claude-sonnet-4-6)
max_tokensintegerYes-Maximum tokens in response
messagesarrayYes-Conversation messages
systemstringNo-System prompt
temperaturefloatNo1.0Sampling temperature (0-1)
top_pfloatNo-Nucleus sampling threshold
streambooleanNofalseEnable streaming
toolsarrayNo-Tool definitions
tool_choiceobjectNoautoHow to select tools
stop_sequencesarrayNo-Custom stop sequences
metadataobjectNo-Request metadata

cURL Template ​

bash
curl https://api.anthropic.com/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-4-6",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "..."}]
  }'

Python SDK Template ​

python
from anthropic import Anthropic

client = Anthropic(api_key="sk-ant-...")

response = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[{"role": "user", "content": "..."}]
)

print(response.content[0].text)

Gotchas ​

IssueFix
401 UnauthorizedCheck API key format: must start with sk-ant-
max_tokens missingRequired parameter, not optional
Tool schema invalidMust be valid JSON Schema with type: "object"
Stream parsingParse data: prefix from SSE lines
Image formatUse base64 with media_type (image/jpeg, image/png, etc.)
System prompt placementsystem is a top-level field, not in messages