import { SegmentationAPIClient } from "@segmentationapi/sdk";
const apiKey = process.env.SEGMENTATION_API_KEY;
if (!apiKey) {
throw new Error("SEGMENTATION_API_KEY is required");
}
const client = new SegmentationAPIClient({ token: apiKey });
const upload = await client.uploads.createUploadPresign({ contentType: "image/png" });
await fetch(upload.uploadUrl, {
method: "PUT",
headers: { "content-type": "image/png" },
body: pngBytes,
});
const created = await client.jobs.createJob({
type: "image",
tasks: [upload.taskId],
prompts: ["person"],
});
const job = await client.jobs.retrieveJob({ jobId: created.jobId });
if (job.status === "success") {
const result = await client.jobs.retrieveJobResult({ jobId: job.jobId });
console.log(result.assets);
}