ballerinax/stabilityai Ballerina library

1.0.2

Overview

The Stability.ai REST API (v1) connector(https://platform.stability.ai/rest-api) OpenAPI specification.

Key Features

  • Programmatic access to create and manage resources via REST API
  • Send and publish data through the API
  • Manage user accounts and profiles
  • Secure authentication with API key or OAuth support

Prerequisites

Quickstart

To use the Stability AI connector in your Ballerina application, update the .bal file as follows:

Step 1: Import connector

Import the ballerinax/stabilityai module into the Ballerina project.

Copy
import ballerinax/stabilityai;

Step 2: Create a new connector instance

Create and initialize a stabilityai:Client with the obtained apiKey from the Satbility AI

Copy
final stabilityai:Client stabilityaiClient = check new ({authorization: api_key});

Step 3: Invoke connector operation

  1. Now you can use the operations available within the connector.

Note: that they are in the form of remote operations.

Following is an example on generating an image based on the text prompt:

Copy
stabilityai:TextToImageRequestBody payload = {
    text_prompts: [
        {
            "text": "A lighthouse on a cliff",
            "weight": 1
        }
    ]
};

stabilityai:ImageRes listResult = check stabilityaiClient->/v1/generation/["stable-diffusion-v1"]/text\-to\-image.post(payload);

listResult.artifacts.forEach(function(stabilityai:Image image) {
    string? imageBytesString = image.'base64;
    if imageBytesString is () {
        io:println("Image byte string is Empty");
        return;
    }
    byte[] imageBytes = imageBytesString.toBytes();
    var base64Decode = mime:base64Decode(imageBytes);
    if base64Decode is error {
        io:println("Error: ", base64Decode);
        return;
    }
    if base64Decode is byte[] {
        io:Error? fileWrite = io:fileWriteBytes("./output.png", base64Decode);
        if fileWrite is io:Error {
            io:println("Error: ", fileWrite);
        }
    }
});
  1. Use bal run command to compile and run the Ballerina program.

Import

import ballerinax/stabilityai;Copy

Other versions

Metadata

Released date: 3 days ago

Version: 1.0.2

License: Apache-2.0


Compatibility

Platform: any

Ballerina version: 2201.8.0

GraalVM compatible: Yes


Pull count

Total: 42

Current verison: 0


Weekly downloads


Source repository


Keywords

Type/Connector

AI/Images

Vendor/Stability AI

Area/AI & Machine Learning

Cost/Paid

Stable Diffusion


Contributors