Replicate · long-running model callbacks
Replicate webhooks that finish what they start.
Your handler stores the output, notifies the user, maybe chains another run. AnyHook acks Replicate at the edge so none of that has to happen in 10 seconds.
The timing problem
Replicate fires a webhook when a model run completes. That part works fine. The problem is what you want to do with the result: persist the artefact, notify the user, fan out to a second model, post a Slack message.
Each of those is a network round-trip. Together they routinely exceed 10 seconds. Replicate retries. Your downstream side-effects fire twice. AnyHook fixes the timing problem at the boundary, so your handler stays linear and obvious.
Replicate completed-run callbacks via AnyHook
Pass the AnyHook inbound URL as the `webhook` parameter on your prediction. Your handler downstream gets all the time it needs to fan out.
import Replicate from "replicate";
import { verifyWebhook } from "@anyhook/verify";
const replicate = new Replicate();
// 1. Start the prediction with AnyHook as the callback target.
await replicate.predictions.create({
version: "...",
input: { prompt: "..." },
webhook: `https://in.anyhook.net/${userSlug}/${appSlug}`,
webhook_events_filter: ["completed"],
});
// 2. Handler — runs after AnyHook has already acked Replicate.
export async function POST(req: Request) {
if (!(await verifyWebhook(req, process.env.ANYHOOK_SIGNING_SECRET!))) {
return new Response("invalid", { status: 401 });
}
const { id, output } = await req.json();
await persistOutput(id, output); // 3s
await notifyUser(id); // 2s
await chainNextModel(output); // 45s — fine, we have 5 min
return new Response("ok", { status: 200 });
}Questions teams ask
- Does this work with all Replicate model types?
- Yes — image, video, audio, language. The webhook contract is identical. AnyHook treats the payload as opaque JSON and forwards it intact.
- Replicate already has retries. Why do I need AnyHook?
- Replicate retries on transport failures, but its window is short and it won't retry your downstream business logic — only the webhook delivery. AnyHook gives you 10 retries with exponential backoff against your handler, plus one-click replay weeks later.
- Can I see the prediction output without checking Replicate again?
- Yes. The full webhook payload — including the `output` URLs — is stored encrypted in your AnyHook event log and inspectable in the dashboard.
Change one URL. Keep your Replicate handler.
Free tier covers 3K events / month. No SDK, no code changes — just point Replicate at your AnyHook inbound URL.