跳转至

Anthropic 兼容推理

Mint Recursive 提供一个与 Anthropic Messages API 兼容的 HTTP 端点,让所有为 Claude 构建的工具——包括 Claude Code 和 Anthropic SDK——只需改 base URL 和 API key 就能指向 Mint Recursive 模型。它支持 Mint Recursive 基座模型,也支持你自己微调的 sampler checkpoint。

训练过程中的推理(例如 RL rollout)请优先使用原生的 SamplingClient。

Beta,低流量

该端点目前面向测试、评估和内部工具场景调优,不适合高吞吐生产流量。Beta 期间延迟和吞吐会随模型变化。如需更大规模部署或为你的组织开通访问,请联系 Mint Recursive 团队。

把 Anthropic 客户端指向 Mint Recursive

  1. Base URL —— 把 Anthropic 客户端的 base URL 设为:
https://mintcn.macaron.xin/services/tinker-prod/anthropic/api

客户端会在后面追加 /v1/messages(以及 /v1/messages/count_tokens)。

  1. Model —— 用 Mint Recursive 基座模型名(例如 Qwen/Qwen3-8B)或 Mint Recursive sampler checkpoint 路径作为 model:
mindlab-toolkit://0034d8c9-0a88-52a9-b2b7-bce7cb1e6fef:train:0/sampler_weights/000080

任意合法 sampler 路径都可以;你也可以在同一个 checkpoint 上一边训练一边采样。

  1. Auth —— 传入你的 MINT_API_KEY。该端点接受 Anthropic SDK 原生的 x-api-key 头(无需改写);Authorization: Bearer <key> 也行。

示例

from os import getenv
from anthropic import Anthropic

BASE_URL = "https://mintcn.macaron.xin/services/tinker-prod/anthropic/api"
MODEL = "Qwen/Qwen3-8B"

client = Anthropic(base_url=BASE_URL, api_key=getenv("MINT_API_KEY"))
response = client.messages.create(
    model=MODEL,
    max_tokens=512,
    messages=[{"role": "user", "content": "The capital of France is"}],
)
print(response.content[0].text)

max_tokens 是必填项(与 Anthropic 一致)。messages、system、 temperature、top_p、top_k、stop_sequences 的行为与 Anthropic Messages API 一致。把 MODEL 换成任意 sampler 路径即可对比不同运行结果。

Thinking effort

Mint Recursive 的推理模型用 effort 值控制,而非 Anthropic 的 thinking.budget_tokens。通过 extra_body 传一个 Mint Recursive 专属的 output_config.effort:

response = client.messages.create(
    model=MODEL,
    max_tokens=1024,
    messages=[{"role": "user", "content": "What is 17 * 23?"}],
    extra_body={"output_config": {"effort": "high"}},
)
for block in response.content:
    if block.type == "thinking":
        print("Reasoning:", block.thinking)
    elif block.type == "text":
        print("Answer:", block.text)

用标准 Anthropic 的 thinking 字段关闭推理:

response = client.messages.create(
    model=MODEL,
    max_tokens=512,
    messages=[{"role": "user", "content": "What is 17 * 23?"}],
    thinking={"type": "disabled"},
)
  • effort 接受 "low"、"medium"、"high"、"xhigh" 或 "max"("max" 行为同 "xhigh")。
  • 并非所有模型都支持;不支持的模型返回 HTTP 400。
  • thinking={"type": "disabled"} 无论 output_config 如何设置都会强制关闭推理。 thinking.budget_tokens 为了线路兼容会被接受但忽略——请用 output_config.effort。
  • 在支持的模型上省略时,使用默认 effort 值。

Tool use

该端点完整往返 Anthropic tool use。传入带 input_schema 的 tools; 模型回复 tool_use 块,你在后续 user 消息中以 tool_result 块回传结果。

response = client.messages.create(
    model=MODEL,
    max_tokens=1024,
    messages=[{"role": "user", "content": "What's the weather in Paris?"}],
    tools=[{
        "name": "get_weather",
        "description": "Get the current weather for a city.",
        "input_schema": {
            "type": "object",
            "properties": {"city": {"type": "string"}},
            "required": ["city"],
        },
    }],
)

tool_choice 支持 auto、any、指定工具名和 none。模型调用工具时, stop_reason 为 tool_use。

Streaming

设 stream=True(或用 client.messages.stream(...))获取标准 Anthropic SSE:先 message_start,然后逐块的 content_block_start / _delta / _stop, 接着 message_delta 和 message_stop。Thinking 块以 thinking_delta 流式返回,文本以 text_delta,工具参数以 input_json_delta。

with client.messages.stream(
    model=MODEL,
    max_tokens=512,
    messages=[{"role": "user", "content": "Write a haiku about the ocean."}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)

Counting tokens

POST /v1/messages/count_tokens 用模型真实的 tokenizer 和 renderer 返回输入 token 数,不进行采样:

count = client.messages.count_tokens(
    model=MODEL,
    messages=[{"role": "user", "content": "How many tokens is this?"}],
)
print(count.input_tokens)

支持与不支持

支持: system prompt(字符串或 content-block 列表)、多轮对话、 流式、tool use / results / tool_choice、extended thinking(通过 output_config.effort 以 thinking 块返回)、图片输入(base64 或 url)、 token 计数、temperature / top_p / top_k / stop_sequences。

不支持: prompt caching(cache_control 被忽略; cache_creation_input_tokens / cache_read_input_tokens 始终为 null)、 citations、音频输入、thinking.budget_tokens(被接受但忽略——请用 output_config.effort)、以及 thinking 块的 signature 值(返回空字符串)。