Messages

POST https://api.model-r.com/v1/messages

所有请求头携带 Authorization 与 Content-Type 两个声明,取值与接入地址见快速开始,被拒绝的请求按错误码返回。

Anthropic Messages 兼容接口:请求与响应保持 Messages API 的官方形态,Claude 系客户端把接入地址换成 api.model-r.com 即可直连。

请求

{
  "model": "your-model",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": "帮我写一个快速排序的单元测试"
    }
  ]
}

key 在门户创建,可设置显示名、过期时间与授权模型列表,见API 密钥。model 的可用取值以模型列表返回为准。

参数

参数类型约束说明
model string 必填,非空 模型名,取值以模型列表接口为准
messages array 必填,非空 消息数组;role 只能是 user、assistant;content 为字符串或块数组,文本块的 text、tool_use 块的 id 与 name、tool_result 块的 tool_use_id 必须提供
system string 或 array 可选 系统提示
max_tokens integer 可选 输出上限,建议提供
temperature / top_p number 可选 采样参数,类型必须是数字
top_k integer 可选 候选数
stop_sequences string[] 可选 停止序列,元素必须是字符串
tools array 可选 函数声明,名字不得以 __ 开头
thinking object 可选 推理声明:{"type": "enabled", "budget_tokens": N} 或 {"type": "disabled"},规则见推理
output_config object 可选 effort 声明;与 thinking 互斥,同时出现按 mutually_exclusive 拒绝
max_tool_calls integer 可选,≥ 1 单次请求最多执行的函数调用数
mcp_servers 任意 不支持 客户端声明的 MCP 工具被明确拒绝,见函数调用

响应

{
  "id": "msg_…",
  "type": "message",
  "role": "assistant",
  "model": "your-model",
  "content": [
    {
      "type": "text",
      "text": "好的,这是一个快速排序的单元测试……"
    }
  ],
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 12,
    "output_tokens": 48
  }
}