Messages 协议
通过 Anthropic Messages API 格式访问 Anthropic、DeepSeek、DashScope、Xiaomi、Kimi、MiniMax 和 Zai 模型。
Messages 协议以 Anthropic Messages API 格式暴露在 POST /v1/messages。它是 OpenModel 上覆盖最广的协议,服务七家供应商:Anthropic、DeepSeek、DashScope、Xiaomi、Kimi、MiniMax 和 Zai。
由于所有供应商共享相同的端点与请求结构,你对它们全部使用 Anthropic SDK——切换供应商只需更改 model 参数,无需修改其他代码。安装与完整示例参见 Anthropic SDK 指南。
端点
POST https://api.openmodel.ai/v1/messages另有一个端点 POST /v1/messages/count_tokens,用于在不创建消息的情况下计算 Token 数(仅 Anthropic)。
认证
所有供应商都使用同一个 OpenModel API 密钥。可作为 Bearer 令牌,或通过 X-Api-Key 请求头传入:
Authorization: Bearer om-your-api-keyanthropic-version 请求头为兼容 SDK 而接受,默认为 2023-06-01。
切换供应商
要切换到不同的供应商,只需更改 model 参数:
# DeepSeek
client.messages.create(model="deepseek-v4-flash", max_tokens=1024, messages=[...])
# DashScope
client.messages.create(model="qwen3-max", max_tokens=1024, messages=[...])
# Xiaomi
client.messages.create(model="mimo-v2.5-pro", max_tokens=1024, messages=[...])
# Kimi
client.messages.create(model="kimi-k2.5", max_tokens=1024, messages=[...])
# MiniMax
client.messages.create(model="MiniMax-M2.5", max_tokens=1024, messages=[...])
# Zai
client.messages.create(model="glm-5", max_tokens=1024, messages=[...])供应商差异与在线试用
在下方选择供应商,即可查看其示例模型、错误响应格式,以及预填了该供应商模型的交互式 playground。多数供应商的行为与 Anthropic 基准完全一致,仅在文档列出的差异点有所不同。
- 示例模型
claude-opus-4-6claude-opus-4-7claude-opus-4-8claude-sonnet-4-6claude-haiku-4-5-20251001- 错误响应格式
- 标准 Anthropic 格式——错误体携带字符串
error.type(如authentication_error、rate_limit_error)。这是 所有 Messages provider 的对比基准。
以上为示例模型,可用列表可能变更。前往控制台查看全部可用模型
在请求中包含您的 API 密钥:Authorization: Bearer om-your-api-key
位置: header
请求头参数
必填。指定 Anthropic API 版本。
"2023-06-01"请求体
application/json
TypeScript 类型定义
在 TypeScript 中使用 request body 类型。
响应体
application/json
application/json
application/json
application/json
curl -X POST "https://example.com/v1/messages" \ -H "anthropic-version: 2023-06-01" \ -H "Content-Type: application/json" \ -d '{ "model": "claude-sonnet-4-6", "max_tokens": 1024, "messages": [ { "role": "user", "content": "Explain the concept of recursion in programming." } ] }'{
"id": "msg_01XFDUDYJgAACzvnptvVoYEL",
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "Recursion is a programming technique where a function calls itself to solve a problem by breaking it down into smaller, identical subproblems."
}
],
"model": "claude-sonnet-4-6",
"stop_reason": "end_turn",
"usage": {
"input_tokens": 15,
"output_tokens": 168
}
}{
"type": "string",
"error": {
"type": "string",
"message": "string"
}
}{
"type": "string",
"error": {
"type": "string",
"message": "string"
}
}{
"type": "string",
"error": {
"type": "string",
"message": "string"
}
}在请求中包含您的 API 密钥:Authorization: Bearer om-your-api-key
位置: header
请求头参数
必填。指定 Anthropic API 版本。
"2023-06-01"请求体
application/json
TypeScript 类型定义
在 TypeScript 中使用 request body 类型。
响应体
application/json
application/json
application/json
curl -X POST "https://example.com/v1/messages/count_tokens" \ -H "anthropic-version: 2023-06-01" \ -H "Content-Type: application/json" \ -d '{ "model": "claude-sonnet-4-6", "messages": [ { "role": "user", "content": "What is the meaning of life?" } ] }'{
"input_tokens": 15
}{
"type": "string",
"error": {
"type": "string",
"message": "string"
}
}{
"type": "string",
"error": {
"type": "string",
"message": "string"
}
}- 示例模型
deepseek-v4-flashdeepseek-v4-pro- 错误响应格式
- 标准 Anthropic
error.type格式。
以上为示例模型,可用列表可能变更。前往控制台查看全部可用模型
兼容性说明
DeepSeek 的 Anthropic 格式端点并未实现 Anthropic 的全部能力,与 Anthropic 的差异如下。
| 字段 | 状态 |
|---|---|
max_tokens、system、stream、 stop_sequences、top_p、tools | 完全支持 |
temperature | 支持,范围 0.0 – 2.0 |
tool_choice | 支持(none / auto / any / tool),disable_parallel_tool_use 被忽略 |
thinking | 支持(budget_tokens 被忽略) |
top_k | 被忽略 |
metadata | 被忽略 |
cache_control(tools 与消息内容块上的) | 被忽略 |
anthropic-beta、anthropic-version 请求头 | 被忽略 |
tool_result.is_error | 被忽略 |
不支持的内容块类型:image、document、search_result、 redacted_thinking、server_tool_use、 web_search_tool_result、code_execution_tool_result、 mcp_tool_use、mcp_tool_result、 container_upload。
模型回退:传入不支持的模型名时,DeepSeek 后端会静默映射到 deepseek-v4-flash。
在请求中包含您的 API 密钥:Authorization: Bearer om-your-api-key
位置: header
请求头参数
必填。指定 Anthropic API 版本。
"2023-06-01"请求体
application/json
TypeScript 类型定义
在 TypeScript 中使用 request body 类型。
响应体
application/json
application/json
application/json
application/json
curl -X POST "https://example.com/v1/messages" \ -H "anthropic-version: 2023-06-01" \ -H "Content-Type: application/json" \ -d '{ "model": "deepseek-v4-flash", "max_tokens": 1024, "messages": [ { "role": "user", "content": "Explain the concept of recursion in programming." } ] }'{
"id": "msg_01XFDUDYJgAACzvnptvVoYEL",
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "Recursion is a programming technique where a function calls itself to solve a problem by breaking it down into smaller, identical subproblems."
}
],
"model": "deepseek-v4-flash",
"stop_reason": "end_turn",
"usage": {
"input_tokens": 15,
"output_tokens": 168
}
}{
"type": "string",
"error": {
"type": "string",
"message": "string"
}
}{
"type": "string",
"error": {
"type": "string",
"message": "string"
}
}{
"type": "string",
"error": {
"type": "string",
"message": "string"
}
}- 示例模型
qwen3.7-maxqwen3.6-plusqwen3.6-max-previewqwen3.6-flashqwen3-max- 错误响应格式
- Messages 端点返回 DashScope 的原生错误格式——根级
code/type,不带error包装。 Responses 端点则使用标准的error.code+error.type结构。
以上为示例模型,可用列表可能变更。前往控制台查看全部可用模型
在请求中包含您的 API 密钥:Authorization: Bearer om-your-api-key
位置: header
请求头参数
必填。指定 Anthropic API 版本。
"2023-06-01"请求体
application/json
TypeScript 类型定义
在 TypeScript 中使用 request body 类型。
响应体
application/json
application/json
application/json
application/json
curl -X POST "https://example.com/v1/messages" \ -H "anthropic-version: 2023-06-01" \ -H "Content-Type: application/json" \ -d '{ "model": "qwen3-max", "max_tokens": 1024, "messages": [ { "role": "user", "content": "Explain the concept of recursion in programming." } ] }'{
"id": "msg_01XFDUDYJgAACzvnptvVoYEL",
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "Recursion is a programming technique where a function calls itself to solve a problem by breaking it down into smaller, identical subproblems."
}
],
"model": "qwen3-max",
"stop_reason": "end_turn",
"usage": {
"input_tokens": 15,
"output_tokens": 168
}
}{
"type": "string",
"error": {
"type": "string",
"message": "string"
}
}{
"type": "string",
"error": {
"type": "string",
"message": "string"
}
}{
"type": "string",
"error": {
"type": "string",
"message": "string"
}
}- 示例模型
mimo-v2-flashmimo-v2-omnimimo-v2-promimo-v2.5mimo-v2.5-pro- 错误响应格式
- Anthropic 兼容的
error.type格式。网关对529(API 过载)响应额外进行重试。
以上为示例模型,可用列表可能变更。前往控制台查看全部可用模型
在请求中包含您的 API 密钥:Authorization: Bearer om-your-api-key
位置: header
请求头参数
必填。指定 Anthropic API 版本。
"2023-06-01"请求体
application/json
TypeScript 类型定义
在 TypeScript 中使用 request body 类型。
响应体
application/json
application/json
application/json
application/json
curl -X POST "https://example.com/v1/messages" \ -H "anthropic-version: 2023-06-01" \ -H "Content-Type: application/json" \ -d '{ "model": "mimo-v2.5-pro", "max_tokens": 1024, "messages": [ { "role": "user", "content": "Explain the concept of recursion in programming." } ] }'{
"id": "msg_01XFDUDYJgAACzvnptvVoYEL",
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "Recursion is a programming technique where a function calls itself to solve a problem by breaking it down into smaller, identical subproblems."
}
],
"model": "mimo-v2.5-pro",
"stop_reason": "end_turn",
"usage": {
"input_tokens": 15,
"output_tokens": 168
}
}{
"type": "string",
"error": {
"type": "string",
"message": "string"
}
}{
"type": "string",
"error": {
"type": "string",
"message": "string"
}
}{
"type": "string",
"error": {
"type": "string",
"message": "string"
}
}- 示例模型
kimi-k2.5kimi-k2.6- 错误响应格式
- 标准 Anthropic
error.type格式。 - 官方文档
- Kimi 开放平台
以上为示例模型,可用列表可能变更。前往控制台查看全部可用模型
在请求中包含您的 API 密钥:Authorization: Bearer om-your-api-key
位置: header
请求头参数
必填。指定 Anthropic API 版本。
"2023-06-01"请求体
application/json
TypeScript 类型定义
在 TypeScript 中使用 request body 类型。
响应体
application/json
application/json
application/json
application/json
curl -X POST "https://example.com/v1/messages" \ -H "anthropic-version: 2023-06-01" \ -H "Content-Type: application/json" \ -d '{ "model": "claude-sonnet-4-6", "max_tokens": 1024, "messages": [ { "role": "user", "content": "Explain the concept of recursion in programming." } ] }'{
"id": "msg_01XFDUDYJgAACzvnptvVoYEL",
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "Recursion is a programming technique where a function calls itself to solve a problem by breaking it down into smaller, identical subproblems."
}
],
"model": "claude-sonnet-4-6",
"stop_reason": "end_turn",
"usage": {
"input_tokens": 15,
"output_tokens": 168
}
}{
"type": "string",
"error": {
"type": "string",
"message": "string"
}
}{
"type": "string",
"error": {
"type": "string",
"message": "string"
}
}{
"type": "string",
"error": {
"type": "string",
"message": "string"
}
}- 示例模型
MiniMax-M3MiniMax-M2.7MiniMax-M2.5- 错误响应格式
- 标准 Anthropic
error.type格式。 - 官方文档
- MiniMax 开放平台
以上为示例模型,可用列表可能变更。前往控制台查看全部可用模型
在请求中包含您的 API 密钥:Authorization: Bearer om-your-api-key
位置: header
请求头参数
必填。指定 Anthropic API 版本。
"2023-06-01"请求体
application/json
TypeScript 类型定义
在 TypeScript 中使用 request body 类型。
响应体
application/json
application/json
application/json
application/json
curl -X POST "https://example.com/v1/messages" \ -H "anthropic-version: 2023-06-01" \ -H "Content-Type: application/json" \ -d '{ "model": "claude-sonnet-4-6", "max_tokens": 1024, "messages": [ { "role": "user", "content": "Explain the concept of recursion in programming." } ] }'{
"id": "msg_01XFDUDYJgAACzvnptvVoYEL",
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "Recursion is a programming technique where a function calls itself to solve a problem by breaking it down into smaller, identical subproblems."
}
],
"model": "claude-sonnet-4-6",
"stop_reason": "end_turn",
"usage": {
"input_tokens": 15,
"output_tokens": 168
}
}{
"type": "string",
"error": {
"type": "string",
"message": "string"
}
}{
"type": "string",
"error": {
"type": "string",
"message": "string"
}
}{
"type": "string",
"error": {
"type": "string",
"message": "string"
}
}- 示例模型
glm-5.1glm-5glm-4.7- 错误响应格式
- 标准 Anthropic
error.type格式。 - 官方文档
- Zai 开放平台
以上为示例模型,可用列表可能变更。前往控制台查看全部可用模型
在请求中包含您的 API 密钥:Authorization: Bearer om-your-api-key
位置: header
请求头参数
必填。指定 Anthropic API 版本。
"2023-06-01"请求体
application/json
TypeScript 类型定义
在 TypeScript 中使用 request body 类型。
响应体
application/json
application/json
application/json
application/json
curl -X POST "https://example.com/v1/messages" \ -H "anthropic-version: 2023-06-01" \ -H "Content-Type: application/json" \ -d '{ "model": "claude-sonnet-4-6", "max_tokens": 1024, "messages": [ { "role": "user", "content": "Explain the concept of recursion in programming." } ] }'{
"id": "msg_01XFDUDYJgAACzvnptvVoYEL",
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "Recursion is a programming technique where a function calls itself to solve a problem by breaking it down into smaller, identical subproblems."
}
],
"model": "claude-sonnet-4-6",
"stop_reason": "end_turn",
"usage": {
"input_tokens": 15,
"output_tokens": 168
}
}{
"type": "string",
"error": {
"type": "string",
"message": "string"
}
}{
"type": "string",
"error": {
"type": "string",
"message": "string"
}
}{
"type": "string",
"error": {
"type": "string",
"message": "string"
}
}