APIPro
网站首页
网站首页
  1. Anthropic 接口
  • (必读)使用说明
  • FAQ
  • 获取模型列表
    • Models(获取模型列表)
      GET
  • OpenAI 接口 (兼容各大原厂模型)
    • OpenAI SDK使用指南
    • Responses API 接口使用指南
    • 对话
      • 聊天(chat)
      • 流式返回(chat)
      • 思考模式(chat)
      • 结构化输出(chat)
      • 工具调用(chat)
      • MCP调用(chat)
      • web search(chat)
      • 聊天(responses)
      • 流式返回(responses)
      • 思考模式(responses)
      • web search(responses)
    • 图像
      • 必读: 生图模型相关说明
      • 文生图(chat)
      • 图生图(chat)
      • 分析图片(chat)
      • 文生图(images)
      • 图生图(images)
    • 视频
      • 视频URL:https://api.apipro.ai
      • seedance官转资源接口文档
      • 提交视频任务 (veo)
      • 提交视频任务 (seedance官转)
      • 提交视频任务 (seedance封装)
      • 提交视频任务 (可灵)
      • 提交视频任务 (万相)
      • 提交视频任务 (grok)
      • 查询视频状态
    • 语音
      • 语音回复(chat)
      • 语音识别(audio)
      • 语音合成(audio)
    • 文本向量处理
      • 文本重排序
      • 文本向量化
    • 音乐(suno接口)
      • 生成歌词lyrics接口
      • 生成音乐suno接口
      • 上传音乐接口
      • 歌曲拼接接口
      • 查询歌词/音乐任务
  • Anthropic 接口
    • Anthropic SDK使用指南
    • 聊天
      POST
    • 聊天(prompt cache)
      POST
    • 流式返回
      POST
    • 聊天(思考)
      POST
    • 工具调用(function call)
      POST
    • 分析图片
      POST
  • Gemini 接口
    • Gemini SDK使用指南
    • 聊天
      POST
    • 流式返回
      POST
    • 联网搜索
      POST
    • 文生图
      POST
    • 图生图(传file)
      POST
    • 图生图(传url)
      POST
    • 分析图片(传base64)
      POST
    • 分析图片(传url)
      POST
    • 音乐生成
      POST
  • Midjourney 接口
    • 接口使用示例 (局部重绘)
    • 任务查询接口
    • 获取种子(Seed)
    • 文生图(Imagine)
    • 图片融合(Blend)
    • 图生文(Describe)
    • 换脸(FaceSwap)
    • 上传(upload)
    • 任务批量查询接口
    • 按钮点击(Action)
    • 窗口执行(Modal)
    • 刷新链接(Refresh)
    • 编辑图片(Edit)
  • 第三方接入
    • OpenClaw接入APIPro
  • 平台接口
    • 余额查询接口
    • 日志查询接口
    • 费用汇总接口
    • 费用明细接口
  • 数据模型
    • 示例数据模型
      • Pet
      • Category
      • Tag
  1. Anthropic 接口

聊天(prompt cache)

POST
/v1/messages
通过设置参数:"cache_control": {"type": "ephemeral"} 可以支持 prompt cache 模式,
默认5m cache,通过显示参数可缓存1h:"cache_control": {"type": "ephemeral", "ttl": "1h"} #默认5分钟,显示指定1h
缓存生效的最小输入token限制如下(https://platform.claude.com/docs/en/build-with-claude/prompt-caching):
512 tokens for Claude Fable 5 and Claude Mythos 5
2,048 tokens for Claude Mythos Preview and Claude Opus 4.7
4,096 tokens for Claude Opus 4.6 and Claude Opus 4.5
1,024 tokens for Claude Opus 4.8, Claude Sonnet 4.6, Claude Sonnet 4.5, Claude Opus 4.1 (deprecated), Claude Opus 4 (retired, except on Vertex AI), and Claude Sonnet 4 (retired, except on Bedrock and Vertex AI)
4,096 tokens for Claude Haiku 4.5
2,048 tokens for Claude Haiku 3.5 (retired, except on Vertex AI)

请求参数

Header 参数

Body 参数application/json

示例
{
    "model": "claude-sonnet-4-5-20250929",
    "messages": [
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "总结文章的内容,不超过50个字: {text}",
                    "cache_control": {
                        "type": "ephemeral",
                        "ttl": "1h"
                    }
                }
            ]
        }
    ]
}

请求示例代码

Shell
JavaScript
Java
Swift
Go
PHP
Python
HTTP
C
C#
Objective-C
Ruby
OCaml
Dart
R
请求示例请求示例
Shell
JavaScript
Java
Swift
curl --location 'https://api.apipro.ai/v1/messages' \
--header 'x-api-key: {YOUR_API_KEY}' \
--header 'content-type: application/json' \
--data '{
    "model": "claude-sonnet-4-5-20250929",
    "messages": [
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "总结文章的内容,不超过50个字: {text}",
                    "cache_control": {
                        "type": "ephemeral",
                        "ttl": "1h"
                    }
                }
            ]
        }
    ]
}'

返回响应

🟢200成功
application/json
Bodyapplication/json

示例
{
    "id": "msg_bdrk_01MKgCTVgyqRZTHF9ej4xwZ8",
    "type": "message",
    "role": "assistant",
    "model": "claude-sonnet-4-5-20250929",
    "content": [
        {
            "type": "text",
            "text": "论文指出AI幻觉实为训练机制下的必然产物,模型倾向于瞎猜而非承认不知道。对比测试显示,善于猜测的模型准确率看似高,但错误率极高;而诚实的模型宁愿不答也不胡说。"
        }
    ],
    "stop_reason": "end_turn",
    "stop_sequence": null,
    "usage": {
        "input_tokens": 3,
        "cache_creation_input_tokens": 0,
        "cache_read_input_tokens": 1869,
        "output_tokens": 93
    }
}
修改于 2026-06-18 05:16:03
上一页
聊天
下一页
流式返回
Built with