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.

By Token1.US Team Updated July 20, 2026 10 min read

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.

Quick answer: To use the Claude API, sign up at Token1.US, get an API key, set 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:

ModelBest ForContext WindowInput / 1MOutput / 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?

Pro tip: For a typical chat application, Claude Sonnet costs about $0.003 per user message (100 input + 200 output tokens). Claude Haiku costs about $0.0003 — 10x cheaper.

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

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:

ScenarioInput TokensOutput TokensCost (Sonnet)Cost (Haiku)
Quick Q&A50100$0.003$0.0001
Code generation200500$0.011$0.0007
Document analysis (10 pages)5,0001,000$0.030$0.0025
Long conversation (50 turns)20,0005,000$0.135$0.011
Full book analysis100,0002,000$0.330$0.0275

Use our interactive cost calculator for your own scenarios.

Troubleshooting Common Claude API Errors

ErrorCauseSolution
401 UnauthorizedInvalid or expired API keyRegenerate your key in the dashboard
429 Too Many RequestsRate limit exceededReduce request frequency or contact support for higher limits
insufficient_quotaBalance depletedTop up your balance
context_length_exceededInput exceeds 200K tokensTrim or chunk your input
TimeoutNetwork issue or long responseAdd retry logic with exponential backoff
Unexpected model name errorWrong model IDUse exact model names: claude-sonnet-4-20250514
Note: Request logs are retained for 7 days for debugging. Conversation content is not permanently stored. Do not send sensitive personal data if this is a concern for your use case.

Claude vs Other AI Models

How does Claude compare to GPT and DeepSeek? Here is a quick summary:

FeatureClaude SonnetGPT-4oDeepSeek-V3
Coding qualityExcellentExcellentVery good
Writing qualityBest in classVery goodGood
Context window200K128K64K
Price (input)$3/1M$2.50/1M$0.14/1M
Instruction followingBestVery goodGood
Vision supportYesYesNo

For a full comparison, see our detailed model comparison page.

Best Practices for Claude API

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

Related Guides