Anthropic SDK
Call the Messages API with the official Anthropic SDK. Use the same code for Claude and other models.
Set baseURL (base_url in Python) to https://api.outerlane.app in the official Anthropic SDK.
const client = new Anthropic({
- apiKey: process.env.ANTHROPIC_API_KEY,
+ apiKey: process.env.OUTERLANE_API_KEY,
+ baseURL: "https://api.outerlane.app",
});Use the base URL without /v1
The SDK appends /v1/messages. Including /v1 in the base URL sends requests to /v1/v1/messages, which returns 404.
Configure the client
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
apiKey: process.env.OUTERLANE_API_KEY,
baseURL: "https://api.outerlane.app",
});Send a message
max_tokens is required.
const message = await client.messages.create({
model: "anthropic/claude-sonnet-5-5",
max_tokens: 1024,
system: "Give accurate, concise answers.",
messages: [{ role: "user", content: "Why does idempotency matter in REST APIs?" }],
});
console.log(message.content);Reasoning effort and structured outputs
Set reasoning effort with output_config.effort. The API accepts thinking without changing behavior. To request output that follows a JSON Schema, use output_config.format.
const message = await client.messages.create({
model: "anthropic/claude-sonnet-5-5",
max_tokens: 2048,
output_config: {
effort: "high",
format: {
type: "json_schema",
schema: {
type: "object",
properties: { summary: { type: "string" } },
required: ["summary"],
additionalProperties: false,
},
},
},
messages: [{ role: "user", content: "Summarize common mistakes in binary search." }],
});Streaming and tool calling
const stream = client.messages.stream({
model: "anthropic/claude-sonnet-5-5",
max_tokens: 1024,
tools: [
{
name: "get_weather",
description: "Look up the current weather in a city.",
input_schema: {
type: "object",
properties: { city: { type: "string" } },
required: ["city"],
},
},
],
messages: [{ role: "user", content: "What's the weather in Seoul?" }],
});
for await (const event of stream) {
if (event.type === "content_block_delta" && event.delta.type === "text_delta") {
process.stdout.write(event.delta.text);
}
}Notes
- Use function tools with
nameandinput_schema. See Tool calling for the complete flow. - Send images as regular
usermessage blocks. PDF and document blocks and images insidetool_resultare unsupported. - See Anthropic Messages for request and response fields.