> ## Documentation Index
> Fetch the complete documentation index at: https://docs.jiji.cc/llms.txt
> Use this file to discover all available pages before exploring further.

# Anthropic Messages

> 使用 Anthropic 原生 Messages 格式调用 Claude 模型，Claude Code 使用的就是这个接口。

```text theme={null}
POST https://www.jiji.cc/v1/messages
```

兼容 Anthropic 官方 Messages 接口，可以完整使用思考、工具调用、图片和 PDF 理解等功能。

## 基础调用

<CodeGroup>
  ```python Python theme={null}
  import os
  import anthropic

  client = anthropic.Anthropic(
      base_url="https://www.jiji.cc",
      auth_token=os.environ["JIJI_API_KEY"],
  )

  msg = client.messages.create(
      model="claude-opus-5-5",
      max_tokens=1024,
      system="你是一个简洁的编程助手。",
      messages=[{"role": "user", "content": "用一句话解释什么是闭包。"}],
  )
  print(msg.content[0].text)
  ```

  ```javascript Node.js theme={null}
  import Anthropic from "@anthropic-ai/sdk";

  const client = new Anthropic({
    baseURL: "https://www.jiji.cc",
    authToken: process.env.JIJI_API_KEY,
  });

  const msg = await client.messages.create({
    model: "claude-opus-5-5",
    max_tokens: 1024,
    system: "你是一个简洁的编程助手。",
    messages: [{ role: "user", content: "用一句话解释什么是闭包。" }],
  });
  console.log(msg.content[0].text);
  ```

  ```bash cURL theme={null}
  curl https://www.jiji.cc/v1/messages \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $JIJI_API_KEY" \
    -H "anthropic-version: 2023-06-01" \
    -d '{
      "model": "claude-opus-5-5",
      "max_tokens": 1024,
      "system": "你是一个简洁的编程助手。",
      "messages": [{"role": "user", "content": "用一句话解释什么是闭包。"}]
    }'
  ```
</CodeGroup>

<Warning>
  * SDK 的 `base_url` 填 `https://www.jiji.cc`，**不要**加 `/v1`
  * 使用 `auth_token`（Node.js 为 `authToken`）传入 Key，SDK 会以 `Authorization: Bearer` 方式发送
</Warning>

## 流式输出

<CodeGroup>
  ```python Python theme={null}
  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)
  ```

  ```javascript Node.js theme={null}
  const stream = client.messages.stream({
    model: "claude-opus-5-5",
    max_tokens: 1024,
    messages: [{ role: "user", content: "写一首关于春天的短诗" }],
  });
  stream.on("text", (text) => process.stdout.write(text));
  await stream.finalMessage();
  ```
</CodeGroup>

## 工具调用

```python Python theme={null}
tools = [{
    "name": "get_weather",
    "description": "查询城市的实时天气",
    "input_schema": {
        "type": "object",
        "properties": {"city": {"type": "string"}},
        "required": ["city"],
    },
}]

messages = [{"role": "user", "content": "北京今天天气怎么样？"}]
msg = client.messages.create(
    model="claude-opus-5-5", max_tokens=1024, tools=tools, messages=messages
)

if msg.stop_reason == "tool_use":
    messages.append({"role": "assistant", "content": msg.content})
    results = []
    for block in msg.content:
        if block.type == "tool_use":
            results.append({
                "type": "tool_result",
                "tool_use_id": block.id,
                "content": f"{block.input['city']}：晴，22°C",  # 替换为真实查询
            })
    messages.append({"role": "user", "content": results})
    msg = client.messages.create(
        model="claude-opus-5-5", max_tokens=1024, tools=tools, messages=messages
    )

print(msg.content[0].text)
```

## 图片理解

```python Python theme={null}
import base64

with open("photo.png", "rb") as f:
    b64 = base64.b64encode(f.read()).decode()

msg = client.messages.create(
    model="claude-opus-5-5",
    max_tokens=1024,
    messages=[{
        "role": "user",
        "content": [
            {"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": b64}},
            {"type": "text", "text": "这张图片里有什么？"},
        ],
    }],
)
print(msg.content[0].text)
```

PDF 文件使用 `"type": "document"`、`"media_type": "application/pdf"`，写法相同。

## 常用参数

| 参数 | 说明 |
| - | - |
| `model` | 模型 ID，以 [模型广场](https://www.jiji.cc/extension/models) 为准 |
| `max_tokens` | 最多生成的 Token 数，必填 |
| `system` | 系统提示词 |
| `messages` | 对话消息列表 |
| `tools` | 可供模型调用的工具列表 |
| `stream` | 是否流式返回 |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.