Skip to main content

Step 1: Upload or Reference an Image

First, you need to provide the source image. You can either:
  • Upload an image file as base64
  • Provide a publicly accessible image URL
import { readFileSync } from "node:fs";

// Option 1: Using base64 encoded image
const imageBuffer = readFileSync("input_image.jpg");
const encodedImage = imageBuffer.toString("base64");

// Option 2: Using image URL
const imageUrl = "https://s.krea.ai/logo-icon-black.jpg";
Replace with your API TokenTo replace the YOUR_API_TOKEN placeholder in the above examples, you’ll need to generate an API token in krea.ai/settings/api-tokens. Follow the instructions on the API Keys & Billing page if you need help.

Step 2: Generate Image

Make a POST request to the appropriate endpoint with your image and parameters.
// npm install @krea-ai/sdk
import { Krea } from "@krea-ai/sdk";

const krea = new Krea({ apiKey: process.env.KREA_API_KEY });

const job = await krea.image("google/nano-banana-pro", {
  image_urls: [imageUrl],
  prompt: "Turn this logo into an aesthetic rug. Product Photography style, with an aura that would make me want it in my own living room."
});

console.log(`Job ID: ${job.job_id}`);
Example Response
{
  "created_at":"2026-02-13T02:20:58.265Z",
  "completed_at":null,
  "job_id":"757a315b-b3ed-457b-b1ba-cff5e140cfd4",
  "status":"processing",
  "type":"externalImage",
  "result":{}
}

Step 3: Poll for Results

Image generation is asynchronous. You’ll receive a job ID immediately, then poll for results until the image is ready. Poll /jobs/{job_id} every 2 seconds until the job completes.
// npm install @krea-ai/sdk
import { Krea } from "@krea-ai/sdk";

const krea = new Krea({ apiKey: process.env.KREA_API_KEY });

async function waitForJob(jobId) {
  const completed = await krea.jobs.wait(jobId, { intervalMs: 2000 });
  return completed.result.urls[0];
}

const imageUrl = await waitForJob(job.job_id);
console.log(`Image ready: ${imageUrl}`);
Example Completed Response

{
  "created_at":"2026-02-13T02:20:58.265Z",
  "completed_at":"2026-02-13T02:21:21.948Z",
  "job_id":"757a315b-b3ed-457b-b1ba-cff5e140cfd4",
  "status":"completed",
  "type":"externalImage",
  "result": {
    "urls": [
      "https://app-uploads.krea.ai/public/757a315b-b3ed-457b-b1ba-cff5e140cfd4-image.png"
    ]
  }
}
Webhooks available!Set up webhooks to receive notifications when jobs complete. See the Webhooks guide to get started.