Instead of polling GET /jobs/{id} repeatedly, you can provide a webhook URL to receive a POST request when your job completes. This is more efficient and reduces unnecessary API calls.
Add the X-Webhook-URL header to any generation request. When the job reaches a terminal state (completed, failed, or cancelled), the API will send a POST request to your URL with the full job data.
// npm install @krea-ai/sdkimport { Krea } from "@krea-ai/sdk";const krea = new Krea({ apiKey: process.env.KREA_API_KEY });const job = await krea.image( "bfl/flux-1-dev", { prompt: "a serene mountain landscape at sunset", width: 1024, height: 576 }, { webhookUrl: "https://your-server.com/webhook" });console.log(`Job ID: ${job.job_id}`);// Your webhook will receive the results when complete
Use webhooks when you have a server that can receive HTTP requests. Use polling for client-side applications or when you can’t expose a public endpoint.