stabilityai
Module stabilityai
API
Definitions
![](https://bcentral-packageicons.azureedge.net/images/ballerinax_stabilityai_1.0.1.png)
ballerinax/stabilityai Ballerina library
Overview
This is a generated connector from Stability.ai REST API (v1) OpenAPI specification.
Prerequisites
- Create an Stability AI account.
- Obtain the API key. Refer to Satbility AI Authentication to learn how to obtain API key.
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.
import ballerinax/stabilityai;
Step 2: Create a new connector instance
Create and initialize a stabilityai:Client
with the obtained apiKey
from the Satbility AI
final stabilityai:Client stabilityaiClient = check new ({authorization: api_key});
Step 3: Invoke connector operation
- 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:
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); } } });
- Use
bal run
command to compile and run the Ballerina program.
Clients![](/images/permalink.svg)
stabilityai: Client![](/images/permalink.svg)
Welcome to the Stability.ai REST API!
Your DreamStudio API key will be required for authentication: How to find your API key
API operations use the following versioning scheme:
/v*
interface is stable and ready for production workloads/v*beta*
: interface is stable, preparing for production release/v*alpha*
: under development and the interface is subject to change
NOTE: The v1alpha and v1beta endpoints from the developer preview are still available, but they will disabled on May 1st, 2023. Please migrate to the v1 endpoints as soon as possible.
If you have feedback or encounter any issues with the API, please reach out:
Constructor![](/images/permalink.svg)
Gets invoked to initialize the connector
.
init (ApiKeysConfig apiKeyConfig, ConnectionConfig config, string serviceUrl)
- apiKeyConfig ApiKeysConfig - API keys for authorization
- config ConnectionConfig {} - The configurations to be used when initializing the
connector
- serviceUrl string "https://api.stability.ai" - URL of the target service
post v1/generation/[string engine_id]/'text-to-image![](/images/permalink.svg)
function post v1/generation/[string engine_id]/'text\-to\-image(TextToImageRequestBody payload, string accept, string? organization) returns ImageRes|error
text-to-image
Parameters
- payload TextToImageRequestBody -
- accept string (default "application/json") - The format of the response. Leave blank for JSON, or set to 'image/png' for a PNG image.
- organization string? (default ()) - Allows for requests to be scoped to an organization other than the user's default. If not provided, the user's default organization will be used.
post v1/generation/[string engine_id]/'image-to-image![](/images/permalink.svg)
function post v1/generation/[string engine_id]/'image\-to\-image(ImageToImageRequestBody payload, string accept, string? organization) returns ImageRes|error
image-to-image
Parameters
- payload ImageToImageRequestBody -
- accept string (default "application/json") - The format of the response. Leave blank for JSON, or set to 'image/png' for a PNG image.
- organization string? (default ()) - Allows for requests to be scoped to an organization other than the user's default. If not provided, the user's default organization will be used.
post v1/generation/[string engine_id]/'image-to-image/upscale![](/images/permalink.svg)
function post v1/generation/[string engine_id]/'image\-to\-image/upscale(UpscaleImageRequestBody payload, string accept, string? organization) returns ImageRes|error
image-to-image/upscale
Parameters
- payload UpscaleImageRequestBody -
- accept string (default "application/json") - The format of the response. Leave blank for JSON, or set to 'image/png' for a PNG image.
- organization string? (default ()) - Allows for requests to be scoped to an organization other than the user's default. If not provided, the user's default organization will be used.
post v1/generation/[string engine_id]/'image-to-image/masking![](/images/permalink.svg)
function post v1/generation/[string engine_id]/'image\-to\-image/masking(MaskingRequestBody payload, string accept, string? organization) returns ImageRes|error
image-to-image/masking
Parameters
- payload MaskingRequestBody -
- accept string (default "application/json") - The format of the response. Leave blank for JSON, or set to 'image/png' for a PNG image.
- organization string? (default ()) - Allows for requests to be scoped to an organization other than the user's default. If not provided, the user's default organization will be used.
get v1/engines/list![](/images/permalink.svg)
list
Parameters
- organization string? (default ()) - Allows for requests to be scoped to an organization other than the user's default. If not provided, the user's default organization will be used.
Return Type
- ListEnginesResponseBody|error - OK response.
get v1/user/account![](/images/permalink.svg)
function get v1/user/account() returns AccountResponseBody|error
account
Return Type
- AccountResponseBody|error - OK response.
get v1/user/balance![](/images/permalink.svg)
function get v1/user/balance(string? organization) returns BalanceResponseBody|error
balance
Parameters
- organization string? (default ()) - Allows for requests to be scoped to an organization other than the user's default. If not provided, the user's default organization will be used.
Return Type
- BalanceResponseBody|error - OK response.
Records![](/images/permalink.svg)
stabilityai: AccountResponseBody![](/images/permalink.svg)
Fields
- email string - The user's email
- id string - The user's ID
- organizations OrganizationMembership[] - The user's organizations
- profile_picture string? - The user's profile picture
stabilityai: ApiKeysConfig![](/images/permalink.svg)
Provides API key configurations needed when communicating with a remote HTTP endpoint.
Fields
- authorization string -
stabilityai: BalanceResponseBody![](/images/permalink.svg)
Fields
- credits decimal - The balance of the account/organization associated with the API key
stabilityai: ClientHttp1Settings![](/images/permalink.svg)
Provides settings related to HTTP/1.x protocol.
Fields
- keepAlive KeepAlive(default http:KEEPALIVE_AUTO) - Specifies whether to reuse a connection for multiple requests
- chunking Chunking(default http:CHUNKING_AUTO) - The chunking behaviour of the request
- proxy ProxyConfig? - Proxy server related options
stabilityai: ConnectionConfig![](/images/permalink.svg)
Provides a set of configurations for controlling the behaviours when communicating with a remote HTTP endpoint.
Fields
- httpVersion HttpVersion(default http:HTTP_2_0) - The HTTP version understood by the client
- http1Settings ClientHttp1Settings? - Configurations related to HTTP/1.x protocol
- http2Settings ClientHttp2Settings? - Configurations related to HTTP/2 protocol
- timeout decimal(default 60) - The maximum time to wait (in seconds) for a response before closing the connection
- forwarded string(default "disable") - The choice of setting
forwarded
/x-forwarded
header
- poolConfig PoolConfiguration? - Configurations associated with request pooling
- cache CacheConfig? - HTTP caching related configurations
- compression Compression(default http:COMPRESSION_AUTO) - Specifies the way of handling compression (
accept-encoding
) header
- circuitBreaker CircuitBreakerConfig? - Configurations associated with the behaviour of the Circuit Breaker
- retryConfig RetryConfig? - Configurations associated with retrying
- responseLimits ResponseLimitConfigs? - Configurations associated with inbound response size limits
- secureSocket ClientSecureSocket? - SSL/TLS-related options
- proxy ProxyConfig? - Proxy server related options
- validation boolean(default true) - Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default
stabilityai: Engine![](/images/permalink.svg)
Fields
- description string -
- id string - Unique identifier for the engine
- name string - Name of the engine
- 'type string - The type of content this engine produces
stabilityai: Error![](/images/permalink.svg)
Fields
- id string - A unique identifier for this particular occurrence of the problem.
- name string - The short-name of this class of errors e.g.
bad_request
.
- message string - A human-readable explanation specific to this occurrence of the problem.
stabilityai: GenerationRequestOptionalParams![](/images/permalink.svg)
Represents the optional parameters that can be passed to any generation request.
Fields
- cfg_scale CfgScale? - How strictly the diffusion process adheres to the prompt text (higher values keep your image closer to your prompt)
- clip_guidance_preset ClipGuidancePreset? -
- sampler Sampler? - Which sampler to use for the diffusion process. If this value is omitted we'll automatically select an appropriate sampler for you.
- samples Samples? - Number of images to generate
- seed Seed? - Random noise seed (omit this option or use
0
for a random seed)
- steps Steps? - Number of diffusion steps to run
stabilityai: Image![](/images/permalink.svg)
Fields
- 'base64 string? - Image encoded in base64
- finishReason string? -
- seed decimal? - The seed associated with this image
stabilityai: ImageRes![](/images/permalink.svg)
Fields
- artifacts Image[] - Array containing one or more images as base64 encoded strings.
stabilityai: ImageToImageRequestBody![](/images/permalink.svg)
Fields
- 'text_prompts\[0\]\[text\] string -
- 'text_prompts\[0\]\[weight\] float -
- init_image InitImage - Image used to initialize the diffusion process, in lieu of random noise.
- init_image_mode InitImageMode? - Whether to use
image_strength
orstep_schedule_*
to control how much influence theinit_image
has on the result.
- image_strength InitImageStrength? - How much influence the
init_image
has on the diffusion process. Values close to1
will yield images very similar to theinit_image
while values close to0
will yield images wildly different than theinit_image
. The behavior of this is meant to mirror DreamStudio's "Image Strength" slider. <br/> <br/> This parameter is just an alternate way to setstep_schedule_start
, which is done via the calculation1 - image_strength
. For example, passing in an Image Strength of 35% (0.35
) would result in astep_schedule_start
of0.65
.
- step_schedule_start StepScheduleStart? - Skips a proportion of the start of the diffusion steps, allowing the init_image to influence the final generated image. Lower values will result in more influence from the init_image, while higher values will result in more influence from the diffusion steps. (e.g. a value of
0
would simply return you the init_image, where a value of1
would return you a completely different image.)
- step_schedule_end StepScheduleEnd? - Skips a proportion of the end of the diffusion steps, allowing the init_image to influence the final generated image. Lower values will result in more influence from the init_image, while higher values will result in more influence from the diffusion steps.
- cfg_scale CfgScale? - How strictly the diffusion process adheres to the prompt text (higher values keep your image closer to your prompt)
- clip_guidance_preset ClipGuidancePreset? -
- sampler Sampler? - Which sampler to use for the diffusion process. If this value is omitted we'll automatically select an appropriate sampler for you.
- samples Samples? - Number of images to generate
- seed Seed? - Random noise seed (omit this option or use
0
for a random seed)
- steps Steps? - Number of diffusion steps to run
stabilityai: InitImage![](/images/permalink.svg)
Image used to initialize the diffusion process, in lieu of random noise.
Fields
- fileContent byte[] -
- fileName string -
stabilityai: InputImage![](/images/permalink.svg)
Fields
- fileContent byte[] -
- fileName string -
stabilityai: MaskImage![](/images/permalink.svg)
Optional grayscale mask that allows for influence over which pixels are eligible for diffusion and at what strength. Must be the same dimensions as the init_image
. Use the mask_source
option to specify whether the white or black pixels should be inpainted.
Fields
- fileContent byte[] -
- fileName string -
stabilityai: MaskingRequestBody![](/images/permalink.svg)
Fields
- init_image InitImage - Image used to initialize the diffusion process, in lieu of random noise.
- mask_source MaskSource - For any given pixel, the mask determines the strength of generation on a linear scale. This parameter determines where to source the mask from:
MASK_IMAGE_WHITE
will use the white pixels of the mask_image as the mask, where white pixels are completely replaced and black pixels are unchangedMASK_IMAGE_BLACK
will use the black pixels of the mask_image as the mask, where black pixels are completely replaced and white pixels are unchangedINIT_IMAGE_ALPHA
will use the alpha channel of the init_image as the mask, where fully transparent pixels are completely replaced and fully opaque pixels are unchanged
- mask_image MaskImage? - Optional grayscale mask that allows for influence over which pixels are eligible for diffusion and at what strength. Must be the same dimensions as the
init_image
. Use themask_source
option to specify whether the white or black pixels should be inpainted.
- 'text_prompts\[0\]\[text\] string -
- 'text_prompts\[0\]\[weight\] float -
- cfg_scale CfgScale? - How strictly the diffusion process adheres to the prompt text (higher values keep your image closer to your prompt)
- clip_guidance_preset ClipGuidancePreset? -
- sampler Sampler? - Which sampler to use for the diffusion process. If this value is omitted we'll automatically select an appropriate sampler for you.
- samples Samples? - Number of images to generate
- seed Seed? - Random noise seed (omit this option or use
0
for a random seed)
- steps Steps? - Number of diffusion steps to run
stabilityai: OrganizationMembership![](/images/permalink.svg)
Fields
- id string -
- is_default boolean -
- name string -
- role string -
stabilityai: ProxyConfig![](/images/permalink.svg)
Proxy server configurations to be used with the HTTP client endpoint.
Fields
- host string(default "") - Host name of the proxy server
- port int(default 0) - Proxy server port
- userName string(default "") - Proxy server username
- password string(default "") - Proxy server password
stabilityai: TextPrompt![](/images/permalink.svg)
Text prompt for image generation
Fields
- text string - The prompt itself
- weight float? - Weight of the prompt (use negative numbers for negative prompts)
stabilityai: TextToImageRequestBody![](/images/permalink.svg)
Fields
- height DiffuseImageHeight? - Height of the image in pixels. Must be in increments of 64 and pass the following validation:
- For 768 engines: <span style='display: flex; justify-content: flex-start; gap:8px'>589,824 <span>≤</span>
height * width
<span>≤</span> 1,048,576</span> - All other engines: <span style='display: flex; justify-content: flex-start; gap:8px'>262,144 <span>≤</span>
height * width
<span>≤</span> 1,048,576</span>
- For 768 engines: <span style='display: flex; justify-content: flex-start; gap:8px'>589,824 <span>≤</span>
- width DiffuseImageWidth? - Width of the image in pixels. Must be in increments of 64 and pass the following validation:
- For 768 engines: <span style='display: flex; justify-content: flex-start; gap:8px'>589,824 <span>≤</span>
height * width
<span>≤</span> 1,048,576</span> - All other engines: <span style='display: flex; justify-content: flex-start; gap:8px'>262,144 <span>≤</span>
height * width
<span>≤</span> 1,048,576</span>
- For 768 engines: <span style='display: flex; justify-content: flex-start; gap:8px'>589,824 <span>≤</span>
- text_prompts TextPromptsForTextToImage - An array of text prompts to use for generation.
Given a text prompt with the text
A lighthouse on a cliff
and a weight of0.5
, it would be represented as: <pre> "text_prompts": [ { "text": "A lighthouse on a cliff", "weight": 0.5 } ] </pre>
- Fields Included from *GenerationRequestOptionalParams
stabilityai: UpscaleImageRequestBody![](/images/permalink.svg)
Fields
- image InputImage -
- width UpscaleImageWidth? - Desired width of the output image. Only one of
width
orheight
may be specified.
- height UpscaleImageHeight? - Desired height of the output image. Only one of
width
orheight
may be specified.
String types![](/images/permalink.svg)
stabilityai: ClipGuidancePreset![](/images/permalink.svg)
ClipGuidancePreset
stabilityai: FinishReason![](/images/permalink.svg)
FinishReason
The result of the generation process.
SUCCESS
indicates successERROR
indicates an errorCONTENT_FILTERED
indicates the result affected by the content filter and may be blurred.
This header is only present when the Accept
is set to image/png
. Otherwise it is returned in the response body.
stabilityai: InitImageMode![](/images/permalink.svg)
InitImageMode
Whether to use image_strength
or step_schedule_*
to control how much influence the init_image
has on the result.
stabilityai: MaskSource![](/images/permalink.svg)
MaskSource
For any given pixel, the mask determines the strength of generation on a linear scale. This parameter determines where to source the mask from:
MASK_IMAGE_WHITE
will use the white pixels of the mask_image as the mask, where white pixels are completely replaced and black pixels are unchangedMASK_IMAGE_BLACK
will use the black pixels of the mask_image as the mask, where black pixels are completely replaced and white pixels are unchangedINIT_IMAGE_ALPHA
will use the alpha channel of the init_image as the mask, where fully transparent pixels are completely replaced and fully opaque pixels are unchanged
stabilityai: Sampler![](/images/permalink.svg)
Sampler
Which sampler to use for the diffusion process. If this value is omitted we'll automatically select an appropriate sampler for you.
Integer types![](/images/permalink.svg)
stabilityai: DiffuseImageHeight![](/images/permalink.svg)
DiffuseImageHeight
Height of the image in pixels. Must be in increments of 64 and pass the following validation:
- For 768 engines: 589,824 ≤
height * width
≤ 1,048,576 - All other engines: 262,144 ≤
height * width
≤ 1,048,576
stabilityai: DiffuseImageWidth![](/images/permalink.svg)
DiffuseImageWidth
Width of the image in pixels. Must be in increments of 64 and pass the following validation:
- For 768 engines: 589,824 ≤
height * width
≤ 1,048,576 - All other engines: 262,144 ≤
height * width
≤ 1,048,576
stabilityai: Samples![](/images/permalink.svg)
Samples
Number of images to generate
stabilityai: Seed![](/images/permalink.svg)
Seed
Random noise seed (omit this option or use 0
for a random seed)
stabilityai: Steps![](/images/permalink.svg)
Steps
Number of diffusion steps to run
stabilityai: UpscaleImageHeight![](/images/permalink.svg)
UpscaleImageHeight
Desired height of the output image. Only one of width
or height
may be specified.
stabilityai: UpscaleImageWidth![](/images/permalink.svg)
UpscaleImageWidth
Desired width of the output image. Only one of width
or height
may be specified.
Decimal types![](/images/permalink.svg)
stabilityai: CfgScale![](/images/permalink.svg)
CfgScale
How strictly the diffusion process adheres to the prompt text (higher values keep your image closer to your prompt)
stabilityai: StepScheduleEnd![](/images/permalink.svg)
StepScheduleEnd
Skips a proportion of the end of the diffusion steps, allowing the init_image to influence the final generated image. Lower values will result in more influence from the init_image, while higher values will result in more influence from the diffusion steps.
stabilityai: StepScheduleStart![](/images/permalink.svg)
StepScheduleStart
Skips a proportion of the start of the diffusion steps, allowing the init_image to influence the final generated image. Lower values will result in more influence from the init_image, while higher values will result in more influence from the diffusion steps. (e.g. a value of 0
would simply return you the init_image, where a value of 1
would return you a completely different image.)
Import
import ballerinax/stabilityai;
Metadata
Released date: over 1 year ago
Version: 1.0.1
License: Apache-2.0
Compatibility
Platform: any
Ballerina version: 2201.4.1
GraalVM compatible: Yes
Pull count
Total: 4
Current verison: 1
Weekly downloads
Keywords
AI/Images
Vendor/Stability AI
Cost/Paid
Stable Diffusion
Contributors
Other versions
1.0.1
1.0.0