There isn’t a model called “Claude Opus 4.5.” You likely mean Claude 3 Opus. Below is a quick guide to calling Anthropic’s Messages API with Claude 3 Opus.
Quick start
- Get an API key: create it in the Anthropic console.
- Endpoint: POST https://api.anthropic.com/v1/messages
- Required headers:
- x-api-key: YOUR_API_KEY
- anthropic-version: 2023-06-01
- content-type: application/json
- Choose a model:
- claude-3-opus-20240229 (or claude-3-opus-latest)
- Basic request fields:
- model: the model ID above
- messages: array of { role: "user" | "assistant", content: "…" } or content blocks
- max_tokens: upper bound for response tokens (e.g., 1024)
- temperature/top_p: sampling controls (optional)
- system: optional system prompt
- stream: true for server-sent events (optional)
cURL example
- Non-streaming:
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-3-opus-latest",
"max_tokens": 1024,
"messages": [
{"role":"user","content":"Explain transformers in 3 sentences."}
]
}'
- Streaming (SSE):
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-3-opus-latest",
"max_tokens": 1024,
"stream": true,
"messages": [
{"role":"user","content":"Stream a short poem about the ocean."}
]
}'
Python example
import os
import requests
API_KEY = os.environ["ANTHROPIC_API_KEY"]
url = "https://api.anthropic.com/v1/messages"
headers = {
"x-api-key": API_KEY,
"anthropic-version": "2023-06-01",
"content-type": "application/json",
}
data = {
"model": "claude-3-opus-latest",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "Write a haiku about debugging."}
],
"temperature": 0.7
}
resp = requests.post(url, headers=headers, json=data, timeout=60)
resp.raise_for_status()
out = resp.json()
# out["content"] is an array of blocks; extract text blocks
text = "".join(block.get("text","") for block in out.get("content", []) if block.get("type") == "text")
print(text)
Node.js example
import fetch from "node-fetch";
const API_KEY = process.env.ANTHROPIC_API_KEY;
const resp = await fetch("https://api.anthropic.com/v1/messages", {
method: "POST",
headers: {
"x-api-key": API_KEY,
"anthropic-version": "2023-06-01",
"content-type": "application/json",
},
body: JSON.stringify({
model: "claude-3-opus-latest",
max_tokens: 1024,
messages: [{ role: "user", content: "Give me a list of 5 creative icebreaker questions." }],
}),
});
const json = await resp.json();
const text = (json.content || [])
.filter(b => b.type === "text")
.map(b => b.text)
.join("");
console.log(text);
Tool use (function calling) overview
- Add a tools array describing callable functions:
- tools: [{ name, description, input_schema }]
- The model may respond with a tool_use block (name + input).
- You run the tool in your code, then send another request including a new user message with a tool_result block that references the tool_use_id and contains the tool’s output.
- Continue until the model returns a final text answer.
Multimodal (images) overview
- In a user message, content can be blocks like:
- { "type": "text", "text": "Describe this image." }
- { "type": "image", "source": { "type": "base64", "media_type": "image/png", "data": "..." } }
Best practices
- Use claude-3-opus-latest unless you need a pinned version.
- Set reasonable max_tokens to control cost.
- Prefer streaming for long outputs or interactive UIs.
- Implement retries with exponential backoff on 429/5xx.
- Keep conversation history concise; send only what the model needs.
If you actually meant Claude 3.5 Sonnet (often the strongest general model as of mid‑2024), swap the model to claude-3-5-sonnet-latest and the rest stays the same.
Anthropic lanserte Claude Opus 4.5 i slutten av november 2025 som en mer kapabel, mer effektiv modell i Opus-klassen rettet mot profesjonell programvareutvikling,