Skip to main content
Myrouter provides API services compatible with the Anthropic SDK, making it easy to integrate into your existing applications. If you have already developed applications using the Anthropic SDK, you only need to replace the base URL and API Key with the Myrouter API address and API Key. Please refer to the integration guide below.

Supported Models

Currently, only the following models provide Anthropic SDK compatibility support:

Quick Start

1. Install the Anthropic SDK

pip install anthropic

2. Initialize the Client

The Anthropic SDK will attempt to retrieve the API Key and base URL from the environment variables ANTHROPIC_API_KEY and ANTHROPIC_BASE_URL respectively. You can also specify them through parameters when initializing the client.
  • Setting via environment variables
export ANTHROPIC_BASE_URL="https://api.myrouter.ai/anthropic"
export ANTHROPIC_API_KEY="<Myrouter API Key>"
  • Setting parameters when initializing the Anthropic client
import anthropic

client = anthropic.Anthropic(
    base_url="https://api.myrouter.ai/anthropic",
    api_key="<Myrouter API Key>",
    # Override headers
    default_headers={
        "Content-Type": "application/json",
        "Authorization": "Bearer <Myrouter API Key>",
    }
)

3. Call the API

import anthropic

# Initialize the client. If you have already set the API Key and base URL
# via the environment variables `ANTHROPIC_BASE_URL` and `ANTHROPIC_API_KEY`,
# you can omit the `api_key` and `base_url` parameters.
client = anthropic.Anthropic(
    base_url="https://api.myrouter.ai/anthropic",
    api_key="<Myrouter API Key>",
    # Override headers
    default_headers={
        "Content-Type": "application/json",
        "Authorization": "Bearer <Myrouter API Key>",
    }
)

message = client.messages.create(
    model="moonshotai/kimi-k2-instruct",
    max_tokens=1000,
    temperature=1,
    system=[
        {
            "type": "text",
            "text": "You are a Myrouter AI assistant. You will help users with an honest and professional attitude."
        }
    ],
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "Who are you?"
                }
            ]
        }
    ]
)

print(message.content)