How to use the Anthropic Messages API on TokenRex

Send Claude requests in Anthropic's native Messages format with the Anthropic SDK.

Point the Anthropic SDK at TokenRex

Use the Anthropic client with your TokenRex key and the TokenRex base URL. This format is for Claude models only.

Example

import anthropic

client = anthropic.Anthropic(api_key="YOUR_TOKENREX_KEY", base_url="https://tokenrex.ai/api/public")

msg = client.messages.create(
    model="claude-sonnet-5",
    max_tokens=512,
    messages=[{"role": "user", "content": "Hello"}],
)
print(msg.content[0].text)
Get API keyCost calculatorDocs

Questions

Do I need a separate key for each provider?
No. One TokenRex API key works for every enabled model; change only the model ID.

Related