import anthropicclient = anthropic.Anthropic( api_key="your-ToAPIs-key", base_url="https://toapis.com")message = client.messages.create( model="claude-sonnet-4-6", max_tokens=1024, messages=[ {"role": "user", "content": "Hello, tell me about yourself"} ])print(message.content[0].text)
import anthropicclient = anthropic.Anthropic( api_key="your-ToAPIs-key", base_url="https://toapis.com")message = client.messages.create( model="claude-sonnet-4-6", max_tokens=1024, system="You are a professional coding assistant specializing in Python and Go.", messages=[ {"role": "user", "content": "Write a quicksort in Python"} ])print(message.content[0].text)
import anthropicclient = anthropic.Anthropic( api_key="your-ToAPIs-key", base_url="https://toapis.com")with client.messages.stream( model="claude-sonnet-4-6", max_tokens=1024, messages=[ {"role": "user", "content": "Explain what recursion is"} ]) as stream: for text in stream.text_stream: print(text, end="", flush=True)
import Anthropic from "@anthropic-ai/sdk";const client = new Anthropic({ apiKey: "your-ToAPIs-key", baseURL: "https://toapis.com",});const message = await client.messages.create({ model: "claude-sonnet-4-6", max_tokens: 1024, messages: [{ role: "user", content: "Hello, tell me about yourself" }],});console.log(message.content[0].text);
import Anthropic from "@anthropic-ai/sdk";const client = new Anthropic({ apiKey: "your-ToAPIs-key", baseURL: "https://toapis.com",});const stream = await client.messages.stream({ model: "claude-sonnet-4-6", max_tokens: 1024, messages: [{ role: "user", content: "Explain what recursion is" }],});for await (const chunk of stream) { if ( chunk.type === "content_block_delta" && chunk.delta.type === "text_delta" ) { process.stdout.write(chunk.delta.text); }}
{ "id": "msg_01XFDUDYJgAACzvnptvVoYEL", "type": "message", "role": "assistant", "content": [ { "type": "text", "text": "Hello! I'm Claude, an AI assistant made by Anthropic. I can help with questions, analysis, coding, writing, and more. How can I help you today?" } ], "model": "claude-sonnet-4-6", "stop_reason": "end_turn", "usage": { "input_tokens": 12, "output_tokens": 35 }}
import anthropicclient = anthropic.Anthropic( api_key="your-ToAPIs-key", base_url="https://toapis.com")message = client.messages.create( model="claude-sonnet-4-6", max_tokens=1024, messages=[ {"role": "user", "content": "Hello, tell me about yourself"} ])print(message.content[0].text)
import anthropicclient = anthropic.Anthropic( api_key="your-ToAPIs-key", base_url="https://toapis.com")message = client.messages.create( model="claude-sonnet-4-6", max_tokens=1024, system="You are a professional coding assistant specializing in Python and Go.", messages=[ {"role": "user", "content": "Write a quicksort in Python"} ])print(message.content[0].text)
import anthropicclient = anthropic.Anthropic( api_key="your-ToAPIs-key", base_url="https://toapis.com")with client.messages.stream( model="claude-sonnet-4-6", max_tokens=1024, messages=[ {"role": "user", "content": "Explain what recursion is"} ]) as stream: for text in stream.text_stream: print(text, end="", flush=True)
import Anthropic from "@anthropic-ai/sdk";const client = new Anthropic({ apiKey: "your-ToAPIs-key", baseURL: "https://toapis.com",});const message = await client.messages.create({ model: "claude-sonnet-4-6", max_tokens: 1024, messages: [{ role: "user", content: "Hello, tell me about yourself" }],});console.log(message.content[0].text);
import Anthropic from "@anthropic-ai/sdk";const client = new Anthropic({ apiKey: "your-ToAPIs-key", baseURL: "https://toapis.com",});const stream = await client.messages.stream({ model: "claude-sonnet-4-6", max_tokens: 1024, messages: [{ role: "user", content: "Explain what recursion is" }],});for await (const chunk of stream) { if ( chunk.type === "content_block_delta" && chunk.delta.type === "text_delta" ) { process.stdout.write(chunk.delta.text); }}
{ "id": "msg_01XFDUDYJgAACzvnptvVoYEL", "type": "message", "role": "assistant", "content": [ { "type": "text", "text": "Hello! I'm Claude, an AI assistant made by Anthropic. I can help with questions, analysis, coding, writing, and more. How can I help you today?" } ], "model": "claude-sonnet-4-6", "stop_reason": "end_turn", "usage": { "input_tokens": 12, "output_tokens": 35 }}
Note for users in mainland China: Please use https://toapis.cn as the API endpoint (Base URL). Replace https://toapis.com with https://toapis.cn in the examples in this document.
Native Anthropic Messages API format
Drop-in compatible with the official Anthropic SDK (Python / JavaScript) — just change base_url
Supports streaming (SSE)
Supports multi-turn conversations, system prompts, vision input, and tool use
If you are already using the OpenAI SDK, use the OpenAI-compatible endpoint instead.
If you are using the Anthropic SDK or Claude Code, this endpoint is recommended.
import anthropicclient = anthropic.Anthropic( api_key="your-ToAPIs-key", base_url="https://toapis.com")message = client.messages.create( model="claude-sonnet-4-6", max_tokens=1024, messages=[ {"role": "user", "content": "Hello, tell me about yourself"} ])print(message.content[0].text)
import anthropicclient = anthropic.Anthropic( api_key="your-ToAPIs-key", base_url="https://toapis.com")message = client.messages.create( model="claude-sonnet-4-6", max_tokens=1024, system="You are a professional coding assistant specializing in Python and Go.", messages=[ {"role": "user", "content": "Write a quicksort in Python"} ])print(message.content[0].text)
import anthropicclient = anthropic.Anthropic( api_key="your-ToAPIs-key", base_url="https://toapis.com")with client.messages.stream( model="claude-sonnet-4-6", max_tokens=1024, messages=[ {"role": "user", "content": "Explain what recursion is"} ]) as stream: for text in stream.text_stream: print(text, end="", flush=True)
import Anthropic from "@anthropic-ai/sdk";const client = new Anthropic({ apiKey: "your-ToAPIs-key", baseURL: "https://toapis.com",});const message = await client.messages.create({ model: "claude-sonnet-4-6", max_tokens: 1024, messages: [{ role: "user", content: "Hello, tell me about yourself" }],});console.log(message.content[0].text);
import Anthropic from "@anthropic-ai/sdk";const client = new Anthropic({ apiKey: "your-ToAPIs-key", baseURL: "https://toapis.com",});const stream = await client.messages.stream({ model: "claude-sonnet-4-6", max_tokens: 1024, messages: [{ role: "user", content: "Explain what recursion is" }],});for await (const chunk of stream) { if ( chunk.type === "content_block_delta" && chunk.delta.type === "text_delta" ) { process.stdout.write(chunk.delta.text); }}
{ "id": "msg_01XFDUDYJgAACzvnptvVoYEL", "type": "message", "role": "assistant", "content": [ { "type": "text", "text": "Hello! I'm Claude, an AI assistant made by Anthropic. I can help with questions, analysis, coding, writing, and more. How can I help you today?" } ], "model": "claude-sonnet-4-6", "stop_reason": "end_turn", "usage": { "input_tokens": 12, "output_tokens": 35 }}