0.3.2 • Published 1 month ago

@sunra/client v0.3.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

sunra JavaScript/TypeScript client library

@sunra/client npm package

Introduction

The Sunra JavaScript Client Library provides a seamless way to interact with Sunra endpoints from your JavaScript or TypeScript applications. With built-in support for various platforms, it ensures consistent behavior across web, Node.js, and React Native environments.

Getting started

Before diving into the client-specific features, ensure you've set up your credentials:

import { createSunraClient } from "@sunra/client";

const sunra = createSunraClient({
  credentials: "SUNRA_KEY",
});

Note: Ensure you've reviewed the sunra getting started guide to acquire your credentials and register your functions. Also, make sure your credentials are always protected. See the ../../server-proxy package for a secure way to use the client in client-side applications.

Running functions without waiting for the result

const { request_id } = await sunra.queue.submit(
  "sunra/lcm/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."
  },
});

Long-running functions with sunra.subscribe

The sunra.subscribe method offers a powerful way to rely on the queue system to execute long-running functions. It returns the result once it's done like any other async function, so your don't have to deal with queue status updates yourself. However, it does support queue events, in case you want to listen and react to them:

const result = await sunra.subscribe(
  "sunra/lcm/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."
    },
    onQueueUpdate(update) {
      if (update.status === "IN_QUEUE") {
        console.log(`Your position in the queue is ${update.position}`);
      }
    },
  }
);

More features

The client library offers a plethora of features designed to simplify your journey with sunra. Dive into the official documentation for a comprehensive guide.

Credits

This project is derived from

and adapted to work with sunra.ai. The original project is licensed under the MIT/Apache2.0 License. We extend our gratitude to the original authors for their contributions.

0.2.1-alpha.2

3 months ago

0.2.1-alpha.1

3 months ago

0.3.0-alpha.6

1 month ago

0.3.0-alpha.7

1 month ago

0.3.0-alpha.8

1 month ago

0.3.0

1 month ago

0.2.1

3 months ago

0.2.0

4 months ago

0.3.0-alpha.2

1 month ago

0.3.0-alpha.3

1 month ago

0.3.0-alpha.4

1 month ago

0.3.0-alpha.5

1 month ago

0.3.2

1 month ago

0.2.3

1 month ago

0.2.2

3 months ago

0.3.0-alpha.1

1 month ago

0.1.2

4 months ago

0.1.1-alpha.2

4 months ago

0.1.2-alpha.2

4 months ago

0.1.3

4 months ago

0.1.2-alpha.1

4 months ago

0.1.1

5 months ago

0.1.0-alpha.2

5 months ago

0.1.0-alpha.1

5 months ago

0.1.0

5 months ago