Developer Docs › Claude Messages (Anthropic native)

Claude Messages (Anthropic native)

Call Claude with Anthropic's official Messages API, with full native support for extended thinking, prompt caching, tool use and more.

Endpoint

POST https://api.onefast.ai/v1/messages
x-api-key: sk-xxx
anthropic-version: 2023-06-01
Content-Type: application/json

The native endpoint is the recommended way to call Claude: requests and responses are identical to Anthropic's official API, so you get extended thinking, prompt caching, anthropic-beta and every other capability. With the official Anthropic SDKs you only change base_url.

Set the Anthropic SDK's base_url to the root URL https://api.onefast.ai — without /v1 (the SDK appends /v1/messages itself).

Basic request

cURL

curl https://api.onefast.ai/v1/messages \
  -H "x-api-key: $API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-6",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Hello, Claude"}]
  }'

Python

# pip install anthropic
import anthropic

client = anthropic.Anthropic(api_key="sk-xxx", base_url="https://api.onefast.ai")
message = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello, Claude"}],
)
print(message.content[0].text)

Node.js

// npm install @anthropic-ai/sdk
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({ apiKey: "sk-xxx", baseURL: "https://api.onefast.ai" });
const message = await client.messages.create({
  model: "claude-sonnet-4-6",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Hello, Claude" }],
});
console.log(message.content[0].text);

Example response:

{
  "id": "msg_...",
  "type": "message",
  "role": "assistant",
  "model": "claude-sonnet-4-6",
  "content": [{ "type": "text", "text": "Hello! How can I help you today?" }],
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 10,
    "output_tokens": 12,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0
  }
}

Headers

Header Description
x-api-key Your key. Authorization: Bearer sk-xxx also works
anthropic-version Protocol version, always 2023-06-01
anthropic-beta Optional. Enables beta features (such as 1M context); passed through unchanged

Streaming

Python

with client.messages.stream(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Write a short poem about autumn"}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)

The event sequence matches the official API: message_start → content_block_delta … → message_delta (with final usage) → message_stop.

Extended thinking

Python

message = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=16000,
    thinking={"type": "enabled", "budget_tokens": 8000},
    messages=[{"role": "user", "content": "Prove that the square root of 2 is irrational"}],
)
for block in message.content:
    print(block.type, ":", getattr(block, "thinking", None) or getattr(block, "text", ""))

Thinking tokens are billed as output tokens. See Tools & reasoning for more.

Counting tokens

Estimate input tokens before sending — not billed:

cURL

curl https://api.onefast.ai/v1/messages/count_tokens \
  -H "x-api-key: $API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{"model": "claude-sonnet-4-6", "messages": [{"role": "user", "content": "Hello, Claude"}]}'

Returns {"input_tokens": 9}. This is a local estimate by the gateway and may differ slightly from actual billing.

Calling non-Claude models through this endpoint

/v1/messages can also call GPT, DeepSeek and other OpenAI-protocol models; the gateway converts the format automatically, which makes switching models in tools like Claude Code easy. Native Gemini routes can't be called through this endpoint yet.