Anthropic Messages
POST /v1/messages speaks the Anthropic Messages format, so the Anthropic SDKs and tools built on them — Claude Code among them — work with only the base URL and key changed. Every text model answers on it, not only Claude.
A request
The Anthropic SDK appends /v1/messages itself, so its base URL has no /v1:
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
baseURL: "https://api.cloakray.com",
apiKey: process.env.CLOAKRAY_API_KEY,
});
const message = await client.messages.create({
model: "claude-opus-4-8",
max_tokens: 1024,
system: "You are a concise assistant.",
messages: [{ role: "user", content: "Explain idempotency in one paragraph." }],
});
console.log(message.content[0].text);
import os
import anthropic
client = anthropic.Anthropic(base_url="https://api.cloakray.com", api_key=os.environ["CLOAKRAY_API_KEY"])
message = client.messages.create(
model="claude-opus-4-8",
max_tokens=1024,
messages=[{"role": "user", "content": "Explain idempotency in one paragraph."}],
)
print(message.content[0].text)
curl https://api.cloakray.com/v1/messages \
-H "x-api-key: $CLOAKRAY_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-opus-4-8",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Explain idempotency in one paragraph."}]
}'
The key goes in x-api-key or Authorization: Bearer; both work.
What carries over
The request and response follow the Anthropic format: max_tokens is required, system is a top-level field, and content is a list of typed blocks.
- Tools —
toolswithinput_schema,tool_useblocks in the reply andtool_resultblocks in your next turn. See tool calling. - Images and PDFs —
imageanddocumentblocks, as base64 or URL sources, on models that accept them. See vision and documents. - Extended thinking —
thinkingwithbudget_tokenson models that reason. See reasoning. - Prompt caching —
cache_controlon content blocks. See prompt caching. - Streaming —
stream: truereturns the Anthropic event stream (message_start,content_block_delta,message_stop). See streaming.
Usage comes back in Anthropic's fields: input_tokens, output_tokens, cache_read_input_tokens and cache_creation_input_tokens.
Non-Claude models
Any text model can be called here — gpt-5.5, gemini-3.6-flash, kimi-k2.6 — which is what lets Claude Code and other Anthropic-native tools use them. Features a model doesn't have, such as extended thinking on a model that doesn't reason, are refused or ignored rather than imitated.
Errors
Errors come back in Anthropic's shape, {"type": "error", "error": {"type": "...", "message": "..."}}, so the SDK raises its usual exceptions. The statuses mean the same as everywhere else — see errors.