Documentation Index
Fetch the complete documentation index at: https://docs-model.skyengine.com.cn/llms.txt
Use this file to discover all available pages before exploring further.
Claude 基础对话示例
以下示例展示如何使用Claude的/v1/messages 接口进行基础文本对话。
快速开始
只需要替换YOUR_API_KEY 为你的实际API密钥即可运行。
结果示例
重要参数说明
- model: Claude模型名称,如
claude-3-7-sonnet-20250219、claude-3-haiku-20240307等 - max_tokens: 最大生成token数量,Claude要求必须指定此参数
- messages: 对话消息数组,包含角色(role)和内容(content)
- anthropic-version: API版本号,建议使用
2023-06-01
支持的模型
- claude-sonnet-4-20250514
- claude-opus-4-250514
- claude-3-7-sonnet-20250219
- claude-3-5-sonnet-20241022
Claude API特点
- 响应格式: Claude返回的内容在
content数组中,每个元素包含text字段 - 必需头部: 需要包含
anthropic-version头部 - token限制: 必须指定
max_tokens参数,不能省略
错误处理
Claude API的常见错误码:- 400 Bad Request: 请求参数错误
- 401 Unauthorized: API密钥无效
- 429 Rate Limit Exceeded: 请求频率超限
- 500 Internal Server Error: 服务器内部错误

