Gemini · long-context callbacks
Gemini webhooks for 1M-token contexts.
Gemini's long-context calls take 30–60 seconds. Triggering one from a webhook handler used to mean either polling or a queue. With AnyHook, neither.
The timing problem
Google added webhook delivery to the Gemini API in May 2026. The delivery contract is standard HTTP: ack in 10 seconds or get retried.
A Gemini 1.5 Pro call against a 1M-token context takes 30 to 60 seconds. Wrapping that in a webhook handler — to do RAG over a private corpus on every Stripe event, for example — means you cannot ack in time. The retries pile up, the costs compound.
Long-context Gemini in a webhook handler
AnyHook ack-and-forwards. You run the Gemini call against your full corpus. No polling loop, no Redis queue, no 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();
// Run RAG over the full corpus. 45 seconds. Stripe doesn't care.
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 });
}Questions teams ask
- Does AnyHook support Gemini's webhook signature scheme?
- Yes. Configure the Gemini signing secret as the source_secret for your app and AnyHook verifies inbound deliveries at the edge before forwarding.
- What if my Gemini call hits a rate limit?
- Return a 429 from your handler. AnyHook treats it as retriable, applies exponential backoff, and surfaces the retry chain in the dashboard. You can replay the original event once your quota resets.
- Is this only for Gemini API webhooks, or also Vertex AI?
- Both. Anything that sends signed HTTP webhooks works. AnyHook is provider-agnostic on the verification layer.
Change one URL. Keep your Gemini handler.
Free tier covers 3K events / month. No SDK, no code changes — just point Gemini at your AnyHook inbound URL.