其他模型 API 详细教程
其他模型 API 详细教程
- 模型路由:
https://token.matpool.com/v1- 路由规则与 OpenAI 标准一致
- 鉴权方式:
Authorization: Bearer YOUR_API_TOKEN
通用接口形式
所有模型均支持以下两种接口形式:
| 接口 | 路径 | 格式 | 适用模型 |
|---|---|---|---|
| Chat Completions | POST /v1/chat/completions | OpenAI 兼容格式,Authorization: Bearer <token> | 全部 16 个模型 |
| Messages | POST /v1/messages | Anthropic Messages 兼容格式,x-api-key: <token> + anthropic-version: 2023-06-01 | 全部 16 个模型 |
Messages 接口说明:Messages 接口使用 Anthropic 原生 API 格式。与 Chat Completions 不同,Messages 接口的鉴权头为
x-api-key,且需要携带anthropic-version头。该接口支持system顶层参数(非messages数组中的 system role)、max_tokens(必填)、stop_reason响应字段等 Anthropic 特有特性。
Messages 接口请求示例
bash复制代码curl https://token.matpool.com/v1/messages \ -H "Content-Type: application/json" \ -H "x-api-key: YOUR_API_TOKEN" \ -H "anthropic-version: 2023-06-01" \ -d '{ "model": "Claude-Sonnet-4.6", "max_tokens": 1024, "system": "You are a helpful assistant.", "messages": [ {"role": "user", "content": "Hello!"} ] }'
Messages 接口响应格式
json复制代码{ "id": "chatcmpl-xxx", "type": "message", "role": "assistant", "model": "claude-4.6-sonnet", "content": [ {"type": "text", "text": "Hello! How can I help you today?"} ], "stop_reason": "end_turn", "usage": { "input_tokens": 19, "output_tokens": 75 } }
Messages 接口流式输出
bash复制代码curl https://token.matpool.com/v1/messages \ -H "Content-Type: application/json" \ -H "x-api-key: YOUR_API_TOKEN" \ -H "anthropic-version: 2023-06-01" \ -d '{ "model": "Claude-Sonnet-4.6", "max_tokens": 1024, "stream": true, "messages": [ {"role": "user", "content": "用英文写一首关于春天的短诗"} ] }'
流式响应对应 Anthropic SSE 事件格式(message_start、content_block_start、content_block_delta、message_delta、message_stop)。
跨模型支持:Messages 接口除了 Claude 系列模型外,也适用于 GPT、Gemini、Grok 系列的所有模型。
system参数在所有模型上均可正常工作。
一、Google Gemini 模型
1.1 支持的模型
| 模型名称 | 说明 | 特点 |
|---|---|---|
| Gemini-3.5-Flash | Google Gemini 3.5 Flash | 轻量快速,低延迟,成本更优,适合高频对话 |
| Gemini-3.1-Flash | Google Gemini 3.1 Flash | 轻量推理模型,价格便宜,支持联网搜索、代码执行 |
| Gemini-3.1-Pro | Google Gemini 3.1 Pro | 旗舰推理模型,支持深度思考(Thinking Levels),支持媒体解析(最高 ULTRA_HIGH),支持流式函数调用 |
1.2 接口地址
Gemini 模型支持两种接口形式:
Chat Completions 接口
text复制代码POST https://token.matpool.com/v1/chat/completions
Messages 接口(Anthropic 原生格式,跨模型通用)
text复制代码POST https://token.matpool.com/v1/messages
Messages 接口为跨模型通用接口,适用于所有模型。通用说明和示例请参见上文通用接口形式章节。
1.3 请求参数(Chat Completions)
通用参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
model | string | 是 | — | 模型名称,如 Gemini-3.5-Flash、Gemini-3.1-Flash 或 Gemini-3.1-Pro |
messages | array | 是 | — | 对话消息列表;role 支持 system、user、assistant |
temperature | number | 否 | 1.0 | 生成随机性,范围 0.0 ~ 2.0 |
top_p | number | 否 | — | 核采样阈值,范围 0.0 ~ 1.0 |
max_tokens | integer | 否 | 模型默认 | 最大输出 Token 数 |
stream | boolean | 否 | false | 是否开启流式输出(SSE) |
stop | string / array | 否 | — | 停止序列,最多 5 个 |
seed | integer | 否 | — | 随机种子,用于提高结果可复现性 |
tools | array | 否 | — | 工具定义(Function Calling),同时支持 googleSearch 和 codeExecution 特殊工具 |
tool_choice | string / object | 否 | auto | 工具选择策略:auto、none、required 或指定函数对象 |
response_format | object | 否 | — | 输出格式控制,{ "type": "json_object" } 或 { "type": "json_schema", "json_schema": {...} } |
Gemini 特有参数(通过 extra_body 传递)
Gemini 特有参数通过 extra_body.google 传入,不会影响 OpenAI 兼容性。
json复制代码{ "model": "Gemini-3.1-Pro", "messages": [...], "extra_body": { "google": { "thinking_config": { "thinking_level": "HIGH", "include_thoughts": true } } } }
thinking_config 参数
| 参数 | 类型 | 说明 |
|---|---|---|
thinking_level | string | 思考强度级别。"HIGH"(默认,适用于复杂推理)、"MEDIUM"(平衡模式)、"LOW"(快速响应,适合高吞吐任务)。仅 Gemini-3.1-Pro 支持。 |
thinking_budget | integer | 思考预算 Token 数。设为 0 可禁用思考。 |
include_thoughts | boolean | 是否在响应中包含思考过程。 |
1.4 多模态输入
Gemini 模型原生支持多种媒体类型输入,通过 OpenAI 兼容的 content 数组传入:
| 类型 | 示例 |
|---|---|
| 文本 | { "type": "text", "text": "..." } |
| 图片 | { "type": "image_url", "image_url": { "url": "https://..." } } |
| 图片(Base64) | { "type": "image_url", "image_url": { "url": "data:image/jpeg;base64,..." } } |
支持的图片 MIME 类型:image/png、image/jpeg、image/webp、image/heic、image/heif。
1.5 调用示例
以下所有示例均使用 curl,您可将 YOUR_API_TOKEN 替换为自己的 API Key 进行测试。
基础文本对话(Gemini-3.1-Pro)
bash复制代码curl https://token.matpool.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -d '{ "model": "Gemini-3.1-Pro", "messages": [ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "介绍一下 Gemini 3.1 Pro 的核心能力" } ], "temperature": 0.7, "max_tokens": 2048 }'
基础文本对话(Gemini-3.5-Flash)
bash复制代码curl https://token.matpool.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -d '{ "model": "Gemini-3.5-Flash", "messages": [ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "用一句话介绍量子计算" } ], "temperature": 0.7, "max_tokens": 1024 }'
基础文本对话(Gemini-3.1-Flash)
bash复制代码curl https://token.matpool.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -d '{ "model": "Gemini-3.1-Flash", "messages": [ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "用一句话介绍量子计算" } ], "temperature": 0.7, "max_tokens": 1024 }'
启用深度思考(Gemini-3.1-Pro)
通过 extra_body.google.thinking_config 控制思考级别:
bash复制代码curl https://token.matpool.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -d '{ "model": "Gemini-3.1-Pro", "messages": [ { "role": "user", "content": "设计一个高并发消息队列的架构方案,要求支持百万级 QPS" } ], "extra_body": { "google": { "thinking_config": { "thinking_level": "HIGH", "include_thoughts": true } } } }'
流式输出
bash复制代码curl https://token.matpool.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -d '{ "model": "Gemini-3.5-Flash", "messages": [ { "role": "user", "content": "用英文写一首关于春天的短诗" } ], "stream": true }'
多模态输入(图片理解)
bash复制代码curl https://token.matpool.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -d '{ "model": "Gemini-3.1-Pro", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "请详细描述这张图片的内容" }, { "type": "image_url", "image_url": { "url": "https://cdn.matpool.com/images/159cfc58_opt_token1.png" } } ] } ], "max_tokens": 1024 }'
Function Calling
bash复制代码curl https://token.matpool.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -d '{ "model": "Gemini-3.1-Pro", "messages": [ { "role": "user", "content": "上海今天天气怎么样?" } ], "tools": [ { "type": "function", "function": { "name": "get_weather", "description": "获取指定城市的天气信息", "parameters": { "type": "object", "properties": { "city": { "type": "string", "description": "城市名称" } }, "required": ["city"] } } } ], "tool_choice": "auto" }'
联网搜索(Google Search)
Gemini 支持通过特殊工具名 googleSearch 启用联网搜索:
bash复制代码curl https://token.matpool.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -d '{ "model": "Gemini-3.5-Flash", "messages": [ { "role": "user", "content": "2026年最新AI技术趋势是什么?" } ], "tools": [ { "type": "function", "function": { "name": "googleSearch", "description": "搜索网络获取最新信息", "parameters": { "type": "object", "properties": {} } } } ] }'
结构化输出(JSON Schema)
bash复制代码curl https://token.matpool.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -d '{ "model": "Gemini-3.1-Pro", "messages": [ { "role": "user", "content": "列出5本科幻小说,包含书名、作者和出版年份" } ], "response_format": { "type": "json_schema", "json_schema": { "name": "books", "strict": true, "schema": { "type": "object", "properties": { "books": { "type": "array", "items": { "type": "object", "properties": { "title": { "type": "string" }, "author": { "type": "string" }, "year": { "type": "integer" } }, "required": ["title", "author", "year"] } } }, "required": ["books"] } } } }'
1.6 响应格式
标准 OpenAI Chat Completions 响应格式:
json复制代码{ "id": "chatcmpl-xxx", "object": "chat.completion", "created": 1718000000, "model": "Gemini-3.1-Pro", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "Gemini 3.1 Pro 是 Google 最新的推理模型..." }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 50, "completion_tokens": 200, "total_tokens": 250 } }
1.7 模型对比
| 特性 | Gemini-3.5-Flash | Gemini-3.1-Flash | Gemini-3.1-Pro |
|---|---|---|---|
| 定位 | 轻量快速模型 | 轻量经济模型 | 旗舰推理模型 |
| Thinking Levels | 有限支持 | 不支持 | LOW / MEDIUM / HIGH |
| 媒体解析 | 标准 | 标准 | ULTRA_HIGH |
| Function Calling | 支持 | 支持 | 支持(含流式) |
| 联网搜索 | 支持 | 支持 | 支持 |
| 代码执行 | 支持 | 支持 | 支持 |
| 结构化输出 | 支持 | 支持 | 支持 |
| 延迟 | 低 | 最低 | 较高(深度思考时) |
| 适用场景 | 高频对话、快速响应、成本敏感场景 | 高吞吐经济场景、简单推理 | 复杂推理、代码生成、多步规划、高级分析 |
1.8 注意事项
- 模型名称大小写敏感,请严格按
Gemini-3.5-Flash、Gemini-3.1-Flash和Gemini-3.1-Pro填写 - Gemini-3.1-Pro 的思考级别(
thinking_level)不能与旧的thinking_budget同时使用,否则会返回 400 错误;Gemini-3.1-Flash 不支持思考配置 - 流式输出时思考内容会先于文本内容返回,客户端需正确处理
- 联网搜索(
googleSearch)和代码执行(codeExecution)通过特殊命名的 Function Calling 工具启用 - Safety Settings 由平台自动配置,用户无需手动设置
- Gemini 对图片和文件的 MIME 类型有严格校验,不支持的格式会返回错误
二、Claude 模型
2.1 支持的模型
| 模型名称 | 说明 | 特点 |
|---|---|---|
| Claude-Fable-5 | Anthropic Claude Fable 5 | 最新旗舰模型,强力推理、编码与多模态,支持联网搜索 |
| Claude-Opus-4.8 | Anthropic Claude Opus 4.8 | 最新 Opus 模型,性能强劲,支持缓存 |
| Claude-Opus-4.7 | Anthropic Claude Opus 4.7 | Opus 4.7 旗舰推理模型,深度思考时需清除 temperature 等参数 |
| Claude-Opus-4.6 | Anthropic Claude Opus 4.6 | Opus 4.6 旗舰推理模型,支持 adaptive thinking |
| Claude-Sonnet-4.6 | Anthropic Claude Sonnet 4.6 | 高性价比模型,速度与质量平衡 |
2.2 接口地址
Claude 模型支持两种接口形式:
Chat Completions 接口
text复制代码POST https://token.matpool.com/v1/chat/completions
Messages 接口(Anthropic 原生格式,推荐)
text复制代码POST https://token.matpool.com/v1/messages
Claude 模型推荐使用 Messages 接口,该接口为 Anthropic 原生 API 格式。鉴权使用 x-api-key 头(非 Authorization: Bearer),需携带 anthropic-version: 2023-06-01 头。system 提示词使用顶层 system 参数而非 messages 中的 system role。通用 Messages 接口说明和示例请参见上文通用接口形式章节。
2.3 请求参数(Chat Completions)
通用参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
model | string | 是 | — | 模型名称,如 Claude-Sonnet-4.6 |
messages | array | 是 | — | 对话消息列表;role 支持 system、user、assistant、tool |
max_tokens | integer | 否 | 模型默认 | 最大输出 Token 数 |
temperature | number | 否 | 1.0 | 生成随机性,范围 0.0 ~ 1.0 |
top_p | number | 否 | — | 核采样阈值,范围 0.0 ~ 1.0 |
top_k | integer | 否 | — | Top-K 采样 |
stream | boolean | 否 | false | 是否开启流式输出(SSE) |
stop | string / array | 否 | — | 停止序列,最多 4 个 |
tools | array | 否 | — | 工具定义(Function Calling) |
tool_choice | string / object | 否 | auto | 工具选择策略:auto、any、none 或 {"type":"tool","name":"..."} |
parallel_tool_calls | boolean | 否 | true | 是否允许并行工具调用 |
response_format | object | 否 | — | 输出格式控制,{ "type": "json_object" } |
扩展思考参数(Extended Thinking)
通过 reasoning_effort 参数控制思考深度:
| 取值 | 说明 |
|---|---|
"low" | 低思考预算(1280 tokens) |
"medium" | 中等思考预算(2048 tokens) |
"high" | 高思考预算(4096 tokens) |
联网搜索
通过 web_search_options 参数启用联网搜索:
json复制代码{ "web_search_options": { "search_context_size": "medium" } }
search_context_size 取值:
| 取值 | 说明 |
|---|---|
"low" | 最多 1 次搜索调用 |
"medium" | 最多 5 次搜索调用 |
"high" | 最多 10 次搜索调用 |
多模态输入
Claude 模型支持图片和 PDF 输入,通过 OpenAI 兼容的 content 数组传入:
| 类型 | 示例 |
|---|---|
| 文本 | { "type": "text", "text": "..." } |
| 图片 | { "type": "image_url", "image_url": { "url": "https://..." } } |
| 图片(Base64) | { "type": "image_url", "image_url": { "url": "data:image/jpeg;base64,..." } } |
支持的图片 MIME 类型:image/png、image/jpeg、image/webp、image/gif。
2.4 调用示例
以下所有示例均使用 curl,您可将 YOUR_API_TOKEN 替换为自己的 API Key 进行测试。
基础文本对话
bash复制代码curl https://token.matpool.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -d '{ "model": "Claude-Sonnet-4.6", "messages": [ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "介绍一下 Claude Sonnet 4.6 的核心能力" } ], "temperature": 0.7, "max_tokens": 1024 }'
启用扩展思考(reasoning_effort)
bash复制代码curl https://token.matpool.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -d '{ "model": "Claude-Opus-4.6", "messages": [ { "role": "user", "content": "设计一个高并发消息队列的架构方案" } ], "max_tokens": 2048, "reasoning_effort": "high" }'
流式输出
bash复制代码curl https://token.matpool.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -d '{ "model": "Claude-Sonnet-4.6", "messages": [ { "role": "user", "content": "用英文写一首关于春天的短诗" } ], "stream": true, "max_tokens": 1024 }'
联网搜索
bash复制代码curl https://token.matpool.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -d '{ "model": "Claude-Sonnet-4.6", "messages": [ { "role": "user", "content": "2026年最新AI技术趋势是什么?" } ], "web_search_options": { "search_context_size": "medium" }, "max_tokens": 2048 }'
Function Calling
bash复制代码curl https://token.matpool.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -d '{ "model": "Claude-Sonnet-4.6", "messages": [ { "role": "user", "content": "北京今天天气怎么样?" } ], "tools": [ { "type": "function", "function": { "name": "get_weather", "description": "获取指定城市的天气信息", "parameters": { "type": "object", "properties": { "city": { "type": "string", "description": "城市名称" } }, "required": ["city"] } } } ], "tool_choice": "auto", "max_tokens": 1024 }'
多模态输入(图片理解)
bash复制代码curl https://token.matpool.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -d '{ "model": "Claude-Sonnet-4.6", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "请详细描述这张图片的内容" }, { "type": "image_url", "image_url": { "url": "https://cdn.matpool.com/images/159cfc58_opt_token1.png" } } ] } ], "max_tokens": 1024 }'
2.5 响应格式
标准 OpenAI Chat Completions 响应格式:
json复制代码{ "id": "chatcmpl-xxx", "object": "chat.completion", "created": 1718000000, "model": "claude-4.6-sonnet", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "Claude Sonnet 4.6 是 Anthropic 最新的..." }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 50, "completion_tokens": 200, "total_tokens": 250 } }
启用扩展思考时,响应会包含 reasoning_content 字段:
json复制代码{ "choices": [ { "index": 0, "message": { "role": "assistant", "content": "最终输出文本...", "reasoning_content": "思考过程..." }, "finish_reason": "end_turn" } ] }
2.6 模型对比
| 特性 | Claude-Fable-5 | Claude-Opus-4.8 | Claude-Opus-4.7 | Claude-Opus-4.6 | Claude-Sonnet-4.6 |
|---|---|---|---|---|---|
| 定位 | 最新旗舰 | 最新 Opus | Opus 旗舰 | Opus 旗舰 | 高性价比 |
| 扩展思考 | 支持 | 支持 | 支持 | 支持 | — |
| adaptive thinking | — | — | 支持 | 支持 | — |
| 联网搜索 | 支持 | 支持 | 支持 | 支持 | 支持 |
| 图片理解 | 支持 | 支持 | 支持 | 支持 | 支持 |
| Function Calling | 支持 | 支持 | 支持 | 支持 | 支持 |
| 流式输出 | 支持 | 支持 | 支持 | 支持 | 支持 |
| 结构化输出 | 支持 | 支持 | 支持 | 支持 | 支持 |
| 缓存支持 | 支持 | 支持 | — | — | — |
| 延迟 | 中等 | 中等 | 较高 | 较高 | 低 |
2.7 注意事项
- 模型名称大小写敏感,请严格按表格中的名称填写
- 启用扩展思考时,Claude-Opus-4.7 会自动清除
temperature、top_p、top_k参数(Opus 4.7 在思考模式下会拒绝这些参数) - 扩展思考的
budget_tokens必须 >= 1024,且小于max_tokens - 联网搜索(
web_search_options)为顶层参数,非tools数组内的工具 - Prompt Caching 自动对 system prompt 生效,无需手动设置
- 图片输入自动转换为 Base64 格式发送给上游
三、GPT 模型
3.1 支持的模型
| 模型名称 | 说明 | 特点 |
|---|---|---|
| GPT-5.5 | OpenAI GPT-5.5 | 最新 GPT 模型,全面升级推理、编码与多模态能力 |
| GPT-5.5-High | OpenAI GPT-5.5 High | GPT-5.5 高性能版,更强的推理深度 |
| GPT-5.4 | OpenAI GPT-5.4 | 旗舰推理模型,支持深度推理(reasoning_effort) |
| GPT-5.4-Pro | OpenAI GPT-5.4 Pro | 专业版,极致推理性能 |
| GPT-5.4-Mini | OpenAI GPT-5.4 Mini | 轻量经济模型,适合高频对话 |
| GPT-5.4-Nano | OpenAI GPT-5.4 Nano | 最轻量模型,极致性价比 |
3.2 接口地址
GPT 模型支持两种接口形式:
Chat Completions 接口(全部 GPT 模型)
text复制代码POST https://token.matpool.com/v1/chat/completions
Response API 接口(仅 GPT-5.5)
text复制代码POST https://token.matpool.com/v1/responses
Response API 说明:Response API 是 OpenAI 推出的新一代接口,使用
Authorization: Bearer <token>鉴权,支持input字段替代messages,响应格式为output数组。目前仅 GPT-5.5 支持该接口。GPT-5.4-Mini、GPT-5.4-Nano、GPT-5.4-Pro、GPT-5.5-High 等模型暂不支持。
Response API 请求示例
bash复制代码curl https://token.matpool.com/v1/responses \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -d '{ "model": "GPT-5.5", "input": "用一句话介绍量子计算" }'
Response API 响应格式
json复制代码{ "id": "resp_xxx", "object": "response", "status": "completed", "model": "gpt-5.5", "output": [ { "type": "message", "role": "assistant", "content": [ { "type": "output_text", "text": "量子计算是利用量子力学原理..." } ] } ], "usage": { "input_tokens": 5093, "output_tokens": 47, "total_tokens": 5140 } }
Response API 流式输出
bash复制代码curl https://token.matpool.com/v1/responses \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -d '{ "model": "GPT-5.5", "input": "用英文写一首关于春天的短诗", "stream": true }'
流式响应对应 OpenAI Response API SSE 事件格式(response.created、response.in_progress、response.output_text.delta、response.completed)。
3.3 请求参数(Chat Completions)
通用参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
model | string | 是 | — | 模型名称,如 GPT-5.5 |
messages | array | 是 | — | 对话消息列表;role 支持 system、user、assistant、developer |
max_tokens | integer | 否 | 模型默认 | 最大输出 Token 数(Chat Completions 格式) |
max_completion_tokens | integer | 否 | — | 最大输出 Token 数(GPT-5.5 推荐使用) |
temperature | number | 否 | 1.0 | 生成随机性,范围 0.0 ~ 2.0 |
top_p | number | 否 | — | 核采样阈值,范围 0.0 ~ 1.0 |
stream | boolean | 否 | false | 是否开启流式输出(SSE) |
stop | string / array | 否 | — | 停止序列 |
tools | array | 否 | — | 工具定义(Function Calling),支持 web_search_preview 等特殊工具 |
tool_choice | string / object | 否 | auto | 工具选择策略:auto、none、required 或指定函数对象 |
parallel_tool_calls | boolean | 否 | true | 是否允许并行工具调用 |
response_format | object | 否 | — | 输出格式控制,{ "type": "json_object" } |
seed | integer | 否 | — | 随机种子,用于提高结果可复现性 |
推理参数
通过 reasoning_effort 控制模型推理深度:
| 取值 | 说明 |
|---|---|
"none" | 不启用推理 |
"low" | 低推理预算 |
"medium" | 中等推理预算 |
"high" | 高推理预算 |
"xhigh" | 最高推理预算 |
联网搜索
通过 tools 数组中的 web_search_preview 工具启用联网搜索:
json复制代码{ "tools": [ { "type": "web_search_preview" } ], "tool_choice": "auto" }
3.4 调用示例
以下所有示例均使用 curl,您可将 YOUR_API_TOKEN 替换为自己的 API Key 进行测试。
基础文本对话(GPT-5.5)
bash复制代码curl https://token.matpool.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -d '{ "model": "GPT-5.5", "messages": [ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "介绍一下 GPT-5.5 的核心能力" } ], "temperature": 0.7, "max_tokens": 1024 }'
基础文本对话(GPT-5.4-Mini)
bash复制代码curl https://token.matpool.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -d '{ "model": "GPT-5.4-Mini", "messages": [ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "用一句话介绍量子计算" } ], "temperature": 0.7, "max_tokens": 1024 }'
启用深度推理(reasoning_effort)
bash复制代码curl https://token.matpool.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -d '{ "model": "GPT-5.5", "messages": [ { "role": "user", "content": "设计一个高并发消息队列的架构方案" } ], "reasoning_effort": "high", "max_tokens": 2048 }'
流式输出
bash复制代码curl https://token.matpool.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -d '{ "model": "GPT-5.5", "messages": [ { "role": "user", "content": "用英文写一首关于春天的短诗" } ], "stream": true, "max_tokens": 1024 }'
联网搜索
bash复制代码curl https://token.matpool.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -d '{ "model": "GPT-5.5", "messages": [ { "role": "user", "content": "2026年最新AI技术趋势是什么?" } ], "tools": [ { "type": "web_search_preview" } ], "tool_choice": "auto", "max_tokens": 2048 }'
Function Calling
bash复制代码curl https://token.matpool.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -d '{ "model": "GPT-5.5", "messages": [ { "role": "user", "content": "上海今天天气怎么样?" } ], "tools": [ { "type": "function", "function": { "name": "get_weather", "description": "获取指定城市的天气信息", "parameters": { "type": "object", "properties": { "city": { "type": "string", "description": "城市名称" } }, "required": ["city"] } } } ], "tool_choice": "auto" }'
结构化输出(JSON Object)
bash复制代码curl https://token.matpool.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -d '{ "model": "GPT-5.5", "messages": [ { "role": "user", "content": "列出5本科幻小说,包含书名、作者和出版年份,以JSON格式返回" } ], "response_format": { "type": "json_object" } }'
3.5 响应格式
标准 OpenAI Chat Completions 响应格式:
json复制代码{ "id": "chatcmpl-xxx", "object": "chat.completion", "created": 1718000000, "model": "gpt-5.5", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "GPT-5.5 是 OpenAI 最新的..." }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 50, "completion_tokens": 200, "total_tokens": 250, "prompt_tokens_details": { "cached_tokens": 0 } } }
3.6 模型对比
| 特性 | GPT-5.5 | GPT-5.5-High | GPT-5.4 | GPT-5.4-Pro | GPT-5.4-Mini | GPT-5.4-Nano |
|---|---|---|---|---|---|---|
| 定位 | 最新全能 | 高性能版 | 旗舰推理 | 专业版 | 轻量经济 | 极致轻量 |
| 深度推理 | 支持 | 支持 | 支持 | 支持 | — | — |
| 联网搜索 | 支持 | 支持 | 支持 | 支持 | 支持 | 支持 |
| Function Calling | 支持 | 支持 | 支持 | 支持 | 支持 | 支持 |
| 结构化输出 | json_object | json_object | json_object | json_object | json_object | json_object |
| 流式输出 | 支持 | 支持 | 支持 | 支持 | 支持 | 支持 |
| 缓存支持 | 支持 | 支持 | — | — | — | — |
| 延迟 | 中等 | 中等 | 较低 | 较高 | 低 | 最低 |
3.7 注意事项
- 模型名称大小写敏感,请严格按表格中的名称填写
reasoning_effort可取值none、low、medium、high、xhigh,部分模型可能不支持所有级别- 联网搜索通过
tools中type: "web_search_preview"启用,非 function calling 格式 max_completion_tokens为 GPT-5.5 推荐使用的最大输出参数,max_tokens同样兼容- 缓存(Prompt Caching)自动生效,用户无需手动配置
- GPT-5.5 系列支持
response_format: { "type": "json_object" }结构化输出,暂不适用于 json_schema
四、Grok 模型
4.1 支持的模型
| 模型名称 | 说明 | 特点 |
|---|---|---|
| Grok-4.1-Fast | xAI Grok 4.1 Fast | 轻量快速模型,低延迟,适合高频对话 |
| Grok-4.1-Fast-Reasoning | xAI Grok 4.1 Fast Reasoning | 支持推理能力的版本,适合需要深度思考的场景 |
4.2 接口地址
Grok 模型支持两种接口形式:
Chat Completions 接口
text复制代码POST https://token.matpool.com/v1/chat/completions
Messages 接口(Anthropic 原生格式,跨模型通用)
text复制代码POST https://token.matpool.com/v1/messages
Messages 接口为跨模型通用接口,适用于所有模型。通用说明和示例请参见上文通用接口形式章节。
4.3 请求参数(Chat Completions)
通用参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
model | string | 是 | — | 模型名称,如 Grok-4.1-Fast 或 Grok-4.1-Fast-Reasoning |
messages | array | 是 | — | 对话消息列表;role 支持 system、user、assistant |
max_tokens | integer | 否 | 模型默认 | 最大输出 Token 数 |
temperature | number | 否 | 1.0 | 生成随机性,范围 0.0 ~ 2.0 |
top_p | number | 否 | — | 核采样阈值,范围 0.0 ~ 1.0 |
stream | boolean | 否 | false | 是否开启流式输出(SSE) |
stop | string / array | 否 | — | 停止序列 |
tools | array | 否 | — | 工具定义(Function Calling) |
tool_choice | string / object | 否 | auto | 工具选择策略:auto、none、required 或指定函数对象 |
response_format | object | 否 | — | 输出格式控制,{ "type": "json_object" } |
seed | integer | 否 | — | 随机种子,用于提高结果可复现性 |
推理参数
Grok-4.1-Fast-Reasoning 支持通过 reasoning_effort 控制推理深度:
| 取值 | 说明 |
|---|---|
"low" | 低推理预算 |
"medium" | 中等推理预算 |
"high" | 高推理预算 |
4.4 调用示例
以下所有示例均使用 curl,您可将 YOUR_API_TOKEN 替换为自己的 API Key 进行测试。
基础文本对话(Grok-4.1-Fast)
bash复制代码curl https://token.matpool.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -d '{ "model": "Grok-4.1-Fast", "messages": [ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "介绍一下 Grok 4.1 Fast 的核心能力" } ], "temperature": 0.7, "max_tokens": 1024 }'
基础文本对话(Grok-4.1-Fast-Reasoning)
bash复制代码curl https://token.matpool.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -d '{ "model": "Grok-4.1-Fast-Reasoning", "messages": [ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "设计一个高并发消息队列的架构方案" } ], "reasoning_effort": "high", "max_tokens": 2048 }'
流式输出
bash复制代码curl https://token.matpool.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -d '{ "model": "Grok-4.1-Fast", "messages": [ { "role": "user", "content": "用英文写一首关于春天的短诗" } ], "stream": true, "max_tokens": 1024 }'
Function Calling
bash复制代码curl https://token.matpool.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -d '{ "model": "Grok-4.1-Fast", "messages": [ { "role": "user", "content": "上海今天天气怎么样?" } ], "tools": [ { "type": "function", "function": { "name": "get_weather", "description": "获取指定城市的天气信息", "parameters": { "type": "object", "properties": { "city": { "type": "string", "description": "城市名称" } }, "required": ["city"] } } } ], "tool_choice": "auto" }'
4.5 响应格式
标准 OpenAI Chat Completions 响应格式:
json复制代码{ "id": "chatcmpl-xxx", "object": "chat.completion", "created": 1718000000, "model": "Grok-4.1-Fast", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "Grok 4.1 Fast 是 xAI 推出的..." }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 50, "completion_tokens": 200, "total_tokens": 250 } }
4.6 模型对比
| 特性 | Grok-4.1-Fast | Grok-4.1-Fast-Reasoning |
|---|---|---|
| 定位 | 轻量快速模型 | 推理增强版 |
| 深度推理 | — | 支持(reasoning_effort) |
| Function Calling | 支持 | 支持 |
| 流式输出 | 支持 | 支持 |
| 结构化输出 | 支持 | 支持 |
| 延迟 | 低 | 中等 |
4.7 注意事项
- 模型名称大小写敏感,请严格按表格中的名称填写
- Grok-4.1-Fast-Reasoning 启用推理时,响应中会返回
reasoning_content字段 - 两类模型均兼容标准 OpenAI 请求格式
五、费用说明
按标准 Token 计费模式:
- 费用 = (输入 Token ÷ 1,000,000) × 输入单价 + (输出 Token ÷ 1,000,000) × 输出单价
- 启用思考模式时,思考过程 Token 按输出 Token 计费
- 多媒体输入按对应 Token 换算计费
- 具体单价请参考 模型广场
六、推荐的 SDK 配置
Chat Completions 接口(OpenAI SDK)
Matpool 接口与 OpenAI 规范兼容,推荐使用 OpenAI 官方 SDK,只需覆盖 base_url:
Python
python复制代码from openai import OpenAI client = OpenAI( api_key="YOUR_API_TOKEN", base_url="https://token.matpool.com/v1" ) response = client.chat.completions.create( model="Gemini-3.5-Flash", messages=[ {"role": "user", "content": "Hello!"} ] )
Node.js
javascript复制代码import OpenAI from "openai"; const openai = new OpenAI({ apiKey: "YOUR_API_TOKEN", baseURL: "https://token.matpool.com/v1" }); const completion = await openai.chat.completions.create({ model: "Gemini-3.5-Flash", messages: [{ role: "user", content: "Hello!" }] });
Messages 接口(Anthropic SDK)
Messages 接口兼容 Anthropic 官方 SDK,只需覆盖 base_url:
Python
python复制代码from anthropic import Anthropic client = Anthropic( api_key="YOUR_API_TOKEN", base_url="https://token.matpool.com/v1" ) message = client.messages.create( model="Claude-Sonnet-4.6", max_tokens=1024, system="You are a helpful assistant.", messages=[ {"role": "user", "content": "Hello!"} ] ) print(message.content[0].text)
Node.js
javascript复制代码import Anthropic from "@anthropic-ai/sdk"; const anthropic = new Anthropic({ apiKey: "YOUR_API_TOKEN", baseURL: "https://token.matpool.com/v1" }); const message = await anthropic.messages.create({ model: "Claude-Sonnet-4.6", max_tokens: 1024, system: "You are a helpful assistant.", messages: [{ role: "user", content: "Hello!" }] }); console.log(message.content[0].text);
Response API 接口(OpenAI SDK)
GPT-5.5 支持 OpenAI 最新的 Response API,可使用 OpenAI SDK 的 responses.create 方法:
Python
python复制代码from openai import OpenAI client = OpenAI( api_key="YOUR_API_TOKEN", base_url="https://token.matpool.com/v1" ) response = client.responses.create( model="GPT-5.5", input="用一句话介绍量子计算" ) print(response.output[0].content[0].text)