使用 Claude 3.5 Haiku 分析和提取各种文件类型的信息,包括文档、电子表格和 PDF
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1699896916,
"model": "claude-haiku-4-5-20251001",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "# Document Analysis Summary\n\n## Key Information:\n- Document Type: Technical API Documentation\n- Total Pages: 35\n- Version: 2.0\n\n## Main Topics:\n1. **Authentication**: The API uses Bearer token authentication with API keys\n2. **Endpoints**: Contains 12 main API endpoints for different operations\n3. **Rate Limiting**: Implements tiered rate limiting based on subscription level\n4. **Error Handling**: Comprehensive error codes and handling strategies\n\n## Key Sections:\n\n### Getting Started\n- Quick start guide for new developers\n- Authentication setup instructions\n- First API call examples in multiple languages\n\n### API Reference\n- Detailed endpoint documentation\n- Request/response formats\n- Parameter descriptions and constraints\n\n### Best Practices\n- Recommended usage patterns\n- Performance optimization tips\n- Security considerations\n\n### Code Examples\n- Python, JavaScript, Go, and cURL examples\n- Common use case implementations\n- Error handling patterns\n\n## Important Notes:\n- All requests must include valid API key\n- Rate limits: 100 requests/minute for free tier, 1000/minute for premium\n- Support for both JSON and XML response formats\n- Webhook notifications available for asynchronous operations"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 3500,
"completion_tokens": 285,
"total_tokens": 3785
}
}| 参数 | 类型 | 必填 | 默认值 | 范围 | 描述 |
|---|---|---|---|---|---|
model | string | 是 | claude-haiku-4-5-20251001 | - | 模型标识符。此模型使用 claude-haiku-4-5-20251001 |
messages | array | 是 | - | - | 对话的输入消息。每条消息必须包含 role(user/assistant/system)和 content。内容可以包含文本块或文件块。支持的格式:PDF、DOCX、XLSX、TXT、CSV、JSON、XML、HTML。最大文件大小:20MB。 |
max_tokens | integer | 否 | 1024 | 1-64000 | 生成的最大 token 数量。模型可能会在此限制之前停止 |
temperature | number | 否 | 1.0 | 0.0-2.0 | 控制输出的随机性。对于分析任务使用较低的值(接近 0.0),对于创意任务使用较高的值 |
top_p | number | 否 | 1.0 | 0.0-1.0 | 核采样阈值。通过仅考虑累积概率达到 top_p 的 token 来控制多样性。 |
stream | boolean | 否 | false | - | 是否使用服务器发送事件逐步流式传输响应 |
stop | string/array | 否 | null | 最多 4 个序列 | 最多 4 个序列,API 将在遇到这些序列时停止生成更多 token |
presence_penalty | number | 否 | 0 | -2.0-2.0 | 根据 token 是否出现在当前文本中来对其进行惩罚。正值增加模型谈论新话题的可能性 |
frequency_penalty | number | 否 | 0 | -2.0-2.0 | 根据 token 在当前文本中的出现频率来对其进行惩罚。正值降低模型重复相同内容的可能性 |
{
"role": "user",
"content": [
{
"type": "text",
"text": "Please analyze this document"
},
{
"type": "file",
"file": {
"filename": "document.pdf",
"file_data": "https://example.com/document.pdf"
}
}
]
}{
"type": "file",
"file": {
"filename": "document.pdf",
"file_data": "data:application/pdf;base64,JVBERi0xLjQK..."
}
}| 字段 | 类型 | 必填 | 描述 |
|---|---|---|---|
role | string | 是 | 消息的角色。可以是:user、assistant 或 system |
content | array/string | 是 | 消息的内容。可以是字符串或内容块数组 |
| 字段 | 类型 | 必填 | 描述 |
|---|---|---|---|
type | string | 是 | 必须是 text |
text | string | 是 | 文本内容 |
| 字段 | 类型 | 必填 | 描述 |
|---|---|---|---|
type | string | 是 | 必须是 file |
file | object | 是 | 包含 filename 和 file_data 的文件对象 |
| 字段 | 类型 | 必填 | 描述 |
|---|---|---|---|
filename | string | 是 | 文件名称(例如:document.pdf) |
file_data | string | 是 | 文件的 URL 或使用 data URI 方案的 base64 编码数据(例如:data:application/pdf;base64,<base64_data>) |
| 格式 | MIME 类型 | 扩展名 |
|---|---|---|
application/pdf | .pdf | |
| Word | application/vnd.openxmlformats-officedocument.wordprocessingml.document | .docx |
| Excel | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet | .xlsx |
| 纯文本 | text/plain | .txt |
| CSV | text/csv | .csv |
| JSON | application/json | .json |
| XML | application/xml 或 text/xml | .xml |
| HTML | text/html | .html |
| 错误码 | 错误名称 | 描述 |
|---|---|---|
| 401 | Unauthorized | API 密钥缺失或无效 |
| 403 | Forbidden | 您的 API 密钥没有访问此资源的权限,或请求操作的余额不足 |
| 429 | Too Many Requests | 您已超出速率限制 |
| 500 | Internal server error | 发生内部服务器错误 |
| 503 | Content policy violation | 内容因安全问题被阻止(实际状态码为 400) |