Anthropic API

TokenOcean 同时支持 Anthropic API 格式。修改服务地址与密钥,即可通过 Anthropic SDK 调用平台模型。

Anthropic 的 base_url 为服务地址加 /anthropic,SDK 会请求 /anthropic/v1/messages。

安装 SDK

pip install anthropic

配置环境变量

export ANTHROPIC_BASE_URL="https://api.tokenocean.pro/anthropic"
export ANTHROPIC_API_KEY="YOUR_API_KEY"

调用 Messages API

import anthropic


client = anthropic.Anthropic()


message = client.messages.create(
    model="deepseek-v4-pro",
    max_tokens=1000,
    system="You are a helpful assistant.",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "Hi, how are you?"}
            ],
        }
    ],
)


print(message.content)
Anthropic API | TokenOcean 文档