Recipe

Start LLM Work From A Webhook

Starting LLM work from a webhook means using the webhook event id to deduplicate the model request.

Problem

Webhook senders retry delivery, so your handler must avoid duplicate LLM calls. ReqRun handles the model request; your app still receives and validates the webhook.

Code

Use the provider event id as idempotency_key.

TypeScript
export async function POST(request: Request) {
  const event = await request.json();

  const response = await reqrun.chat.completions.create({
    model: "gpt-5-nano",
    messages: [{ role: "user", content: "Summarize the webhook event." }],
    wait: false,
    idempotency_key: event.id,
  });

  return Response.json({ request_id: response.id });
}