> ## Documentation Index
> Fetch the complete documentation index at: https://mixroute.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Decisions API

> 透過 MixRoute 呼叫 Google Decisions：具名的 noul、choice、score 問題、機率映射、多模態輸入結構與錯誤處理。

使用 Gemini Decision 1 評估共用輸入，為每個具名問題回傳具型別的答案。本頁介紹 Google Decisions 協定，與 OpenAI Decisions 和 Jev System One 不同。

`POST https://api.mixroute.ai/v1beta/decisions`

傳送 Authorization: Bearer \$MIXROUTE\_API\_KEY 和 Content-Type: application/json。使用 MixRoute Key，並儲存在伺服器端；不要將它傳送到 Google 的 API 網域。

> [!WARNING]
>
> Google 的 questions 是以問題 ID 為鍵的物件，answers 也使用對應鍵。真假判斷用 noul，選項或等級用 criteria。不要混用 OpenAI 的 questions 陣列、predicate、choices、levels，或 Jev 的 state 欄位。

## 請求參數

| 欄位 | 說明 |
| - | - |
| `model` | 必填，使用 gemini-decision-1。 |
| `input` | 必填的共用材料：非空字串、單一內容區塊或內容區塊陣列。 |
| `questions` | 必填，包含 1-1,000 個問題的物件。鍵為 1-64 個符合 `[A-Za-z0-9_-]+` 的 ASCII 字元，答案使用相同的鍵。 |

| 欄位 | 說明 |
| - | - |
| `questions.<id>.type` | 必填: `noul` / `choice` / `score` |
| `questions.<id>.instructions` | 必填的完整問題或評分準則，可用字串、文字內容區塊或其陣列。僅接受文字。模型看不到問題 ID。 |
| `questions.<id>.criteria` | `noul`: 可選物件，包含 `true_description` 和／或 `false_description` 字串；問題已清楚定義兩種結果時可以省略。 |
| `questions.<id>.criteria` | `choice`: 必填，包含 2-255 個選項 ID 到說明字串的映射，說明可為空字串。選項 ID 不能為空，不能有首尾空格或控制字元。 |
| `questions.<id>.criteria` | `score`: 必填，包含 2-255 個非空等級說明的有序陣列。等級值是從 0 開始的陣列索引，不是任意數字標籤。 |

每個問題獨立評估共用輸入，無法看到其他答案。請在 instructions 中寫完整問題，再由應用程式碼組合結果。

選項 ID 為 1-128 個字元、最多 512 UTF-8 位元組；允許內部 ASCII 空格，不允許非 ASCII 空白字元。

## 請求示例

設定 MIXROUTE\_API\_KEY。Python 示例使用 requests，JavaScript 示例使用 Node.js fetch。

> [tab] cURL
>
> ```bash theme={null}
> curl --request POST "https://api.mixroute.ai/v1beta/decisions" \
>   --header "Authorization: Bearer $MIXROUTE_API_KEY" \
>   --header "Content-Type: application/json" \
>   --data '{
>   "model": "gemini-decision-1",
>   "input": "CSV export fails on every attempt. The customer needs the file today and asks for a human agent.",
>   "questions": {
>     "team": {
>       "type": "choice",
>       "instructions": "Which team should handle this ticket?",
>       "criteria": {
>         "engineering": "Software defects",
>         "billing": "Payments and refunds"
>       }
>     },
>     "urgency": {
>       "type": "score",
>       "instructions": "How soon does the customer need help?",
>       "criteria": [
>         "No deadline is specified.",
>         "Help is needed within a week.",
>         "Help is explicitly required today."
>       ]
>     },
>     "needs_human": {
>       "type": "noul",
>       "instructions": "Does the customer request a human agent?"
>     }
>   }
> }'
> ```

> [tab] Python
>
> ```python theme={null}
> import json
> import os
> import requests
>
> payload = json.loads(r'''{
>   "model": "gemini-decision-1",
>   "input": "CSV export fails on every attempt. The customer needs the file today and asks for a human agent.",
>   "questions": {
>     "team": {
>       "type": "choice",
>       "instructions": "Which team should handle this ticket?",
>       "criteria": {
>         "engineering": "Software defects",
>         "billing": "Payments and refunds"
>       }
>     },
>     "urgency": {
>       "type": "score",
>       "instructions": "How soon does the customer need help?",
>       "criteria": [
>         "No deadline is specified.",
>         "Help is needed within a week.",
>         "Help is explicitly required today."
>       ]
>     },
>     "needs_human": {
>       "type": "noul",
>       "instructions": "Does the customer request a human agent?"
>     }
>   }
> }''')
> response = requests.post(
>     "https://api.mixroute.ai/v1beta/decisions",
>     headers={"Authorization": "Bearer " + os.environ["MIXROUTE_API_KEY"]},
>     json=payload,
>     timeout=60,
>     allow_redirects=False,
> )
> response.raise_for_status()
> result = response.json()
> if "error" in result:
>     raise RuntimeError(result["error"])
> answers = result.get("answers")
> if not isinstance(answers, dict):
>     raise ValueError("Expected an answers object")
> fields = {"noul": "noul", "choice": "choice", "score": "score"}
> for name, question in payload["questions"].items():
>     answer = answers.get(name)
>     if not isinstance(answer, dict) or answer.get("type") != question["type"]:
>         raise ValueError("Missing or unexpected answer type: " + name)
>     print(name, answer[fields[question["type"]]], answer["confidence"])
> print(result.get("usage", {}))
> ```

> [tab] JavaScript
>
> ```javascript theme={null}
> const apiKey = process.env.MIXROUTE_API_KEY;
> if (!apiKey) throw new Error("Set MIXROUTE_API_KEY");
> const payload = {
>   "model": "gemini-decision-1",
>   "input": "CSV export fails on every attempt. The customer needs the file today and asks for a human agent.",
>   "questions": {
>     "team": {
>       "type": "choice",
>       "instructions": "Which team should handle this ticket?",
>       "criteria": {
>         "engineering": "Software defects",
>         "billing": "Payments and refunds"
>       }
>     },
>     "urgency": {
>       "type": "score",
>       "instructions": "How soon does the customer need help?",
>       "criteria": [
>         "No deadline is specified.",
>         "Help is needed within a week.",
>         "Help is explicitly required today."
>       ]
>     },
>     "needs_human": {
>       "type": "noul",
>       "instructions": "Does the customer request a human agent?"
>     }
>   }
> };
> const response = await fetch("https://api.mixroute.ai/v1beta/decisions", {
>   method: "POST",
>   headers: {Authorization: "Bearer " + apiKey, "Content-Type": "application/json"},
>   body: JSON.stringify(payload),
>   redirect: "error",
>   signal: AbortSignal.timeout(60000),
> });
> const result = await response.json();
> if (!response.ok || result.error) {
>   throw new Error("HTTP " + response.status + ": " + JSON.stringify(result.error ?? result));
> }
> if (!result.answers || Array.isArray(result.answers) || typeof result.answers !== "object") {
>   throw new Error("Expected an answers object");
> }
> const fields = {noul: "noul", choice: "choice", score: "score"};
> for (const [name, question] of Object.entries(payload.questions)) {
>   const answer = result.answers[name];
>   if (!answer || answer.type !== question.type) {
>     throw new Error("Missing or unexpected answer type: " + name);
>   }
>   console.log(name, answer[fields[question.type]], answer.confidence);
> }
> console.log(result.usage ?? {});
> ```

## 答案與用量

| 欄位 | 說明 |
| - | - |
| `noul` | noul 是 P(true)，範圍為 0.01-0.99，不是布林值。confidence 等於 max(noul, 1 - noul)。 |
| `choice` | choice 是獲選的選項 ID，probabilities 為每個選項的機率映射，confidence 為獲選機率。機率完全相同時，依選項鍵的 UTF-8 位元組字典序選擇最前者。 |
| `score` | score 是等級索引的機率加權平均值，可以是小數。probabilities 將字串索引映射為機率，legend 將其映射為等級說明。confidence 是最大的等級機率，不是正規化後的 score。 |

機率不保證答案一定正確。請用有標註的代表性資料設定操作門檻；信心程度低或沒有合適選項時應允許複核。

```json theme={null}
{
  "answers": {
    "team": {
      "confidence": 0.9980277470061801,
      "choice": "engineering",
      "probabilities": {
        "billing": 0.0019722529938198032,
        "engineering": 0.9980277470061801
      },
      "type": "choice"
    },
    "urgency": {
      "confidence": 0.9833902224118356,
      "score": 1.9825588708050947,
      "probabilities": {
        "0": 0.0008313516067408738,
        "1": 0.015778425981423486,
        "2": 0.9833902224118356
      },
      "legend": {
        "0": "No deadline is specified.",
        "1": "Help is needed within a week.",
        "2": "Help is explicitly required today."
      },
      "type": "score"
    },
    "needs_human": {
      "confidence": 0.99,
      "noul": 0.99,
      "type": "noul"
    }
  },
  "usage": {
    "total_tokens": 230,
    "total_input_tokens": 230,
    "input_tokens_by_modality": [
      {
        "modality": "text",
        "tokens": 230
      }
    ],
    "total_output_tokens": 0
  }
}
```

輸出 token 為 0 是正常行為：模型回傳具型別的決策，不生成文字 token。輸入仍會計費。讀取 `usage.total_input_tokens`、`usage.total_output_tokens` 和 `usage.total_tokens`；實際扣費以控制台消費紀錄為準。

## 限制與輸入格式

共用輸入與所有問題合計不得超過 262,144 tokens；JSON 巢狀深度上限為 100 層。

文字區塊使用 `{"type":"text","text":"..."}`。圖片、音訊、影片和 PDF document 區塊使用 type、`mime_type`，以及內嵌 Base64 data 或 uri。應用程式自身的 JSON 應序列化為文字字串，不要直接作為內容區塊傳送。

Google 公布的內嵌資料上限為每次 100 MB（PDF 為 50 MB），外部 HTTPS URL 為每個 15 MB。Files API URI、公開 URL 和簽署的 HTTPS URL 屬於廠商格式；經 MixRoute 上傳或取得媒體的能力取決於路由。Decisions 不支援 YouTube URL 或直接使用 gs\:// URI。

相鄰文字區塊串接時不會自動加入分隔符，請自行加入空格或換行。不要傳對話訊息、思考或工具呼叫內容區塊，應將這些上下文序列化為文字。本介面不提供上下文快取、Batch API、Flex 或 Priority 推理。路由限制可能低於廠商上限。

## 錯誤處理

讀取 answers 前先檢查 HTTP 狀態和 JSON error 物件。參數或限制錯誤可回傳 HTTP 400；Google 安全攔截回傳錯誤而不是 answers，不能照搬 OpenAI 的逐問題 refusal 處理。也應拒絕缺少答案或答案型別不符合請求的回應。

逾時不代表請求未執行，不要盲目重試 POST。遇到限流或暫時性服務錯誤時，保留請求 ID，並依應用程式需要控制重試與退避。

## 相關協定

[Gemini Decision 1](https://mixroute.ai/docs/zh-Hant/model-api/google/gemini-decision-1.md) · [OpenAI Decisions](https://mixroute.ai/docs/zh-Hant/api-reference/endpoint/decisions.md) · [Jev System One](https://mixroute.ai/docs/zh-Hant/api-reference/endpoint/jev.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.