The Claude API becomes remarkably easy to work with once you've made that very first call. From wiring up my own services as an indie developer, I've found the hard part isn't grasping the concepts — it's knowing the right order to get a minimal setup running. This guide lays out that path, from getting your API key to your first Python and TypeScript request, so you can reach a working call in five minutes without detours.
What is the Claude API?
The Claude API lets you integrate Claude's capabilities into your own applications. Through Anthropic's developer platform, you can programmatically access text generation, code generation, analysis, summarization, and more.
Getting Your API Key
- Visit console.anthropic.com
- Create an account or log in
- Navigate to the "API Keys" section and create a new key
- Save the key securely (it's only shown once)
# Set as environment variable
export ANTHROPIC_API_KEY="sk-ant-..."Python SDK
Installation
pip install anthropicYour First Request
import anthropic
client = anthropic.Anthropic()
message = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[
{"role": "user", "content": "Write a prime number checker in Python"}
]
)
print(message.content[0].text)Streaming Responses
For real-time output:
with client.messages.stream(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[
{"role": "user", "content": "Explain the basics of machine learning"}
]
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)TypeScript SDK
Installation
npm install @anthropic-ai/sdkYour First Request
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic();
const message = await client.messages.create({
model: "claude-sonnet-4-6",
max_tokens: 1024,
messages: [
{ role: "user", content: "Implement FizzBuzz in TypeScript" }
],
});
console.log(message.content[0].text);Key Parameters
| Parameter | Description | Example |
|---|---|---|
model | Model to use | claude-opus-4-6, claude-sonnet-4-6 |
max_tokens | Maximum output tokens | 1024, 4096 |
temperature | Randomness (0–1) | 0 = deterministic, 1 = creative |
system | System prompt | "You are a Python expert" |
stop_sequences | Stop strings | ["nn"] |
Using System Prompts
message = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
system="You are a senior software engineer. Always include code examples and comment on performance.",
messages=[
{"role": "user", "content": "What are effective caching strategies?"}
]
)Tool Use (Function Calling)
The Claude API supports calling external functions:
message = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
tools=[
{
"name": "get_weather",
"description": "Get weather for a given city",
"input_schema": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "City name (e.g., Tokyo)"
}
},
"required": ["city"]
}
}
],
messages=[
{"role": "user", "content": "What's the weather in Tokyo?"}
]
)Choosing the Right Model
| Model | Strengths | Best For |
|---|---|---|
| Claude Opus 4.6 | Highest capability, deep reasoning | Complex analysis, high-quality code |
| Claude Sonnet 4.6 | Balanced speed and quality | Everyday tasks, chatbots |
| Claude Haiku 4.5 | Fastest, lowest cost | High-volume processing, classification |
Next Steps
- Vision (Image Input) — Analyze and describe images via the API
- Advanced Tool Use — Automate complex multi-step workflows
- Batch Processing — Handle large volumes of requests efficiently
- MCP Integration — Connect services with Model Context Protocol
As an indie developer running the Dolice Labs sites, the thing that actually slowed down my first call wasn't auth — it was guessing the right model string. Run the official minimal sample untouched first, then immediately rewrite it into the smallest version of your own use case. That order is what gets you from zero to a working call in five minutes.