Messages API
Use the Anthropic SDK
The POST https://alprouter.com/api/v1/messages interface looks similar to the Anthropic Messages API. In the Claude model, requests are sent in the same form as before. The thought blocks, cache indicators, and tool calls remain unchanged.
Get started
Please change the default address of the Anthropic SDK to https://alprouter.com/api. The SDK is followed by /v1/messages.
import anthropic
client = anthropic.Anthropic(
base_url="https://alprouter.com/api",
api_key="alp-your-key",
)
with client.messages.stream(
model="claude-sonnet-5-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}],
) as stream:
for text in stream.text_stream:
print(text, end="")Model Name
I receive both the names used in “Anthropic” and the names used by AlpRouter. For example, claude-sonnet-5-5 and anthropic/claude-sonnet-5.5 are the same model.
| Anthropic name | AlpRouter name |
|---|---|
claude-fable-5-2 | anthropic/claude-fable-5.2 |
claude-fable-5-1 | anthropic/claude-fable-5.1 |
claude-opus-5-5 | anthropic/claude-opus-5.5 |
claude-sonnet-5-5 | anthropic/claude-sonnet-5.5 |
claude-haiku-5-5 | anthropic/claude-haiku-5.5 |
claude-opus-5 | anthropic/claude-opus-5 |
claude-sonnet-5 | anthropic/claude-sonnet-5 |
claude-opus-4-8 | anthropic/claude-opus-4.8 |
claude-opus-4-7 | anthropic/claude-opus-4.7 |
claude-opus-4-6 | anthropic/claude-opus-4.6 |
claude-opus-4-5 | anthropic/claude-opus-4.5 |
claude-sonnet-4-6 | anthropic/claude-sonnet-4.6 |
claude-haiku-4-5 | anthropic/claude-haiku-4.5 |
This address only accepts messages from the Claude model. For other models, please send the messages to /chat/completions.
Items to be received
| Classification | Item |
|---|---|
| Just pass it along as it is. | messages, system, max_tokens, tools, tool_choice, thinking, output_config, stop_sequences, temperature, top_p, top_k, metadata |
| Blocks | Text, Image, Document (PDF), Tool Usage, Tool Results, Thinking, and Cache Control Indicators |
| None | Like web searching, there are tools that allow the server to perform certain tasks on its own’s behalf (web_search, web_fetch, code_execution). We’ll inform you about the 400 error. |
| Remove and send it away. | Items whose prices vary, such as service_tier, speed, and fallbacks. In Bedrock connection, the Bedrock rejects certain options, and the beta values are also excluded. |
If there are any items that were removed from the list, please write the names of those items in the response header x-alprouter-dropped. If there is no header, it means that the item was sent as it was.
Usage and Fees
- The response for
usagelooks like that of Anthropic. The fee is calculated based on the price of Model Screen. - The tokens used in the cache are calculated based on the cost of storing them for 5 minutes. For tokens that last for 1 hour, the cost is twice the input price.
- The value of the response header
request-idcan be viewed fromGET https://alprouter.com/api/v1/generation?id=.
Counting tokens
Please inform POST https://alprouter.com/api/v1/messages/count_tokens of the number of tokens to be sent before sending it out. There is no charge for this service. For models that are counted by the supplier, the returned value will be an accurate figure. For models that aren’t counted by the supplier, the returned value will be slightly higher than the actual number.
Restrictions
- You can send up to 400KB of text, 20 images, or 5 documents.
- Please return the error to the form like in “Anthropic” (
type: error). - Even if the connection is terminated during the process, AlpRouter will still receive responses from Anthropic or Amazon Bedrock until the end. The actual usage is then calculated based on those responses. If you want to specify a maximum number of tokens, please enter that number in the “max_tokens” field.