Gemini · long-context callback
支援 1M-token context 的 Gemini webhook。
Gemini 的 long-context 呼叫一跑 30–60 秒。從 webhook handler 觸發以前要嘛 polling、要嘛架 queue。用 AnyHook,兩個都不用。
時序問題
Google 在 2026 年 5 月為 Gemini API 加上 webhook delivery。Delivery contract 標準——10 秒內 ack,不然重試。
Gemini 1.5 Pro 對 1M-token context 的一次呼叫要 30 到 60 秒。把它包在 webhook handler 裡——例如每個 Stripe 事件都做一次私有 corpus 的 RAG——根本來不及 ack。Retry 堆積、成本翻倍。
30–60s
Gemini long-context 呼叫延遲
1M
Gemini 單次 context tokens
10s
Webhook sender SLA
$0
Free tier 每月 3K events
在 webhook handler 裡跑 long-context Gemini
AnyHook ack 後 forward。你對全 corpus 跑 Gemini 呼叫——不用 polling loop、不用 Redis queue、不用 Cloud Tasks。
import { verifyWebhook } from "@anyhook/verify";
import { GoogleGenerativeAI } from "@google/generative-ai";
const gemini = new GoogleGenerativeAI(process.env.GEMINI_API_KEY!);
export async function POST(req: Request) {
if (!(await verifyWebhook(req, process.env.ANYHOOK_SIGNING_SECRET!))) {
return new Response("invalid", { status: 401 });
}
const event = await req.json();
// 對整個 corpus 跑 RAG。45 秒。Stripe 不在意。
const model = gemini.getGenerativeModel({ model: "gemini-1.5-pro" });
const result = await model.generateContent([
fullCorpusFor(event.payload.tenant_id),
`Process: ${JSON.stringify(event.payload)}`,
]);
await persistDecision(result.response.text());
return new Response("ok", { status: 200 });
}工程團隊常問的問題
- AnyHook 支援 Gemini 的 webhook 簽章機制嗎?
- 支援。把 Gemini 的 signing secret 設為你 app 的 source_secret,AnyHook 在 edge 驗 inbound delivery 後再 forward。
- Gemini 呼叫遇到 rate limit 怎辦?
- 從 handler 回 429。AnyHook 視為可重試,套用指數退避,在 dashboard 顯示完整重試鏈。額度恢復後可以 replay 原始事件。
- 只支援 Gemini API webhook 還是也支援 Vertex AI?
- 兩個都支援。任何發簽名 HTTP webhook 的服務都可以。AnyHook 的驗證層是 provider-agnostic 的。
改一個 URL,保留你的 Gemini handler。
Free tier 每月含 3,000 events。沒有 SDK、沒有 code 變更——把 Gemini 指到你的 AnyHook inbound URL 就好。