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

# DeepSeek Messages

> Anthropic SDK 调用地址、文本提取和流式完成条件。

调用 `POST https://code.heihuzi.ai/v1/messages`。实测日期：**2026-09-19**。Anthropic SDK 配置 **`base_url="https://code.heihuzi.ai"`**，SDK 会拼接 `/v1/messages`；不用套用官方的 `/anthropic` 地址前缀。

## 请求参数

<ParamField body="model" type="string" required>
  填写 `deepseek-flash`。本页普通文本、流式和图片输入均使用此模型。
</ParamField>

<ParamField body="messages" type="object[]" required>
  本次验证 user 文本以及单张 base64 PNG 图片内容数组。
</ParamField>

<ParamField body="max_tokens" type="integer" required>
  本页成功示例使用 `1024`。同一取值的长输出测试也已通过，`stop_reason` 为 `max_tokens`，实际输出 token 为 1024。
</ParamField>

<ParamField body="stream" type="boolean">
  SDK 的 `messages.stream()` 开启流式。本次观察到 `message_start`、内容块事件、`message_delta`、`message_stop`。
</ParamField>

## 普通文本示例

以下 Flash 请求已返回 `HEIHUZI_OK`，`stop_reason` 为 `end_turn`；示例按内容块类型提取正文。

<RequestExample>
  ```python theme={null}
  import os
  from anthropic import Anthropic
  client = Anthropic(api_key=os.environ['HEIHUZI_API_KEY'], base_url='https://code.heihuzi.ai', timeout=120.0, max_retries=0)
  result = client.messages.create(model='deepseek-flash', max_tokens=1024, messages=[{'role': 'user', 'content': 'Reply exactly HEIHUZI_OK.'}])
  answer = ''.join((block.text for block in result.content if block.type == 'text'))
  print(answer)
  assert result.stop_reason == 'end_turn' and answer.strip() == 'HEIHUZI_OK'
  ```
</RequestExample>

## Flash 流式示例

本次答案为 `42`，最终 `stop_reason` 为 `end_turn`。下面的完整脚本已实际运行通过。

```python theme={null}
import os
from anthropic import Anthropic
client = Anthropic(api_key=os.environ['HEIHUZI_API_KEY'], base_url='https://code.heihuzi.ai', timeout=120.0, max_retries=0)
with client.messages.stream(model='deepseek-flash', max_tokens=1024, messages=[{'role': 'user', 'content': 'What is 19 + 23? Reply with the number only.'}]) as stream:
    answer = ''.join(stream.text_stream)
    result = stream.get_final_message()
print(answer)
print('stop_reason', result.stop_reason)
assert result.stop_reason == 'end_turn' and answer.strip() == '42'
```

## 完成条件与兼容差异

非流式读取 `content` 中 `type="text"` 的块；流式用最终消息的 `stop_reason` 确认完成。本次用量返回 `input_tokens`、`output_tokens` 及值为 0 的缓存字段，不据此推断缓存命中能力。

本页只保留实际通过的请求配置，见[实测范围](/cn/api-reference/deepseek/compatibility)。[图片理解](/cn/api-reference/deepseek/vision)页提供已验证的 Flash 单图示例。

[官方 Anthropic API 文档](https://api-docs.deepseek.com/zh-cn/guides/anthropic_api/)
