Gemini Priority API 是進階推論層級,專為需要低延遲和最高可靠性的業務關鍵工作負載設計,價格較高。系統會優先處理 Priority 層級的流量,再處理 Standard API 和 Flex 層級的流量。
您可以在 Interactions API 端點使用優先順序推論功能。
如何使用優先檔案區
如要使用「優先」層級,請將要求中的 service_tier 欄位設為 priority。如果省略這個欄位,預設層級為標準。
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3.8-flash",
input="Triage this critical customer support ticket immediately.",
service_tier='priority'
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from '@google/genai';
const ai = new GoogleGenAI({});
async function main() {
const interaction = await ai.interactions.create({
model: "gemini-3.8-flash",
input: "Triage this critical customer support ticket immediately.",
service_tier: "priority"
});
console.log(interaction.output_text);
}
await main();
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.ServiceTier;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
Client client = new Client();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("gemini-3.8-flash"))
.input(InteractionsInput.of("Perform a priority inference task."))
.serviceTier(ServiceTier.PRIORITY)
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println(interaction.outputText().orElse(""));
Go
package main
import (
"context"
"fmt"
"log"
"google.golang.org/genai"
"google.golang.org/genai/interactions/models/interactions"
"google.golang.org/genai/interactions/models/operations"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
Model: interactions.Model("gemini-3.8-flash"),
Input: interactions.NewInteractionsInput("Perform a priority inference task."),
ServiceTier: interactions.ServiceTierPriority.ToPointer(),
}),
})
if err != nil {
log.Fatal(err)
}
if res.Interaction.OutputText != nil {
fmt.Println(*res.Interaction.OutputText)
}
}
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
"model": "gemini-3.8-flash",
"input": "Triage this critical customer support ticket immediately.",
"service_tier": "priority"
}'
優先推論的運作方式
優先順序推論會將要求轉送至高重要性的運算佇列,為面向使用者的應用程式提供可預測的快速效能。主要機制是將超過動態限制的流量,從伺服器端順暢降級為標準處理程序,確保應用程式穩定性,而不是讓要求失敗。
| 功能 | 優先順序 | 標準 | Flex | 批次 |
|---|---|---|---|---|
| 定價 | 比 Standard 方案多 75% 至 100% | 原價 | 50% 折扣 | 50% 折扣 |
| 延遲 | 秒 | 秒數換算成分鐘數 | 分鐘數 (目標為 1 到 15 分鐘) | 長達 24 小時 |
| 穩定性 | 高 (不掉毛) | 高 / 中高 | 盡可能取得容量 (可捨棄) | 高 (處理量) |
| 介面 | 同步 | 同步 | 同步 | 非同步 |
主要優點
- 低延遲:專為互動式 AI 工具設計,可快速回應使用者。
- 高可靠性:系統會以最高優先順序處理流量,且嚴格禁止捨棄。
- 正常降級:如果流量尖峰超過動態限制,系統會自動將流量降級至標準層級進行處理,而非處理失敗,避免服務中斷。
- 低摩擦:使用與標準和 Flex 層級相同的同步
create方法。
用途
優先處理非常適合用於效能和可靠性至關重要的業務關鍵工作流程。
- 互動式 AI 應用程式:客戶服務聊天機器人和副手,使用者會支付額外費用,並期望獲得快速且一致的回覆。
- 即時決策引擎:需要高可靠性、低延遲結果的系統,例如即時票證分類或詐欺偵測。
- 進階客戶功能:開發人員需要為付費客戶確保更高的服務水準目標 (SLO)。
頻率限制
即使優先取用量會計入整體互動式流量速率限制,仍有自己的速率限制。優先推論的預設速率限制為模型 / 層級的標準速率限制的 0.3 倍
安全降級邏輯
如果因壅塞而超出優先順序限制,系統會自動且順暢地將溢出的要求降級為標準處理程序,而不是因 503 或 429 錯誤而失敗。降級的要求會以標準費率計費,而非優先級進階費率。
客戶責任
- 回應監控:開發人員應監控 API 回應中的
x-gemini-service-tier標頭,偵測要求是否經常降級為standard。 - 重試:用戶端必須為標準錯誤 (例如
DEADLINE_EXCEEDED) 執行重試邏輯/指數輪詢。
定價
優先推論的價格比標準 API 高出 75% 至 100%,並以每個權杖計費。
支援的模型
下列模型支援優先順序推論:
| 模型 | 優先順序推斷 |
|---|---|
| Gemini 3.8 Flash | ✔️ |
| Gemini 3.7 Flash | ✔️ |
| Gemini 3.6 Flash | ✔️ |
| Gemini 3.5 Flash-Lite | ✔️ |
| Gemini 3.5 Flash | ✔️ |
| Gemini 3.1 Flash-Lite | ✔️ |
| Gemini 3.1 Pro 預先發布版 | ✔️ |
| Gemini 3 Flash 預先發布版 | ✔️ |
| Gemini 2.5 Pro | ✔️ |
| Gemini 2.5 Flash | ✔️ |
| Gemini 2.5 Flash-Lite | ✔️ |