Introduction
The client library for JavaScript/TypeScript offers an easy-to-use interface to interact with Sunra’s services.
Installation
To integrate the client into your project, install it using npm:
npm install @sunra/client
Features
Calling Endpoints
Sunra manages endpoint requests through a queue system, ensuring reliability and scalability. Use the subscribe
method to submit a request and await the result.
Example:
import { sunra } from "@sunra/client";
const result = await sunra.subscribe("black-forest-labs/flux-kontext-pro/text-to-image", {
input: {
prompt: "A glass teapot with blooming flower tea inside, placed on a wooden table by a sunlit window with gentle morning light.",
"aspect_ratio": "16:9",
"output_format": "jpeg",
},
logs: true,
onQueueUpdate: (update) => {
if (update.status === "IN_PROGRESS") {
console.log(update.logs)
}
},
});
console.log(result.data);
console.log(result.requestId);
Queue Management
Manage your requests with these methods:
Submitting a Request
Submit a request and retrieve the request_id
for later use.
Example:
import { sunra } from "@sunra/client";
const { request_id } = await sunra.queue.submit("black-forest-labs/flux-kontext-max", {
input: {
prompt: "A glass teapot with blooming flower tea inside, placed on a wooden table by a sunlit window with gentle morning light.",
"aspect_ratio": "16:9",
"output_format": "jpeg",
},
});
Checking Request Status
Retrieve the status of a request.
Example:
import { sunra } from "@sunra/client";
const status = await sunra.queue.status({
requestId: "pd_eTYYuw4EqYLzRBHgnAMHA8zH",
logs: true,
});
Retrieving Request Results
Fetch the result of a completed request.
Example:
import { sunra } from "@sunra/client";
const result = await sunra.queue.result({
requestId: "pd_eTYYuw4EqYLzRBHgnAMHA8zH",
});
console.log(result.data);
console.log(result.requestId);
File Uploads
Upload files to obtain URLs for use in asynchronous requests.
Example:
import { sunra } from "@sunra/client";
const file = new File(["your file content"], "file.txt", { type: "text/plain" });
const url = await sunra.storage.upload(file);
Support
Join our community for help or discussions:
We’re here to assist you!