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

# Claude Sonnet 4

> 通过 OpenAI 兼容接口调用 Anthropic 的 Claude Sonnet 4，智能与速度的最佳平衡，适用于日常编程和复杂任务。

Claude Sonnet 4 是 Anthropic 最佳的编程模型，通过 Starrise AI 以 OpenAI 兼容接口提供服务。在智能、速度和成本之间实现理想平衡，擅长软件工程、复杂推理和日常开发任务。

## 核心能力

* **OpenAI 兼容** — 可直接替换 OpenAI SDK，无需修改其他代码
* **最佳编程模型** — 代码生成、调试和重构表现顶尖
* **快速高效** — 相比 Opus 模型延迟更低、成本更优
* **强大推理** — 擅长多步骤问题求解和分析
* **长上下文** — 支持大文档处理和多轮对话
* **流式输出** — 通过 SSE 实现实时 Token 流式传输

## 快速示例

```bash cURL theme={null}
curl https://dayu.cdn-fly.com/v1/messages \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-20250514",
    "messages": [
      { "role": "user", "content": "写一个 Python 函数合并两个有序数组。" }
    ]
  }'
```

```python Python theme={null}
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://dayu.cdn-fly.com/v1"
)

response = client.chat.completions.create(
    model="claude-sonnet-4-20250514",
    messages=[
        {"role": "user", "content": "写一个 Python 函数合并两个有序数组。"}
    ]
)

print(response.choices[0].message.content)
```

```python 流式输出 theme={null}
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://dayu.cdn-fly.com/v1"
)

stream = client.chat.completions.create(
    model="claude-sonnet-4-20250514",
    messages=[
        {"role": "user", "content": "解释异步编程和同步编程的区别。"}
    ],
    stream=True
)

for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="")
```

## 参数说明

| 参数 | 类型 | 必填 | 说明 |
| - | - | - | - |
| `model` | string | 是 | 固定为 `claude-sonnet-4-20250514` |
| `messages` | array | 是 | `{ role, content }` 对象数组 |
| `max_tokens` | integer | 否 | 最大生成 Token 数 |
| `temperature` | float | 否 | `0`–`2`，控制随机性，默认 `1` |
| `stream` | boolean | 否 | 开启 SSE 流式传输，默认 `false` |
| `top_p` | float | 否 | 核采样阈值，默认 `1` |
| `stop` | string / array | 否 | 触发停止生成的序列 |

> **[API 参考](/zh/api-reference/introduction)**
>
> 查看 Claude Sonnet 4 的交互式 API Playground。


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