Get started
OpenAI 兼容 API
MinT 在 /oai/api/v1 上提供了一个 OpenAI 兼容的 HTTP 接口。把任意 OpenAI SDK
或 HTTP 客户端指向这个前缀,就能对已部署的 MinT 模型做推理,不需要 import
mint 或 tinker。
概念
和 MinT 通信有两种方式,分别用于不同场景:
- 原生
mintSDK —— 训练、RL 循环、边训练边采样。你自己写训练循环时用它。 参见 MinT CLI。 - OpenAI 兼容 API —— 对已经部署好的模型做纯推理。当你只想用现有的 OpenAI SDK 代码做 completions、chat 或工具调用时用它。
本页讲第二种。
这个接口用于对已部署模型做推理。它不会启动、训练或微调任何东西。训练请用原生 SDK。
配置
兼容前缀为:
http://<host>:<port>/oai/api/v1本地示例:
http://127.0.0.1:8000/oai/api/v1按区域选择托管地址:
- 中国大陆以外:
https://mint.macaron.xin/oai/api/v1 - 中国大陆:
https://mint-cn.macaron.xin/oai/api/v1
API key 传你真实的 MinT key。如果服务端没开鉴权,任意非空字符串都可以 —— 示例
里用的是 dummy。
安装 SDK:
pip install openai快速开始
from openai import OpenAI
client = OpenAI(
base_url="http://127.0.0.1:8000/oai/api/v1",
api_key="dummy",
)
resp = client.chat.completions.create(
model="Qwen/Qwen3-30B-A3B-Instruct-2507",
messages=[{"role": "user", "content": "Reply with exactly: pong"}],
max_tokens=16,
temperature=0.0,
)
print(resp.choices[0].message.content)已支持的能力
已在真实 MinT 服务上验证:
client.models.list()client.models.retrieve(model_id)client.completions.create(...)(legacy completions)client.chat.completions.create(...)tools以及完整的工具调用 roundtripOpenAI和AsyncOpenAI两种客户端- 小规模并发 async chat
暂不支持
下面这些会明确报错,而不是鉴权失败:
| 调用 | 结果 |
|---|---|
stream=True | stream=True is not supported |
n > 1 | Only n=1 is supported |
client.responses.create(...) | HTTP 404 |
client.embeddings.create(...) | HTTP 404 |
示例
列出与获取模型
from openai import OpenAI
client = OpenAI(base_url="http://127.0.0.1:8000/oai/api/v1", api_key="dummy")
for model in client.models.list().data:
print(model.id)
print(client.models.retrieve("Qwen/Qwen3-30B-A3B-Instruct-2507"))Legacy completions
resp = client.completions.create(
model="Qwen/Qwen3-30B-A3B-Instruct-2507",
prompt="The capital of France is",
max_tokens=16,
temperature=0.1,
)
print(resp.choices[0].text)Chat completions
resp = client.chat.completions.create(
model="Qwen/Qwen3-30B-A3B-Instruct-2507",
messages=[
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "Reply with exactly: pong"},
],
max_tokens=16,
temperature=0.0,
)
print(resp.choices[0].message.content)工具调用 roundtrip
传入 tools,读回 tool_calls,自己执行工具,再把结果用 tool 消息发回去拿到
最终回答。
import json
from openai import OpenAI
client = OpenAI(base_url="http://127.0.0.1:8000/oai/api/v1", api_key="dummy")
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather for a city",
"parameters": {
"type": "object",
"properties": {"location": {"type": "string"}},
"required": ["location"],
},
},
}
]
question = "北京天气如何?请调用工具后再回答。"
first = client.chat.completions.create(
model="Qwen/Qwen3-30B-A3B-Instruct-2507",
messages=[{"role": "user", "content": question}],
tools=tools,
tool_choice="required", # 强制模型先调工具再回答
max_tokens=128,
temperature=0.1,
)
call = first.choices[0].message.tool_calls[0]
second = client.chat.completions.create(
model="Qwen/Qwen3-30B-A3B-Instruct-2507",
messages=[
{"role": "user", "content": question},
{
"role": "assistant",
"content": None,
"tool_calls": [
{
"id": call.id,
"type": "function",
"function": {
"name": call.function.name,
"arguments": call.function.arguments,
},
}
],
},
{
"role": "tool",
"tool_call_id": call.id,
"content": json.dumps(
{"location": "北京", "weather": "晴,18摄氏度"},
ensure_ascii=False,
),
},
],
tools=tools,
max_tokens=128,
temperature=0.1,
)
print(second.choices[0].message.content)异步客户端
import asyncio
from openai import AsyncOpenAI
client = AsyncOpenAI(base_url="http://127.0.0.1:8000/oai/api/v1", api_key="dummy")
async def main():
resp = await client.chat.completions.create(
model="Qwen/Qwen3-30B-A3B-Instruct-2507",
messages=[{"role": "user", "content": "Reply with exactly: async-pong"}],
max_tokens=16,
temperature=0.0,
)
print(resp.choices[0].message.content)
asyncio.run(main())在 quickstart 里试一下
mint-quickstart 仓库提供 了这些调用的可运行版本:
MINT_BASE_URL=http://127.0.0.1:8000 \
MINT_API_KEY=dummy \
python quickstart/openai_compat.py chat \
--model Qwen/Qwen3-30B-A3B-Instruct-2507 \
--user-message "Reply with exactly: pong"脚本有 completions、chat、tool、smoke 四个子命令。跑 smoke 可以一次性
检查整个已支持的能力面。
限制
这个 API 面向开发和内部使用,不面向大规模用户流量。延迟和吞吐取决于所部署的模型, 可能会变。训练期间的推理(例如 RL 循环内部)请用原生采样客户端,而不是这个接口。