Skip to content

Anthropic Messages

Point the Anthropic SDK or Claude Code at AnyRouter and send Messages requests to any model.

POSThttps://anyrouter.dev/api/v1/messages
import os
import anthropic

client = anthropic.Anthropic(
    base_url="https://anyrouter.dev/api",
    api_key=os.environ["ANYROUTER_API_KEY"],
)

msg = client.messages.create(
    model="anyrouter/auto",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hi"}],
)
print(msg.content[0].text)

What works

  • Streaming (SSE)
  • Tools / function calling
  • Extended thinking
  • Image input on vision models