Anthropic Python SDK with MagmaRouter

The Anthropic Python SDK posts to /v1/messages under a configurable base URL. Point it at MagmaRouter and pass your key as the bearer auth token.
- Base URL
- https://api.magmarouter.com
- API key
- Get one, starts sk-mr-
- Example model
- glm-5.3-xploded
base_url and auth_token
The SDK default base URL is https://api.anthropic.com and it appends /v1/messages, so set base_url to https://api.magmarouter.com with no path. Pass the key as auth_token (sent as Authorization: Bearer), not api_key.
Python
# pip install anthropic from anthropic import Anthropic client = Anthropic( base_url="https://api.magmarouter.com", auth_token="sk-mr-...", ) msg = client.messages.create( model="glm-5.3-xploded", max_tokens=1024, messages=[{"role": "user", "content": "Hello"}], ) print(msg.content[0].text)
One endpoint gap messages.count_tokens calls /v1/messages/count_tokens, which MagmaRouter does not implement. Avoid that helper; ordinary messages.create works.