# Gemini Decisions

Gemini 多模态分类、选择和评分。提交 input 与 questions，返回概率和置信度；仅同步非流式，请求体不超过 20 MiB。

## 接口与鉴权

`POST https://api.tu-zi.com/v1beta/decisions`

传输方式: json

使用模型调用 API Key。示例凭证为占位符，请从环境变量读取真实密钥。

```http
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
```

## 请求体参数

| 字段 | 类型 | 必填 | 说明与约束 |
| --- | --- | --- | --- |
| model | string | 是 | 模型名 gemini-decision-1。 示例: gemini-decision-1 |
| input | string \| object \| array | 是 | 共享文本或包含图片、音频、视频、PDF 的原生内容块。 示例: The ordered mug arrived broken. |
| questions | object | 是 | 1 至 1000 个独立问题，每项必填 type 和 instructions；choice 使用 2 至 255 项 criteria 对象，score 使用 2 至 255 项有序 criteria 数组。 示例: {"damaged":{"type":"noul","instructions":"Did the item arrive damaged?"}} |

## 调用准备

- 示例使用本站地址；调用其他站点时，仅替换站点地址，保留完整接口路径。
- 使用本站令牌页面创建的模型调用密钥。按示例设置环境变量 `API_KEY`，或替换 `YOUR_API_KEY` 占位符。

## 适用限制

本页是协议基础结构。模型可用参数、枚举、上限和异步行为以该模型“快速上手”为准；示例中的 YOUR_MODEL 必须替换。表中表单初始值不代表上游默认值。

## 最小请求示例

```json
{
  "model": "gemini-decision-1",
  "input": "The ordered mug arrived broken.",
  "questions": {
    "damaged": {
      "type": "noul",
      "instructions": "Did the item arrive damaged?"
    }
  }
}
```

## 代码示例

### curl

```bash
# 需要 curl 7.76+。HTTP 错误返回非零退出码；仍需检查 JSON/SSE 业务状态。
curl --fail-with-body --silent --show-error --connect-timeout 10 --max-time 120 --request POST 'https://api.tu-zi.com/v1beta/decisions' \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "gemini-decision-1",
  "input": "The ordered mug arrived broken.",
  "questions": {
    "damaged": {
      "type": "noul",
      "instructions": "Did the item arrive damaged?"
    }
  }
}'
```

### python

```python
# 安装依赖：python3 -m pip install requests
import json
import os
import requests

url = "https://api.tu-zi.com/v1beta/decisions"
headers = json.loads("{\"Authorization\":\"Bearer YOUR_API_KEY\",\"Content-Type\":\"application/json\"}")
for name in ["API_KEY"]:
    if not os.environ.get(name, "").strip():
        raise RuntimeError("Set environment variable: " + name)
headers["Authorization"] = "Bearer " + os.environ["API_KEY"]
payload = json.loads("{\"model\":\"gemini-decision-1\",\"input\":\"The ordered mug arrived broken.\",\"questions\":{\"damaged\":{\"type\":\"noul\",\"instructions\":\"Did the item arrive damaged?\"}}}")
response = requests.request("POST", url, headers=headers, json=payload, timeout=120)
response.raise_for_status()
result = response.json()
if isinstance(result, dict) and (result.get("success") is False or result.get("code") is False or result.get("error")):
    raise RuntimeError(json.dumps(result, ensure_ascii=False))
print(json.dumps(result, ensure_ascii=False, indent=2))
```

### javascript

```javascript
// 使用 Node.js 20+，保存为 example.mjs 后运行。
const url = "https://api.tu-zi.com/v1beta/decisions";
const headers = {
  "Authorization": "Bearer YOUR_API_KEY",
  "Content-Type": "application/json"
};
for (const name of ["API_KEY"]) {
  if (!process.env[name]?.trim()) throw new Error("Set environment variable: " + name);
}
headers.Authorization = 'Bearer ' + process.env.API_KEY;
const response = await fetch(url, { method: "POST", headers, body: JSON.stringify({
  "model": "gemini-decision-1",
  "input": "The ordered mug arrived broken.",
  "questions": {
    "damaged": {
      "type": "noul",
      "instructions": "Did the item arrive damaged?"
    }
  }
}), signal: AbortSignal.timeout(120000) });
if (!response.ok) throw new Error(await response.text());
const result = await response.json();
if (result?.success === false || result?.code === false || result?.error) throw new Error(JSON.stringify(result));
console.log(JSON.stringify(result, null, 2));
```

## 响应字段

| 字段 | 类型 | 说明与约束 |
| --- | --- | --- |
| answers | object | 每个问题的判断、概率及置信度。 |
| usage.total_input_tokens | integer | 实际输入 token 数，共享输入仅计一次，包含各问题指令和标准。 |
| usage.total_output_tokens | integer | 固定为 0。 |

以下为示例响应，部分接口仅展示主要字段；可选字段不保证出现。

```json
{
  "answers": {
    "damaged": {
      "type": "noul",
      "noul": 0.99,
      "confidence": 0.99
    }
  },
  "usage": {
    "total_input_tokens": 94,
    "total_output_tokens": 0,
    "total_tokens": 94
  }
}
```

## 如何判断调用成功

先检查 HTTP 状态，再检查正文的业务状态和所需结果字段，不能只看 HTTP 200 或脚本退出码。

## 错误处理与重试

检查 HTTP 状态与该协议的错误对象；不要将不同协议的错误字段混用。

- **401/403：** 检查凭证与权限。
- **429：** 区分临时限流、额度不足与服务容量，只有临时故障适合有限退避。
- **5xx：** 检查网关、上游及模型/渠道配置。

错误正文可能含 error/message/code 等字段，以实际协议为准。

- 查询遇到临时错误时可采用有上限的指数退避；参数、鉴权、额度或配置问题先修复再请求。
- 创建任务、生成内容、创建或删除密钥等操作不要盲目重试，以免重复计费或重复执行。

## 文档依据

定义版本: 1

审核日期: 2026-11-02

来源: https://api.tu-zi.com/docs/api/reference-relay-gemini-decision

本文只包含接口文档和示例。真实密钥、账号数据及用户请求内容不包含在复制内容中。
