from anthropic import Anthropic
client = Anthropic(
base_url="https://api.routerhub.ai",
api_key="YOUR_API_KEY",
)
message = client.messages.create(
model="anthropic/claude-sonnet-4",
max_tokens=1024,
messages=[
{"role": "user", "content": "Hello, what can you do?"}
],
)
print(message.content[0].text)
Multi-Turn Conversation
curl https://api.routerhub.ai/v1/messages \
-H "x-api-key: $ROUTERHUB_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-sonnet-4",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "What is the capital of France?"},
{"role": "assistant", "content": "The capital of France is Paris."},
{"role": "user", "content": "What is its population?"}
]
}'
import requests
response = requests.post(
"https://api.routerhub.ai/v1/messages",
headers={
"x-api-key": "YOUR_API_KEY",
"anthropic-version": "2023-06-01",
"Content-Type": "application/json",
},
json={
"model": "anthropic/claude-sonnet-4",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "What is the capital of France?"},
{"role": "assistant", "content": "The capital of France is Paris."},
{"role": "user", "content": "What is its population?"},
],
},
)
print(response.json()["content"][0]["text"])
from anthropic import Anthropic
client = Anthropic(
base_url="https://api.routerhub.ai",
api_key="YOUR_API_KEY",
)
message = client.messages.create(
model="anthropic/claude-sonnet-4",
max_tokens=1024,
messages=[
{"role": "user", "content": "What is the capital of France?"},
{"role": "assistant", "content": "The capital of France is Paris."},
{"role": "user", "content": "What is its population?"},
],
)
print(message.content[0].text)
System Message
curl https://api.routerhub.ai/v1/messages \
-H "x-api-key: $ROUTERHUB_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-sonnet-4",
"max_tokens": 1024,
"system": "You are a helpful assistant that responds in haiku.",
"messages": [
{"role": "user", "content": "Tell me about the ocean."}
]
}'
import requests
response = requests.post(
"https://api.routerhub.ai/v1/messages",
headers={
"x-api-key": "YOUR_API_KEY",
"anthropic-version": "2023-06-01",
"Content-Type": "application/json",
},
json={
"model": "anthropic/claude-sonnet-4",
"max_tokens": 1024,
"system": "You are a helpful assistant that responds in haiku.",
"messages": [
{"role": "user", "content": "Tell me about the ocean."}
],
},
)
print(response.json()["content"][0]["text"])
from anthropic import Anthropic
client = Anthropic(
base_url="https://api.routerhub.ai",
api_key="YOUR_API_KEY",
)
message = client.messages.create(
model="anthropic/claude-sonnet-4",
max_tokens=1024,
system="You are a helpful assistant that responds in haiku.",
messages=[
{"role": "user", "content": "Tell me about the ocean."}
],
)
print(message.content[0].text)
Sample Response
{
"id": "msg_01XFDUDYJgAACzvnptvVoYEL",
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "Hello! I'm Claude, an AI assistant. I can help you with a wide range of tasks, including:\n\n- Answering questions and explaining concepts\n- Writing and editing text\n- Analyzing data and solving problems\n- Generating code and debugging\n- Brainstorming ideas\n\nHow can I help you today?"
}
],
"model": "anthropic/claude-sonnet-4",
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 12,
"output_tokens": 64,
"cache_creation_input_tokens": 0,
"cache_read_input_tokens": 0
}
}