Anthropic SDK Integration
Use the official Anthropic SDK with Thesean to call supported Ship models through the Anthropic-compatible Messages API.
Ensure you have your Thesean API key from the Thesean Dashboard before continuing.
Installation
Install the Anthropic SDK for your language:
uv add anthropic
Configuration
Configure the Anthropic SDK to use Thesean's base URL:
Use the bare origin without /v1. The Anthropic SDK appends /v1/messages to the configured
base URL.
Python
import anthropic
client = anthropic.Anthropic(
base_url="https://api.thesean.ai",
api_key="THESEAN_API_KEY"
)
Node.js / TypeScript
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
baseURL: "https://api.thesean.ai",
apiKey: process.env.THESEAN_API_KEY,
});
Basic Usage
Messages
Make a simple message request:
message = client.messages.create(
model="ship-like/claude-opus-4-8",
max_tokens=1024,
messages=[
{"role": "user", "content": "What is Olympus Mons?"}
]
)
print(message.content[0].text)
Ship Models
Use ship-like/claude-opus-4-8, ship-like/claude-sonnet-5, or
ship-like/claude-haiku-4-5 with the Anthropic-compatible Messages API. This example uses Opus:
message = client.messages.create(
model="ship-like/claude-opus-4-8",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello!"}]
)
See Available Models for details about the supported Ship models.
Advanced Features
Streaming Responses
stream = client.messages.create(
model="ship-like/claude-opus-4-8",
max_tokens=1024,
messages=[{"role": "user", "content": "Write a story about Mars"}],
stream=True
)
for chunk in stream:
if chunk.type == "content_block_delta" and chunk.delta.type == "text_delta":
print(chunk.delta.text, end="")
Prompt Caching
Use Anthropic's prompt caching to reduce costs and latency:
system_instruction = [
{
"type": "text",
"text": "You are a helpful assistant."
},
{
"type": "text",
"text": "<large context document here>",
"cache_control": {"type": "ephemeral"}
}
]
# First request - creates cache
message1 = client.messages.create(
model="ship-like/claude-opus-4-8",
max_tokens=100,
system=system_instruction,
messages=[{"role": "user", "content": "Question 1"}]
)
# Second request - uses cache
message2 = client.messages.create(
model="ship-like/claude-opus-4-8",
max_tokens=100,
system=system_instruction, # Must be identical
messages=[{"role": "user", "content": "Question 2"}]
)
Tool Use
response = client.messages.create(
model="ship-like/claude-opus-4-8",
max_tokens=1024,
tools=[
{
"name": "get_weather",
"description": "Get the current weather in a location",
"input_schema": {
"type": "object",
"properties": {
"location": {"type": "string"}
}
}
}
],
messages=[
{"role": "user", "content": "What's the weather in San Francisco?"}
]
)
for item in response.content:
if item.type == "tool_use":
print(f"Tool: {item.name}")
print(f"Args: {item.input}")
Error Handling
import anthropic
try:
message = client.messages.create(
model="ship-like/claude-opus-4-8",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello!"}]
)
except anthropic.AuthenticationError:
print("Invalid API key")
except anthropic.RateLimitError:
print("Rate limit exceeded")
except anthropic.APIError as e:
print(f"API error: {e}")