跳至主要內容

Vertex AI PayGo 與 Priority

優先 PayGo

LiteLLM 支援 Priority PayGo。
傳送 priority 標頭,即可獲得 priority 排隊,並以 priority token 費率計費。

哪些模型支援 Priority PayGo?

截至撰寫本文時:gemini/gemini-2.5-provertex_ai/gemini-3-pro-previewvertex_ai/gemini-3.1-pro-previewvertex_ai/gemini-3-flash-preview,以及它們的變體。
請查看 LiteLLM 的 model pricing JSON 中的 supports_service_tier: true

傳送 priority 請求

使用此標頭:

X-Vertex-AI-LLM-Shared-Request-Type: priority

import litellm

response = litellm.completion(
model="vertex_ai/gemini-3-pro-preview",
messages=[{"role": "user", "content": "Summarize the Gettysburg Address."}],
vertex_project="YOUR_PROJECT_ID",
vertex_location="us-central1",
extra_headers={"X-Vertex-AI-LLM-Shared-Request-Type": "priority"},
)

print(response.choices[0].message.content)

費用追蹤運作方式

Vertex AI Priority PayGo 費用追蹤流程

trafficTypeservice_tier 對應

usageMetadata.trafficTypeservice_tier使用的定價鍵
ON_DEMANDNoneinput_cost_per_token
ON_DEMAND_PRIORITY"priority"input_cost_per_token_priority
FLEX / BATCH"flex"input_cost_per_token_flex

如果缺少特定層級的鍵,LiteLLM 會回退到標準定價鍵。


標準 PayGo 與 Provisioned Throughput

這與 priority 路由是不同的標頭:

標頭值行為
X-Vertex-AI-LLM-Request-Type: shared強制標準 PayGo(略過 PT)
X-Vertex-AI-LLM-Request-Type: dedicated僅強制 Provisioned Throughput(若耗盡則 429

原生路由範例

import litellm

response = litellm.completion(
model="vertex_ai/gemini-2.0-flash",
messages=[{"role": "user", "content": "Hello!"}],
vertex_project="YOUR_PROJECT_ID",
vertex_location="us-central1",
extra_headers={"X-Vertex-AI-LLM-Request-Type": "shared"},
)

直通範例

MODEL_ID="gemini-2.0-flash-001"
PROJECT_ID="YOUR_PROJECT_ID"

curl -X POST \
"${LITELLM_PROXY_BASE_URL}/vertex_ai/v1/projects/${PROJECT_ID}/locations/global/publishers/google/models/${MODEL_ID}:generateContent" \
-H "Authorization: Bearer sk-your-litellm-key" \
-H "Content-Type: application/json" \
-H "x-pass-X-Vertex-AI-LLM-Request-Type: shared" \
-d '{
"contents": [{"role": "user", "parts": [{"text": "Hello!"}]}]
}'

疑難排解

Q: 403 Permission deniedIAM_PERMISSION_DENIED 代表什麼?
A: 服務帳戶或 Application Default Credentials (ADC) 使用者沒有 roles/aiplatform.user 角色。若要解決此問題,請重新執行 gcloud projects add-iam-policy-binding

Q: 如果我收到 429 Quota exceeded 錯誤,該怎麼做?
A: 這表示您已達到每個區域的 QPM(每分鐘查詢數)或 TPM(每分鐘 token 數)配額。您可以:

Q: 我要如何修正 VERTEXAI_PROJECT not set 錯誤?
A: 請在 LiteLLM 呼叫中明確傳入 vertex_project 參數,或在執行程式碼前設定 VERTEXAI_PROJECT 環境變數。

🚅
LiteLLM Enterprise
為正式環境打造的 SSO/SAML、稽核記錄、支出追蹤、多團隊管理與防護欄。
深入瞭解 →