Anthropic Messages API
Anthropic-compatible messages endpoint. Easiest to integrate using the official Anthropic SDK.
Request
POST /v1/messages
Headers
x-api-key: pk_live_xxxxxxxxxxxxxxxx
anthropic-version: 2023-06-01
Content-Type: application/json
Body
Identical to the Anthropic Messages API, including messages, system, max_tokens, cache_control, and all other fields.
Prompt Caching
Tokensmart fully supports Anthropic prompt caching. Add cache_control: { type: "ephemeral" } to system or messages — subsequent cached tokens cost one-tenth of the normal rate.
See Understanding Cache Token Pricing for details.
Python SDK example
import anthropic
client = anthropic.Anthropic(
api_key="pk_live_xxxxxxxxxxxxxxxx",
base_url="https://api.tokensmart.ai",
)
message = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[
{"role": "user", "content": "Write a poem about cats"}
],
)
print(message.content[0].text)