Claude API Access: Complete Setup Guide for Sonnet, Opus & Haiku (2026)
Call Claude Sonnet, Opus, and Haiku from Python, Node.js, Cursor, LangChain, and any OpenAI-compatible tool — with a single API key.
Claude by Anthropic is one of the most capable AI model families available today. It excels at reasoning, coding, creative writing, long-document analysis, and following complex instructions. This guide shows you everything you need to access the Claude API — from setup to advanced features — with practical, copy-paste-ready code examples.
base_url="https://discount-token.com/v1" in the OpenAI SDK, and call models like claude-sonnet-4-20250514. No separate Anthropic account needed.
Claude Model Family Overview
Anthropic offers three Claude model tiers, each optimized for different use cases and budgets:
| Model | Best For | Context Window | Input / 1M | Output / 1M |
|---|---|---|---|---|
| Claude Sonnet | Coding, analysis, complex reasoning, production use | 200K tokens | $3.00 | $15.00 |
| Claude Opus | Research, deep reasoning, long documents | 200K tokens | $15.00 | $75.00 |
| Claude Haiku | Quick tasks, classification, budget applications | 200K tokens | $0.25 | $1.25 |
Which Claude Model Should You Use?
- Claude Sonnet is the recommended default for most developers. It offers the best balance of intelligence, speed, and cost. Use it for coding, content generation, data analysis, and production chatbots.
- Claude Haiku is ideal for high-volume tasks where cost matters most: classification, sentiment analysis, simple Q&A, and bulk content moderation.
- Claude Opus is reserved for the hardest problems: deep research, complex multi-step reasoning, and tasks where maximum accuracy justifies the premium cost.
What Makes Claude Special?
Claude stands out from other AI models in several ways:
1. Exceptional Instruction Following
Claude is widely regarded as the best model for following complex, multi-step instructions. If you give it a detailed system prompt with specific formatting requirements, it adheres more reliably than most alternatives.
2. 200K Token Context Window
Claude can process up to 200,000 tokens of context — equivalent to a 500-page book. This makes it ideal for analyzing long documents, codebases, or multi-turn conversations without losing track of earlier context.
3. Nuanced Writing Quality
Claude's writing style is natural and sophisticated. For content creation, marketing copy, and creative writing, many developers prefer Claude's output over GPT's more predictable patterns.
4. Strong Coding Performance
Claude Sonnet consistently ranks at or near the top of coding benchmarks. It excels at understanding entire codebases, generating complex functions, and debugging subtle issues.
Prerequisites
- A Token1.US account with a topped-up balance (start with $1+)
- Your API key from the dashboard
- The OpenAI SDK for your language (or any HTTP client)
Python Setup
Install the SDK
pip install openai
Basic API Call
from openai import OpenAI
client = OpenAI(
api_key="your-token1-us-key",
base_url="https://discount-token.com/v1"
)
response = client.chat.completions.create(
model="claude-sonnet-4-20250514",
messages=[
{"role": "system", "content": "You are a senior Python developer."},
{"role": "user", "content": "Explain decorators with a practical example."}
],
max_tokens=1024
)
print(response.choices[0].message.content)
print(f"\nTokens: {response.usage.total_tokens}")
Streaming Responses
stream = client.chat.completions.create(
model="claude-sonnet-4-20250514",
messages=[{"role": "user", "content": "Write a haiku about APIs."}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
Multi-Turn Conversation
messages = [
{"role": "system", "content": "You are a helpful coding assistant."},
{"role": "user", "content": "What is a context manager in Python?"},
]
response = client.chat.completions.create(
model="claude-sonnet-4-20250514",
messages=messages
)
# Add Claude's response to history
messages.append({"role": "assistant", "content": response.choices[0].message.content})
# Ask a follow-up question
messages.append({"role": "user", "content": "Show me an example."})
response2 = client.chat.completions.create(
model="claude-sonnet-4-20250514",
messages=messages
)
print(response2.choices[0].message.content)
Node.js Setup
npm install openai
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "your-token1-us-key",
baseURL: "https://discount-token.com/v1",
});
const response = await client.chat.completions.create({
model: "claude-sonnet-4-20250514",
messages: [{ role: "user", content: "Hello, Claude!" }],
});
console.log(response.choices[0].message.content);
Using Claude API with Popular Tools
Cursor IDE
Open Cursor Settings → Models → set OpenAI Base URL to https://discount-token.com/v1 and enter your Token1.US API key. Select claude-sonnet-4-20250514 as the model. Cursor will use Claude for code generation, refactoring, and chat.
LangChain
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="claude-sonnet-4-20250514",
api_key="your-token1-us-key",
base_url="https://discount-token.com/v1"
)
# Simple invocation
response = llm.invoke("What is 15 * 37?")
print(response.content)
# With prompt template
from langchain_core.prompts import ChatPromptTemplate
prompt = ChatPromptTemplate.from_messages([
("system", "You are a helpful assistant that translates English to French."),
("user", "Translate: {text}")
])
chain = prompt | llm
result = chain.invoke({"text": "Hello, how are you?"})
print(result.content)
Dify
Add a model provider in Dify settings with base URL https://discount-token.com/v1 and your Token1.US API key. You can then use Claude Sonnet in any Dify AI app.
curl
curl https://discount-token.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-token1-us-key" \
-d '{
"model": "claude-sonnet-4-20250514",
"messages": [{"role": "user", "content": "Hello!"}],
"max_tokens": 500
}'
Claude API Pricing Deep Dive
Understanding Claude's pricing helps you estimate costs accurately:
| Scenario | Input Tokens | Output Tokens | Cost (Sonnet) | Cost (Haiku) |
|---|---|---|---|---|
| Quick Q&A | 50 | 100 | $0.003 | $0.0001 |
| Code generation | 200 | 500 | $0.011 | $0.0007 |
| Document analysis (10 pages) | 5,000 | 1,000 | $0.030 | $0.0025 |
| Long conversation (50 turns) | 20,000 | 5,000 | $0.135 | $0.011 |
| Full book analysis | 100,000 | 2,000 | $0.330 | $0.0275 |
Use our interactive cost calculator for your own scenarios.
Troubleshooting Common Claude API Errors
| Error | Cause | Solution |
|---|---|---|
401 Unauthorized | Invalid or expired API key | Regenerate your key in the dashboard |
429 Too Many Requests | Rate limit exceeded | Reduce request frequency or contact support for higher limits |
insufficient_quota | Balance depleted | Top up your balance |
context_length_exceeded | Input exceeds 200K tokens | Trim or chunk your input |
| Timeout | Network issue or long response | Add retry logic with exponential backoff |
| Unexpected model name error | Wrong model ID | Use exact model names: claude-sonnet-4-20250514 |
Claude vs Other AI Models
How does Claude compare to GPT and DeepSeek? Here is a quick summary:
| Feature | Claude Sonnet | GPT-4o | DeepSeek-V3 |
|---|---|---|---|
| Coding quality | Excellent | Excellent | Very good |
| Writing quality | Best in class | Very good | Good |
| Context window | 200K | 128K | 64K |
| Price (input) | $3/1M | $2.50/1M | $0.14/1M |
| Instruction following | Best | Very good | Good |
| Vision support | Yes | Yes | No |
For a full comparison, see our detailed model comparison page.
Best Practices for Claude API
- Use system prompts effectively: Claude responds well to clear, detailed system prompts. Set expectations and formatting rules up front.
- Leverage the long context window: Claude's 200K token window means you can pass entire documents, codebases, or long conversation histories without summarization.
- Be specific: Claude follows instructions precisely. If you want a specific format (JSON, markdown, bullet points), say so explicitly.
- Use streaming for better UX: Claude's streaming is smooth and reduces perceived latency for end users.
- Choose the right tier: Use Haiku for simple tasks, Sonnet for most work, and Opus only when you need maximum reasoning power.
Frequently Asked Questions
How do I get a Claude API key?
Sign up at Token1.US, top up your balance, and generate an API key from the dashboard. The key works with the OpenAI SDK by setting base_url="https://discount-token.com/v1".
Is Claude API compatible with the OpenAI SDK?
Yes. Through Token1.US, Claude API is fully compatible with the OpenAI SDK. You only change the base_url and model name. All features (streaming, function calling) work the same way.
What Claude models are available?
Claude Sonnet ($3/1M input, $15/1M output), Claude Opus ($15/1M, $75/1M), and Claude Haiku ($0.25/1M, $1.25/1M). All accessible through Token1.US with a single API key.
How much does the Claude API cost?
Claude Sonnet costs $3/1M input and $15/1M output. Claude Haiku is the cheapest at $0.25/1M input and $1.25/1M output. A typical 200-token response from Sonnet costs about $0.003.
What is Claude best at?
Claude excels at long-context analysis (200K token window), nuanced writing, code generation, and complex reasoning. Claude Sonnet is particularly strong at coding tasks and following detailed instructions.
Can I use Claude API with Cursor or LangChain?
Yes. Set the OpenAI base URL to https://discount-token.com/v1 in Cursor settings, or use the base_url parameter in LangChain's ChatOpenAI. Claude works seamlessly with all OpenAI-compatible tools.
What is Claude's context window?
All Claude models support up to 200,000 tokens of context — equivalent to roughly 500 pages of text. This is larger than GPT-4o's 128K window and makes Claude ideal for processing long documents.
Does Claude support function calling?
Yes. Claude models support function calling (tool use) through the OpenAI-compatible API. Define your tools in the request, and Claude will decide when to call them.
Start Building with Claude
Get your API key and call Claude Sonnet in under 5 minutes.
Get Your API Key