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

The Gemini API delivers webhooks under the Standard Webhooks spec and retries a failed delivery for 24 hours with exponential backoff, so a slow handler is hit again and again.

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.

30-60s
Gemini long-context call latency
1M
Tokens in a single Gemini context
24h
How long Gemini keeps retrying a missed webhook
$0
Free tier covers 10K events / mo

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(tenantOf(event)),
    `Process: ${JSON.stringify(event)}`,
  ]);

  await persistDecision(result.response.text());
  return new Response("ok", { status: 200 });
}

Questions teams ask

Does AnyHook support Gemini's webhook signature scheme?
Yes. Gemini signs with the Standard Webhooks scheme. Set the app's source to Standard Webhooks and paste the signing secret: AnyHook verifies each delivery at the edge before forwarding it.
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 HTTP webhooks can go through AnyHook. Signatures are checked at the edge for the schemes in the docs, Standard Webhooks included; a sender outside them runs as Generic, with its original headers forwarded for your own check.

Change one URL. Keep your Gemini handler.

Free tier covers 10K events / month. No SDK: point Gemini at your AnyHook inbound URL.