SDKs

@segmentationapi/sdk wraps the generated Fetch client from api/openapi.yaml.

1pnpm add @segmentationapi/sdk
1import { SegmentationAPIClient } from "@segmentationapi/sdk";
2
3const apiKey = process.env.SEGMENTATION_API_KEY;
4if (!apiKey) {
5 throw new Error("SEGMENTATION_API_KEY is required");
6}
7
8const client = new SegmentationAPIClient({ token: apiKey });
9const upload = await client.uploads.createUploadPresign({ contentType: "image/png" });
10
11await fetch(upload.uploadUrl, {
12 method: "PUT",
13 headers: { "content-type": "image/png" },
14 body: pngBytes,
15});
16
17const created = await client.jobs.createJob({
18 type: "image",
19 tasks: [upload.taskId],
20 prompts: ["person"],
21});
22
23const job = await client.jobs.retrieveJob({ jobId: created.jobId });
24if (job.status === "success") {
25 const result = await client.jobs.retrieveJobResult({ jobId: job.jobId });
26 console.log(result.assets);
27}

Keep keys on a server. Browser apps should use an access-token provider, not sk_live_.