ballerinax/openai.images Ballerina library

1.0.1

Overview

This is a generated connector for the OpenAI Images API OpenAPI Specification. OpenAI is an American artificial intelligence research laboratory consisting of a non-profit corporation and a for-profit subsidiary. OpenAI conducts AI research with the declared intention of promoting and developing friendly AI. The OpenAI Images API provides a way to access new DALL.E models developed by OpenAI for a variety of image-related tasks.

Prerequisites

Before using this connector in your Ballerina application, complete the following:

Quick start

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

Step 1: Import the connector

First, import the ballerinax/openai.images module into the Ballerina project.

Copy
import ballerinax/openai.images;
import ballerina/io;

Step 2: Create a new connector instance

Create and initialize an images:Client with the obtained apiKey.

Copy
images:Client imagesClient = check new ({
    auth: {
        token: "sk-XXXXXXXXX"
    }
});

Step 3: Invoke the connector operation

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

    Following is an example on generating image using the OpenAI DALL.E model:

    Generate image with DALL.E

    Copy
    public function main() returns error? {
        images:CreateImageRequest createImageRequest = {
            prompt: "A cute baby sea otter",
            n: 1,
            size: "256x256",
            response_format: "url",
            user: "user-1234"
        };
        images:ImagesResponse|error unionResult = check imagesClient->/images/generations.post(createImageRequest);
        if unionResult is images:ImagesResponse {
            io:println(unionResult);
        } else {
            io:println(unionResult);
        }
    }
  2. Use thebal run command to compile and run the Ballerina program.

Sample

Copy
import ballerinax/openai.images;
import ballerina/io;

images:Client imagesClient = check new ({
    auth: {
        token: "sk-XXXXXXXXX"
    }
});

public function main() returns error? {
    images:CreateImageRequest createImageRequest = {
        prompt: "A cute baby sea otter",
        n: 1,
        size: "256x256",
        response_format: "url",
        user: "user-1234"
    };
    images:ImagesResponse|error unionResult = check imagesClient->/images/generations.post(createImageRequest);
    if unionResult is images:ImagesResponse {
        io:println(unionResult);
    } else {
        io:println(unionResult);
    }
}

Import

import ballerinax/openai.images;Copy

Metadata

Released date: over 1 year ago

Version: 1.0.1

License: Apache-2.0


Compatibility

Platform: any

Ballerina version: 2201.4.0

GraalVM compatible: Yes


Pull count

Total: 52

Current verison: 9


Weekly downloads


Source repository


Keywords

AI/OpenAI

Cost/Paid

image generation

DALLE


Contributors

Other versions

See more...