Integrate Claude directly into your applications, scripts, and services using the Anthropic API — with streaming, tool use, vision, and prompt caching.
The Claude API (formerly Anthropic API) gives you direct programmatic access to Claude models. You send messages, Claude responds — with full control over model selection, system prompts, temperature, streaming, tool definitions, and vision inputs. It's the foundation for every Claude-powered product.
The official Python and TypeScript SDKs make integration simple: pip install anthropic and you're one function call away from a production-grade AI response. All models support streaming, multi-turn conversations, tool use, image inputs, and prompt caching for 90% cost reduction on repeated context.
The simplest possible integration — send a message, get a response. The starting point for any Claude-powered feature.
import anthropic client = anthropic.Anthropic() message = client.messages.create( model="claude-sonnet-4-6", max_tokens=1024, messages=[ {"role": "user", "content": "Explain JWT authentication"} ] ) print(message.content[0].text)
Stream Claude's output token-by-token for a responsive chat feel — essential for user-facing apps where latency matters.
with client.messages.stream( model="claude-sonnet-4-6", max_tokens=1024, messages=[{"role": "user", "content": prompt}] ) as stream: for text in stream.text_stream: print(text, end="", flush=True)
Define tools and Claude decides when to call them — enabling AI-driven workflows that interact with databases, APIs, and external systems.
tools = [{
"name": "get_weather",
"description": "Get current weather for a city",
"input_schema": {
"type": "object",
"properties": {
"city": {"type": "string"}
},
"required": ["city"]
}
}]
response = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
tools=tools,
messages=[{"role": "user",
"content": "What's the weather in Paris?"}]
)
Pass images directly to Claude via base64 or URL. Ideal for OCR, UI feedback analysis, chart interpretation, and multimodal apps.
message = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[{
"role": "user",
"content": [
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/png",
"data": image_data
}
},
{"type": "text",
"text": "Describe this UI and identify issues"}
]
}]
)
Mark large, repeated context (system prompts, documents, examples) as cacheable. Pay full price once, then 10% on every subsequent call that reuses it.
response = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
system=[{
"type": "text",
"text": large_system_prompt, # 10K+ tokens
"cache_control": {"type": "ephemeral"}
}],
messages=[{
"role": "user",
"content": user_question
}]
)
# cache_read_input_tokens → billed at 10% of normal
max_tokens explicitly to avoid unexpected costs. Use ANTHROPIC_API_KEY env var — never hardcode your key.