安装与地址#

安装依赖
pip install anthropic
# Node.js
npm install @anthropic-ai/sdk

Python 示例#

Python · Messages
import anthropic

# Anthropic SDK 的 base_url 不带 /v1
client = anthropic.Anthropic(
    base_url="https://api.shrimpapi.example",
    api_key="sk-YOUR_SHRIMPAPI_KEY",
)

with client.messages.stream(
    model="claude-opus-5-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "你好"}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)

Node.js 示例#

Node.js · Messages
import Anthropic from "@anthropic-ai/sdk";

// Anthropic SDK 的 baseURL 不带 /v1
const client = new Anthropic({
  baseURL: "https://api.shrimpapi.example",
  apiKey: "sk-YOUR_SHRIMPAPI_KEY",
});

const stream = client.messages
  .stream({
    model: "claude-opus-5-5",
    max_tokens: 1024,
    messages: [{ role: "user", content: "你好" }],
  })
  .on("text", (text) => process.stdout.write(text));

await stream.finalMessage();

参数与错误#

  • max_tokens 为 Messages 必填参数。
  • system、tools 等按 Messages 结构传入。
  • 请求头 x-api-key 可用于鉴权。
  • 404 检查地址是否重复 /v1 及模型 ID;402 检查余额和 Key 额度。

字段列表见 Messages 接口。

更多系统与语言示例#

Node · 补充示例
Node 示例
npm install @anthropic-ai/sdk