Anthropic Messages
Endpoint
Section titled “Endpoint”POST /anthropic/v1/messagesFully compatible with the Anthropic Messages API.
SDK base URL
Section titled “SDK base URL”When using the Anthropic SDK, set the base URL to:
https://api.cheapestinference.com/anthropicThe SDK appends /v1/messages automatically.
Request body
Section titled “Request body”| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model ID (e.g. claude-sonnet-4-20250514) |
max_tokens | integer | Yes | Maximum tokens to generate |
messages | array | Yes | Array of message objects |
stream | boolean | No | Enable SSE streaming |
temperature | number | No | Sampling temperature (0–1) |
system | string | No | System prompt |
Example
Section titled “Example”curl https://api.cheapestinference.com/anthropic/v1/messages \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -H "anthropic-version: 2023-06-01" \ -d '{ "model": "claude-sonnet-4-20250514", "max_tokens": 1024, "messages": [ {"role": "user", "content": "Hello!"} ] }'Python
Section titled “Python”from anthropic import Anthropic
client = Anthropic( api_key="YOUR_API_KEY", base_url="https://api.cheapestinference.com/anthropic")
message = client.messages.create( model="claude-sonnet-4-20250514", max_tokens=1024, messages=[{"role": "user", "content": "Hello!"}])print(message.content[0].text)Node.js
Section titled “Node.js”import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({ apiKey: "YOUR_API_KEY", baseURL: "https://api.cheapestinference.com/anthropic",});
const message = await client.messages.create({ model: "claude-sonnet-4-20250514", max_tokens: 1024, messages: [{ role: "user", content: "Hello!" }],});console.log(message.content[0].text);Response
Section titled “Response”{ "id": "msg_abc123", "type": "message", "role": "assistant", "model": "claude-sonnet-4-20250514", "content": [ { "type": "text", "text": "Hello! How can I help you today?" } ], "stop_reason": "end_turn", "usage": { "input_tokens": 10, "output_tokens": 12 }}Non-Claude models
Section titled “Non-Claude models”You can also use non-Claude models through the Anthropic endpoint. The API translates the format automatically:
message = client.messages.create( model="gpt-4o-mini", max_tokens=1024, messages=[{"role": "user", "content": "Hello!"}])