跳转到主要内容
POST /v1/responses 上用 text.format 把模型输出强制为 JSON。它遵循 OpenAI Responses text.format 规范仅在 backbone 模式mode:"model")下可用
text.format 需要 mode:"model"。在默认的 agent 模式下它返回 400 unsupported_parameterparam: "text")—— 自由文本在下游爆炸比接口报错贵得多。Answers API(/v1/chat/completions)同样以 400 拒绝 response_format

json_object

把输出约束为语法合法的 JSON 对象(无 schema):
{
  "model": "mirobody-flash",
  "mode": "model",
  "input": "Reply with a JSON object having keys a and b.",
  "text": { "format": { "type": "json_object" } }
}
消息文本是一个由你自行解析的 JSON 字符串:
{ "output_text": "{\"a\":1,\"b\":2}", "status": "completed", ... }

json_schema

把输出约束为你提供的 schema。设 strict: true 要求严格贴合 schema:
curl https://mirobody-api.thetahealth.ai/v1/responses \
  -H "Authorization: Bearer $MIROBODY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
        "model": "mirobody-flash",
        "mode": "model",
        "input": "Give me a manifest for apples with count 3.",
        "text": {
          "format": {
            "type": "json_schema",
            "name": "manifest",
            "strict": true,
            "schema": {
              "type": "object",
              "properties": {
                "item":  { "type": "string" },
                "count": { "type": "integer" }
              },
              "required": ["item", "count"],
              "additionalProperties": false
            }
          }
        }
      }'
from openai import OpenAI

client = OpenAI(api_key="mb_live_...", base_url="https://mirobody-api.thetahealth.ai/v1")

resp = client.responses.create(
    model="mirobody-flash",
    extra_body={"mode": "model"},
    input="Give me a manifest for apples with count 3.",
    text={
        "format": {
            "type": "json_schema",
            "name": "manifest",
            "strict": True,
            "schema": {
                "type": "object",
                "properties": {"item": {"type": "string"}, "count": {"type": "integer"}},
                "required": ["item", "count"],
                "additionalProperties": False,
            },
        }
    },
)
print(resp.output_text)   # {"item":"apples","count":3}

Provider 降级

text.format 透传给底层模型。当背后的 provider 没有原生 json_schema 支持时,Mirobody 会自动降级重试一次 —— 用 json_object + 把 schema 注入系统提示。该重试对你透明(你仍拿到符合 schema 形状的 JSON),因此无需关心某个档位背后是哪个 provider,都可把结构化输出当作可靠能力使用。

另见

  • Backbone 模式 —— mode:"model"text.format 的前置条件。
  • Function calling —— 需要约束工具参数时,把 text.formattool_choice:"required" 搭配使用。