TokenReply

Loading…

Reload

Anthropic SDK with TokenReply

Construct the Anthropic client with the TokenReply gateway origin as base_url, a TokenReply key, and an exact Claude-compatible catalog model ID.

Last checked · Sources: Official client documentation and TokenReply route review

Category
SDK
API format
Anthropic Messages
Endpoint setting
Gateway origin; SDK appends /v1/messages

Setup

  1. Install a current official Anthropic SDK.
  2. Set base_url to the TokenReply origin without adding /v1; the SDK appends /v1/messages.
  3. Use a TokenReply API key and an exact model ID that supports the Anthropic endpoint.
  4. Start with a small non-streaming Messages request and explicit max_tokens.
Example
from anthropic import Anthropic

client = Anthropic(
    api_key="sk-your-token-here",
    base_url="https://api.tokenreply.com",
)

message = client.messages.create(
    model="YOUR_MODEL_ID",
    max_tokens=256,
    messages=[{"role": "user", "content": "Say hello."}],
)

print(message.content[0].text)

How to verify

  • The final request path is /v1/messages, not /v1/v1/messages.
  • The response contains an Anthropic content block with text.
  • Streaming, tools, prompt caching, and beta headers are tested separately when required.

Limitations

  • Only use model routes that advertise Anthropic-compatible Messages support.
  • Provider-specific beta features and headers are not guaranteed across every routed model.
  • The Anthropic SDK base URL convention differs from OpenAI SDK base URLs that normally end in /v1.

Troubleshooting

SymptomWhat it usually meansWhat to do
The request path contains /v1/v1/messagesbase_url already contains /v1 and the SDK appended /v1/messages.Set the Anthropic client base_url to the gateway origin only. TokenReply currently tolerates the repeated prefix, but other services and proxies may not.
A catalog model works through chat but not MessagesThe model route does not advertise the Anthropic endpoint type.Choose a route that supports Anthropic Messages or use its advertised OpenAI endpoint.

Resources

Ready to try it?