# Anthropic API 接口

该模型适配于 Anthropic 端侧接口标准

Base Url： https://maas-openapi.wanjiedata.com/api/anthropic

获取 [API KEY](https://www.wjark.com/center/api-key)：https://www.wjark.com/center/api-key

- [Anthropic 端侧接口标准适配模型一览表](https://docs.wjark.com/maas/UserGuide/Usage/Anthropic.html)：https://docs.wjark.com/maas/UserGuide/Usage/Anthropic.html

```shell
POST /api/anthropic/v1/messages
```

## 基础文本对话

**请求示例**：

```shell 
export API_KEY="<你的 API KEY>"
export MODEL="<Anthropic 端侧接口标准适配模型>"
curl --location 'https://maas-openapi.wanjiedata.com/api/anthropic/v1/messages' \
--header "Authorization: Bearer $API_KEY"  \
--header 'Content-Type: application/json' \
--data '{
  "model": "'$MODEL'",
  "messages": [
    {
      "role": "user",
      "content": "Who are you?"
    }
  ],
  "stream": false
}'
```

```python 
import requests

API_KEY = "<你的 API KEY>"
MODEL = "<Anthropic 端侧接口标准适配模型>"
url = "https://maas-openapi.wanjiedata.com/api/anthropic/v1/messages"
headers = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json"
}
payload = {
    "model": MODEL,
    "messages": [
        {
            "role": "user",
            "content": "Who are you?"
        }
    ],
    "stream": False 
}

response = requests.post(url, headers=headers, json=payload)

print("状态码:", response.status_code)
try:
    print("返回内容:", response.json())
except Exception:
    print("不是 JSON 内容，原始响应：")
    print(response.text)

```

```javascript
const API_KEY = '<你的 API KEY>';
const MODEL = '<Anthropic 端侧接口标准适配模型>';

fetch('https://maas-openapi.wanjiedata.com/api/anthropic/v1/messages', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer ' + API_KEY,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    model: MODEL,
    messages: [{ role: 'user', content: 'Who are you?' }],
    stream: false
  })
})
.then(res => res.json())
.then(console.log);
```

**响应示例：**

```shell 
{
    "content": [
        {
            "text": " I'm Claude, an AI assistant created by Anthropic. I'm Claude Sonnet 4, which is part of the Claude 4 model family - designed to be a smart, efficient model for everyday use. I'm here to help with a wide variety of tasks like answering questions, helping with analysis and research, creative writing, coding, math, and having conversations on topics you're interested in.\n\nIs there something specific I can help you with today?",
            "type": "text"
        }
    ],
    "id": "chatcmpl-89D4VckZWG45tf5pn880S2JXvBETE",
    "model": "claude-sonnet-4-20250514",
    "role": "assistant",
    "stop_reason": "end_turn",
    "type": "message",
    "usage": {
        "cache_creation_input_tokens": 0,
        "cache_read_input_tokens": 0,
        "input_tokens": 11,
        "output_tokens": 92
}
}
```

```python 

状态码: 200
返回内容:
 {
    'content': 
    [{'text': "I'm Claude Code, Anthropic's official CLI for Claude. I'm designed to help you interact with Claude's capabilities through a command-line interface. I can assist with tasks like answering questions, providing information, helping with code, or discussing various topics - all through a text-based interface. How can I help you today?", 'type': 'text'}], 
    'id': 'msg_01SSwdDURPtrBYeKharsKJFU',
     'model': 'claude-sonnet-4-20250514', 
     'role': 'assistant', 
     'stop_reason':'end_turn', 
     'stop_sequence': None, 
     'type': 'message', 
     'usage': 
     {'cache_creation': {'ephemeral_1h_input_tokens': 0, 'ephemeral_5m_input_tokens': 0}, 
     'cache_creation_input_tokens': 0, 
     'cache_read_input_tokens': 0,
     'input_tokens': 25,
      'output_tokens': 72, 
      'service_tier': 'standard'}}
```

```javascript 
{
  content: [
    {
      text: "I am Claude Code, Anthropic's official CLI (command-line interface) for Claude. I'm designed to help you through this command-line environment, providing assistance with various tasks, answering questions, and offering support as needed. How can I help you today?",
      type: 'text'
    }
  ],
  id: 'msg_01GjfDdSHvUnmm15CN4KxA2H',
  model: 'claude-sonnet-4-20250514',
  role: 'assistant',
  stop_reason: 'end_turn',
  stop_sequence: null,
  type: 'message',
  usage: {
    cache_creation: { ephemeral_1h_input_tokens: 0, ephemeral_5m_input_tokens: 0 },
    cache_creation_input_tokens: 0,
    cache_read_input_tokens: 0,
    input_tokens: 25,
    output_tokens: 59,
    service_tier: 'standard'
  }
}
```

## 图像分析对话

**请求示例**：

```shell 
export API_KEY="<你的 API KEY>"
export MODEL="<Anthropic 端侧接口标准适配模型>"
curl --location 'https://maas-openapi.wanjiedata.com/api/anthropic/v1/messages' \
--header 'anthropic-version: 2023-06-01' \
--header 'content-type: application/json' \
--header 'Authorization: $NEWAPI_API_KEY' \
--data '{
    "model": "claude-sonnet-4-20250514",
    "messages": [
        {
            "role": "user",
            "content": [
                {
                    "type": "image",
                    "source": {
                        "type": "base64",
                        "media_type": "image/jpeg",
                        "data": "/9j/4AA..."
                    }
                },
                {
                    "type": "text",
                    "text": "这张图片里有什么?"
                }
            ]
        }
    ]
}'
```

```python 
import requests
import base64

API_KEY = "<你的 API KEY>"
MODEL = "claude-sonnet-4-20250514"
url = "https://maas-openapi.wanjiedata.com/api/anthropic/v1/messages"
headers = {
    "anthropic-version": "2025-09-29", 
    "Content-Type": "application/json",
    "Authorization": API_KEY,
}

with open("example.jpg", "rb") as f:
    img_data = base64.b64encode(f.read()).decode("utf-8")

payload = {
    "model": MODEL,
    "messages": [
        {
            "role": "user",
            "content": [
                {
                    "type": "image",
                    "source": {
                        "type": "base64",
                        "media_type": "image/jpeg",
                        "data": img_data
                    }
                },
                {
                    "type": "text",
                    "text": "这张图片里有什么?"
                }
            ]
        }
    ]
}

response = requests.post(url, headers=headers, json=payload)
print("状态码:", response.status_code)
try:
    print("响应内容:", response.json())
except Exception:
    print("不是JSON内容，原始响应：")
    print(response.text)

```

```javascript
const API_KEY = '<你的 API KEY>';

fetch('https://maas-openapi.wanjiedata.com/api/anthropic/v1/messages', {
  method: 'POST',
  headers: {
    'anthropic-version': '2023-06-01',
    'content-type': 'application/json',
    'Authorization': API_KEY
  },
  body: JSON.stringify({
    model: 'claude-sonnet-4-20250514',
    messages: [{
      role: 'user',
      content: [
        {
          type: 'image',
          source: {
            type: 'base64',
            media_type: 'image/jpeg',
            data: '/9j/4AA...'
          }
        },
        {
          type: 'text',
          text: '这张图片里有什么?'
        }
      ]
    }]
  })
})
.then(res => res.json())
.then(console.log);

```

**响应示例：**

```shell
{
    "content": [
        {
            "text": "这张图片展示了一个非常详细且恐怖的怪物或恶魔生物的数字艺术作品。"
            "type": "text"
        }
    ],
    "id": "msg_012dwFPtzacgz4JzdvP7Vvy6",
    "model": "claude-sonnet-4-20250514",
    "role": "assistant",
    "stop_reason": "end_turn",
    "stop_sequence": null,
    "type": "message",
    "usage": {
        "cache_creation": {
            "ephemeral_1h_input_tokens": 0,
            "ephemeral_5m_input_tokens": 0
        },
        "cache_creation_input_tokens": 0,
        "cache_read_input_tokens": 0,
        "input_tokens": 1403,
        "output_tokens": 320,
        "service_tier": "standard"
        }
}

```

```python 
状态码: 200
响应内容:
 {
    'content':
     [{'text': '这张图片展示了一个品牌或公司的标志。标志由两部分组成:\n\n1. 左侧是一个几何图形标识，由蓝色和橙色的交错形状组成，形成一个方形的设计，包含了角形和圆形元素。\n\n2. 右侧 是中文字符"万界方舟"，以黑色字体呈现。\n\n图片的背景是一个柔和的淡蓝色渐变，带有蓝色和橙色的流线型装饰曲线，给整体设计带来现代感和动态效果。这看起来像是一个科技公司、应用程序或游戏的品牌标识。', 'type': 'text'}],
      'id': 'msg_01NQwq2FoeXMjTKG85vC46Xz',
       'model': 'claude-sonnet-4-20250514',
       'role': 'assistant', 
       'stop_reason': 'end_turn', 
       'stop_sequence': None, 
       'type': 'message', 
       'usage': {'cache_creation': {'ephemeral_1h_input_tokens': 0, 'ephemeral_5m_input_tokens': 0},
        'cache_creation_input_tokens': 0,
         'cache_read_input_tokens': 0,
          'input_tokens': 1048, 
          'output_tokens': 206,
           'service_tier': 'standard'}}

```

```javascript
{
  content: [
    {
      text: '这张图片展示了一个品牌标识，左侧是一个由蓝色和橙色线条组成的几何图形标志，看起来像是由方形元素和圆点组合而成。右侧是中文字符"万界方舟"，这可能是一家公司、应用程序或产品的名称。\n' +     
        '\n' +
        '背景设计采用了简约的风格，有蓝色和橙色的流线型曲线元素，呈现出一种现代、科技感的美学。整体色调以蓝白为主，搭配橙色的点缀，给人一种专业且富有活力的感觉。',
      type: 'text'
    }
  ],
  id: 'msg_01LZ9TF5dUdCw4PJjqtXgL3j',
  model: 'claude-sonnet-4-20250514',
  role: 'assistant',
  stop_reason: 'end_turn',
  stop_sequence: null,
  type: 'message',
  usage: {
    cache_creation: { ephemeral_1h_input_tokens: 0, ephemeral_5m_input_tokens: 0 },
    cache_creation_input_tokens: 0,
    cache_read_input_tokens: 0,
    input_tokens: 1048,
    output_tokens: 189,
    service_tier: 'standard'
  }
}
```

## 工具调用
**请求示例**：

```shell
export API_KEY="<你的 API KEY>"
export MODEL="<Anthropic 端侧接口标准适配模型>"
curl --location 'https://maas-openapi.wanjiedata.com/api/anthropic/v1/messages' \
--header 'anthropic-version: 2025-09-29' \
--header 'content-type: application/json' \
--header 'Authorization: $NEWAPI_API_KEY' \
--data '{
    "model": "claude-sonnet-4-20250514",
    "messages": [
        {
            "role": "user", 
            "content": "今天北京的天气怎么样?"
        }
    ],
    "tools": [
        {
            "name": "get_weather",
            "description": "获取指定位置的当前天气",
            "input_schema": {
                "type": "object",
                "properties": {
                    "location": {
                        "type": "string",
                        "description": "城市名称,如:北京"
                    }
                },
                "required": ["location"]
            }
        }
    ]
}'
```

```python
import requests

API_KEY = "<你的 API KEY>"
MODEL = "claude-sonnet-4-20250514"
url = "https://maas-openapi.wanjiedata.com/api/anthropic/v1/messages"
headers = {
    "anthropic-version": "2025-09-29",
    "Content-Type": "application/json",
    "Authorization": API_KEY  
}
payload = {
    "model": MODEL,
    "messages": [
        {
            "role": "user", 
            "content": "今天北京的天气怎么样?"
        }
    ],
    "tools": [
        {
            "name": "get_weather",
            "description": "获取指定位置的当前天气",
            "input_schema": {
                "type": "object",
                "properties": {
                    "location": {
                        "type": "string",
                        "description": "城市名称,如:北京"
                    }
                },
                "required": ["location"]
            }
        }
    ]
}

response = requests.post(url, headers=headers, json=payload)

print("状态码:", response.status_code)
try:
    print("响应内容:", response.json())
except Exception:
    print("不是JSON内容，原始响应：")
    print(response.text)

```

```javascript
const API_KEY = '<你的 API KEY>';
const MODEL = '<Anthropic 端侧接口标准适配模型>';

fetch('https://maas-openapi.wanjiedata.com/api/anthropic/v1/messages', {
  method: 'POST',
  headers: {
    'anthropic-version': '2025-09-29',
    'content-type': 'application/json',
    'Authorization': API_KEY
  },
  body: JSON.stringify({
    model: MODEL,
    messages: [{ role: 'user', content: '今天北京的天气怎么样?' }],
    tools: [{
      name: 'get_weather',
      description: '获取指定位置的当前天气',
      input_schema: {
        type: 'object',
        properties: { location: { type: 'string', description: '城市名称,如:北京' } },
        required: ['location']
      }
    }]
  })
})
.then(res => res.json())
.then(console.log);
```

**响应示例：**

```shell
{
    "content": 
        {
            "text": "我可以帮您查询北京今天的天气。让我使用工具来获取这个信息。",
            "type": "text"
        },
        {
            "id": "toolu_01NkGsn5vLhjRFdDSPHmMget",
            "input": {
                "location": "北京"
            },
            "name": "get_weather",
            "type": "tool_use"
        },
    "id": "msg_01C2UydM8Q4hxkVcDs58yXxr",
    "model": "claude-sonnet-4-20250514",
    "role": "assistant",
    "stop_reason": "tool_use",
    "stop_sequence": null,
    "type": "message",
    "usage": {
        "cache_creation": {
            "ephemeral_1h_input_tokens": 0,
            "ephemeral_5m_input_tokens": 0,
        "cache_creation_input_tokens": 0,
        "cache_read_input_tokens": 0,
        "input_tokens": 485,
        "output_tokens": 86,
        "service_tier": "standard"
        }
}
}
```

```python
状态码: 200
响应内容:
 {
    'content': [{'text': '我可以帮您查询北京的天气。让我为您获取北京今天的天气信息。', 'type': 'text'}, {'id': 'toolu_01FYsLLzi11MyEK6PMxvfYGJ', 'input': {'location': '北京'}, 'name': 'get_weather', 'type': 'tool_use'}],
     'id': 'msg_01MyeHkQUc7DJxLJKhFjrgWQ',
      'model': 'claude-sonnet-4-20250514',
       'role': 'assistant', 
       'stop_reason': 'tool_use',
        'stop_sequence': None, 
        'type': 'message',
         'usage': {'cache_creation': {'ephemeral_1h_input_tokens': 0, 
         'ephemeral_5m_input_tokens': 0},
          'cache_creation_input_tokens': 0, 
          'cache_read_input_tokens': 0,
           'input_tokens': 485,
            'output_tokens': 86, 
            'service_tier': 'standard'}}
```

```javascript
{
  content: [
    { text: '我可以为您查询北京的天气情况。让我使用天气查询工具来获取北京今天的天气。', type: 'text' },
    {
      id: 'toolu_01Hz5X7xPeU2ZFbSrZr4LVQ7',
      input: [Object],
      name: 'get_weather',
      type: 'tool_use'
    }
  ],
  id: 'msg_01RgMpnsPrdotk29p5q9ZrMq',
  model: 'claude-sonnet-4-20250514',
  role: 'assistant',
  stop_reason: 'tool_use',
  stop_sequence: null,
  type: 'message',
  usage: {
    cache_creation: { ephemeral_1h_input_tokens: 0, ephemeral_5m_input_tokens: 0 },
    cache_creation_input_tokens: 0,
    cache_read_input_tokens: 0,
    input_tokens: 485,
    output_tokens: 92,
    service_tier: 'standard'
  }
}
```

## Anthropic 端侧接口标准适配模型使用方法详见

示例一： [在 Cherry Studio 中配置 Anthropic 端侧接口标准适配模型](https://docs.wjark.com/maas/scenarios/USEClaudemodel/claudeCherryStudio.html)

示例二： [Claude code 使用说明](https://docs.wjark.com/maas/scenarios/USEClaudemodel/claudecode.html)

示例二： [Claude code 在 VScode 中的应用](https://docs.wjark.com/maas/scenarios/USEClaudemodel/claudeVScode.html)