# Claude Opus 4.6 API 由 Anthropic 提供支持的 Claude Opus 4.6 大模型完整 API 参考。 ## 模型版本 此 API 支持两种 Claude Opus 4.6 模型版本: | 模型 | ID | 描述 | |-------|----|-------------| | **Claude Opus 4.6 Text to Text** | `claude-opus-4.6-text-to-text` | 更高能力的文本推理和写作 | | **Claude Opus 4.6 File Analysis** | `claude-opus-4.6-file-analysis` | 使用 Claude Opus 进行文件和图像分析 | ## 快速对比 | 功能 | Text to Text | File Analysis | |---------|--------------|---------------| | 文本输入 | 必填 ✅ | 可选 | | 图像输入 | 不支持 ❌ | 可选 | | 文件输入 | 不支持 ❌ | 可选 | | 流式响应 | SSE | SSE | | `max_tokens` | 可选 | 可选 | | `top_p` | 可选 | 可选 | | `top_k` | 可选 | 可选 | ## Claude Opus 4.6 Text to Text ### 接口地址 ```http POST /api/v1/chat/completions ``` ### 请求参数 #### 必填参数 | 参数 | 类型 | 描述 | |-----------|------|-------------| | `model` | string | 必须为 `"claude-opus-4.6-text-to-text"` | | `messages` | array | 有序消息。请参阅 大模型 API 了解消息结构。 | | `stream` | boolean | `true` 返回 SSE,`false` 返回单个 JSON 响应。 | #### 消息支持 | 字段 | 文本 | 文件 | 图像 | |-------|------|------|-------| | `messages` | 必填 ✅ | 不支持 ❌ | 不支持 ❌ | #### 可选 | 参数 | 类型 | 范围 | 描述 | |-----------|------|-------|-------------| | `max_tokens` | integer | `1` - `64000` | 最大输出 token 数。 | | `top_p` | number | `0.0` - `1.0` | 限制候选 token 的累积概率质量。 | | `top_k` | integer | `> 0` | 限制候选 token 的数量。 | ### 请求示例 ```javascript const response = await fetch('https://api.flaq.ai/api/v1/chat/completions', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Accept': 'text/event-stream', 'Content-Type': 'application/json' }, body: JSON.stringify({ model: 'claude-opus-4.6-text-to-text', messages: [ { role: 'user', content: 'Analyze this launch strategy and list the biggest risks.' } ], stream: true, max_tokens: 2048, top_p: 0.5, top_k: 50 }) }); ``` ## Claude Opus 4.6 File Analysis ### 接口地址 ```http POST /api/v1/chat/completions ``` ### 请求参数 #### 必填参数 | 参数 | 类型 | 描述 | |-----------|------|-------------| | `model` | string | 必须为 `"claude-opus-4.6-file-analysis"` | | `messages` | array | 有序消息。请参阅 大模型 API 和 消息附件。 | | `stream` | boolean | `true` 返回 SSE,`false` 返回单个 JSON 响应。 | #### 消息支持 | 字段 | 文本 | 文件 | 图像 | |-------|------|------|-------| | `messages` | 可选 | 可选 | 可选 | #### 可选 | 参数 | 类型 | 范围 | 描述 | |-----------|------|-------|-------------| | `max_tokens` | integer | `1` - `64000` | 最大输出 token 数。 | | `top_p` | number | `0.0` - `1.0` | 限制候选 token 的累积概率质量。 | | `top_k` | integer | `> 0` | 限制候选 token 的数量。 | ### 请求示例 ```javascript const response = await fetch('https://api.flaq.ai/api/v1/chat/completions', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Accept': 'text/event-stream', 'Content-Type': 'application/json' }, body: JSON.stringify({ model: 'claude-opus-4.6-file-analysis', messages: [ { role: 'user', content: [ { type: 'text', text: 'Review this document and identify missing requirements.' }, { type: 'file', file: { filename: 'requirements.pdf', file_data: 'https://example.com/requirements.pdf' } } ] } ], stream: true, max_tokens: 4096, top_p: 0.5, top_k: 50 }) }); ``` ## 响应格式 Claude Opus 4.6 大模型返回 OpenAI 兼容生成响应。`stream: true` 时响应为 Server-Sent Events;`stream: false` 时响应为单个 JSON 对象。 ### 成功响应 ```text data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"claude-opus-4.6-file-analysis","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]} data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"claude-opus-4.6-file-analysis","choices":[{"index":0,"delta":{"content":"Here are the missing requirements"},"finish_reason":null}]} data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"claude-opus-4.6-file-analysis","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]} data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"claude-opus-4.6-file-analysis","choices":[],"usage":{"prompt_tokens":12,"completion_tokens":8,"total_tokens":20}} data: [DONE] ``` ### 错误响应 ```text event: error data: {"error":{"message":"API requests too frequent, exceeding rate limit","type":"rate_limit_error","code":"1302","param":null}} ``` ## 最佳实践 1. **使用结构化消息:** 通过 `messages[]` 发送对话历史,而不是把上下文压平成一个 prompt。 2. **选择正确的模型版本:** 仅文本推理与写作使用 Text to Text,需要文件或图像时使用 File Analysis。 3. **谨慎调整 Claude 参数:** 支持 `top_p` 和 `top_k`,它们会影响输出多样性。 4. **消费 SSE 事件:** 追加 `choices[0].delta.content` 进行流式展示,并将 `data: [DONE]` 视为成功完成。 5. **仅发送受支持的输入:** 当前客户端中的 Text 模型会忽略不支持的文件和图像部分。