跳转到主要内容

推荐 endpoint

最小请求

{
  "model": "gpt-4.1",
  "input": "从这段文本中提取订单号和金额:订单 A-1024,金额 99.5 美元。",
  "text": {
    "format": {
      "type": "json_schema",
      "name": "order",
      "strict": true,
      "schema": {
        "type": "object",
        "properties": {
          "order_id": { "type": "string" },
          "amount": { "type": "number" }
        },
        "required": ["order_id", "amount"],
        "additionalProperties": false
      }
    }
  }
}

cURL 示例

curl https://mass.apigo.ai/v1/responses \
  -H "Authorization: Bearer $TIDEMIND_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4.1",
    "input": "从这段文本中提取订单号和金额:订单 A-1024,金额 99.5 美元。",
    "text": {
      "format": {
        "type": "json_schema",
        "name": "order",
        "strict": true,
        "schema": {
          "type": "object",
          "properties": {
            "order_id": { "type": "string" },
            "amount": { "type": "number" }
          },
          "required": ["order_id", "amount"],
          "additionalProperties": false
        }
      }
    }
  }'

Python 示例

import json
from openai import OpenAI

client = OpenAI(
    base_url="https://mass.apigo.ai/v1",
    api_key="<TIDEMIND_API_KEY>",
)

response = client.responses.create(
    model="gpt-4.1",
    input="从这段文本中提取订单号和金额:订单 A-1024,金额 99.5 美元。",
    text={
        "format": {
            "type": "json_schema",
            "name": "order",
            "strict": True,
            "schema": {
                "type": "object",
                "properties": {
                    "order_id": {"type": "string"},
                    "amount": {"type": "number"},
                },
                "required": ["order_id", "amount"],
                "additionalProperties": False,
            },
        }
    },
)

print(json.loads(response.output_text))

Node.js 示例

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://mass.apigo.ai/v1",
  apiKey: process.env.TIDEMIND_API_KEY,
});

const response = await client.responses.create({
  model: "gpt-4.1",
  input: "从这段文本中提取订单号和金额:订单 A-1024,金额 99.5 美元。",
  text: {
    format: {
      type: "json_schema",
      name: "order",
      strict: true,
      schema: {
        type: "object",
        properties: {
          order_id: { type: "string" },
          amount: { type: "number" }
        },
        required: ["order_id", "amount"],
        additionalProperties: false
      }
    }
  }
});

console.log(JSON.parse(response.output_text));

最佳实践

  • JSON Schema 尽量小而硬,不要一上来就做深层嵌套
  • strict: trueadditionalProperties: false 降低漂移
  • 服务端仍要做二次校验,不要直接信任模型输出