Extended Thinking
Extended thinking lets the model reason deeply before answering. It is suitable for complex math, logic, and analysis tasks.
- Python
- JavaScript
- curl
import anthropic
client = anthropic.Anthropic(api_key="your-api-key", base_url="https://aisupermarket.work")
response = client.messages.create(
model="claude-opus-4-7",
max_tokens=16000,
thinking={
"type": "enabled",
"budget_tokens": 10000
},
messages=[{"role": "user", "content": "Prove that the square root of 2 is irrational"}]
)
for block in response.content:
if block.type == "thinking":
print("Thinking process:")
print(block.thinking)
elif block.type == "text":
print("Answer:")
print(block.text)
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({ apiKey: "your-api-key", baseURL: "https://aisupermarket.work" });
const response = await client.messages.create({
model: "claude-opus-4-7",
max_tokens: 16000,
thinking: { type: "enabled", budget_tokens: 10000 },
messages: [{ role: "user", content: "Prove that the square root of 2 is irrational" }],
});
for (const block of response.content) {
if (block.type === "thinking") {
console.log("Thinking process:");
console.log(block.thinking);
} else if (block.type === "text") {
console.log("Answer:");
console.log(block.text);
}
}
curl https://aisupermarket.work/v1/messages \
-H "x-api-key: your-api-key" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-opus-4-7",
"max_tokens": 16000,
"thinking": {"type": "enabled", "budget_tokens": 10000},
"messages": [{"role": "user", "content": "Prove that the square root of 2 is irrational"}]
}'
Streaming Extended Thinking
- Python
- JavaScript
- curl
import anthropic
client = anthropic.Anthropic(api_key="your-api-key", base_url="https://aisupermarket.work")
with client.messages.stream(
model="claude-opus-4-7",
max_tokens=16000,
thinking={"type": "enabled", "budget_tokens": 8000},
messages=[{"role": "user", "content": "Analyze the pros and cons of this business plan: ..."}]
) as stream:
for event in stream:
if hasattr(event, "type"):
if event.type == "content_block_start" and hasattr(event.content_block, "type"):
if event.content_block.type == "thinking":
print("\n[Thinking...]")
elif event.type == "content_block_delta":
if hasattr(event.delta, "thinking"):
print(event.delta.thinking, end="", flush=True)
elif hasattr(event.delta, "text"):
print(event.delta.text, end="", flush=True)
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({ apiKey: "your-api-key", baseURL: "https://aisupermarket.work" });
const stream = await client.messages.stream({
model: "claude-opus-4-7",
max_tokens: 16000,
thinking: { type: "enabled", budget_tokens: 8000 },
messages: [{ role: "user", content: "Analyze the pros and cons of this business plan: ..." }],
});
for await (const event of stream) {
if (event.type === "content_block_start" && event.content_block?.type === "thinking") {
console.log("\n[Thinking...]");
} else if (event.type === "content_block_delta") {
if (event.delta.type === "thinking_delta") {
process.stdout.write(event.delta.thinking);
} else if (event.delta.type === "text_delta") {
process.stdout.write(event.delta.text);
}
}
}
curl https://aisupermarket.work/v1/messages \
-H "x-api-key: your-api-key" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-opus-4-7",
"max_tokens": 16000,
"stream": true,
"thinking": {"type": "enabled", "budget_tokens": 8000},
"messages": [{"role": "user", "content": "Analyze the pros and cons of this business plan: ..."}]
}'
budget_tokens must be at least 1024, and max_tokens must be greater than budget_tokens.