Sdcb.StabilityAI 1.1.0

Prefix Reserved
dotnet add package Sdcb.StabilityAI --version 1.1.0                
NuGet\Install-Package Sdcb.StabilityAI -Version 1.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sdcb.StabilityAI" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Sdcb.StabilityAI --version 1.1.0                
#r "nuget: Sdcb.StabilityAI, 1.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Sdcb.StabilityAI as a Cake Addin
#addin nuget:?package=Sdcb.StabilityAI&version=1.1.0

// Install Sdcb.StabilityAI as a Cake Tool
#tool nuget:?package=Sdcb.StabilityAI&version=1.1.0                

Sdcb.StabilityAI NuGet NuGet GitHub

Unofficial Stability AI rest API C# SDK, upstream Stability API documentation: https://platform.stability.ai/rest-api

Functions mapping

All functions are in class StabilityAIClient and all are async.

API Endpoint C# Function Name Description
GET /v1/user/account GetUserAccountAsync Returns the user account information
GET /v1/user/balance GetUserBalanceAsync Returns the current balance of the user's account
GET /v1/engines/list GetAllEnginesAsync Returns a list of all available engine names
POST /v1/generation/:engine/text-to-image TextToImageAsync Generates an image from text using the specified engine ID and image generation options
POST /v1/generation/:engine/image-to-image ImageToImageAsync Generates a new image from an input image and prompts using the specified engine ID and image generation options
POST /v1/generation/:engine/image-to-image/upscale UpscaleImageAsync Upscales an input image using the specified upscale engine ID and desired width or height for the output image
POST /v1/generation/:engine/image-to-image/masking MaskImageAsync Generates an image based on the specified mask using the given engine ID and MaskImageRequest options

Usage

First you need to get a DreamStudios API key from https://dreamstudio.ai/account and then you can use it to create an instance of the StabilityAIClient class.

Example 1: Get User Account

In this example, we demonstrate how to get user account information using the StabilityAIClient class.

using Sdcb.StabilityAI;

// Create an instance of the StabilityAIClient using your API key
StabilityAIClient aiClient = new StabilityAIClient("your_api_key_here");

// Get the user account information and display it
UserAccount userAccount = await aiClient.GetUserAccountAsync();
Console.WriteLine($"User ID: {userAccount.Id}");
Console.WriteLine($"Email: {userAccount.Email}");

Example 2: Get User Balance

In this example, we demonstrate how to get the account balance using the StabilityAIClient class.

using Sdcb.StabilityAI;

// Create an instance of the StabilityAIClient using your API key
StabilityAIClient aiClient = new StabilityAIClient("your_api_key_here");

// Get the user balance and display it
decimal balance = await aiClient.GetUserBalanceAsync();
Console.WriteLine($"Remaining balance: ${balance}");

Example 3: Get Engine List

In this example, we demonstrate how to get the list of available engines using the StabilityAIClient class.

using Sdcb.StabilityAI;

// Create an instance of the StabilityAIClient using your API key
StabilityAIClient aiClient = new StabilityAIClient("your_api_key_here");

// Get the engine list and display it
EngineInfo[] engineList = await aiClient.GetAllEnginesAsync();
foreach (EngineInfo engine in engineList)
{
    Console.WriteLine($"Engine ID: {engine.Id} - Name: {engine.Name}");
}

Example 4: Text to Image

In this example, we demonstrate how to generate an image from text using the StabilityAIClient class.

using Sdcb.StabilityAI;

// Create an instance of the StabilityAIClient using your API key
StabilityAIClient aiClient = new StabilityAIClient("your_api_key_here");

// Set up the TextToImageRequest options
TextToImageRequest options = new TextToImageRequest
{
    Samples = 2,
    Width = 128,
    Height = 256,
    Seed = 1,
    Steps = 20,
    TextPrompts = new TextPrompt[]
    {
        new TextPrompt("A beautiful sunset over the ocean."),
    }
};

// Generate the image from text using the specified options
Artifact[] generatedImages = await aiClient.TextToImageAsync(options);

// Save generated images to files
foreach (Artifact image in generatedImages)
{
    string fileName = $"generated-{image.Seed}.png";
    File.WriteAllBytes(fileName, Convert.FromBase64String(image.Base64));
}

Example 5: Image to Image

In this example, we demonstrate how to generate a new image from an input image and prompts using the StabilityAIClient class.

using Sdcb.StabilityAI;

// Create an instance of the StabilityAIClient using your API key
StabilityAIClient aiClient = new StabilityAIClient("your_api_key_here");

// Set up the ImageToImageRequest options
ImageToImageRequest options = new ImageToImageRequest
{
    InitImage = File.ReadAllBytes("input_image.jpg"),
    Samples = 2,
    Seed = 1,
    Steps = 20,
    TextPrompts = new TextPrompt[]
    {
        new TextPrompt("3 cat"),
    },
    StylePreset = "anime",
};

// Generate the new image from the input image and prompts using the specified options
Artifact[] generatedImages = await aiClient.ImageToImageAsync(options);

// Save generated images to files
foreach (Artifact image in generatedImages)
{
    string fileName = $"image_to_image-{image.Seed}.png";
    File.WriteAllBytes(fileName, Convert.FromBase64String(image.Base64));
}

Example 6: Upscale Image

In this example, we demonstrate how to upscale an input image using the StabilityAIClient class.

using Sdcb.StabilityAI;

// Create an instance of the StabilityAIClient using your API key
StabilityAIClient aiClient = new StabilityAIClient("your_api_key_here");

// Set up the UpscaleRequest options
UpscaleRequest options = new UpscaleRequest
{
    Image = File.ReadAllBytes("input_image.jpg"),
    Width = 2048,
};

// Upscale the input image using the specified options
Artifact[] upscaledImages = await aiClient.UpscaleImageAsync(options);

// Save upscaled images to files
foreach (Artifact image in upscaledImages)
{
    string fileName = $"upscaled-{image.Seed}.png";
    File.WriteAllBytes(fileName, Convert.FromBase64String(image.Base64));
}

Example 7: Mask Image

In this example, we demonstrate how to generate an image based on a specified mask using the StabilityAIClient class.

using Sdcb.StabilityAI;

// Create an instance of the StabilityAIClient using your API key
StabilityAIClient aiClient = new StabilityAIClient("your_api_key_here");

// Set up the MaskImageRequest options
MaskImageRequest options = new MaskImageRequest
{
    InitImage = File.ReadAllBytes("source_image.jpg"),
    MaskImage = File.ReadAllBytes("mask_image.jpg"),
    TextPrompts = new TextPrompt[]
    {
        new TextPrompt("empty"),
    },
    MaskSource = "MASK_IMAGE_WHITE",
    Samples = 2,
    Seed = 1,
    Steps = 20,
};

// Generate the masked image using the specified options
Artifact[] maskedImages = await aiClient.MaskImageAsync(options);

// Save masked images to files
foreach (Artifact image in maskedImages)
{
    string fileName = $"masked-{image.Seed}.png";
    File.WriteAllBytes(fileName, Convert.FromBase64String(image.Base64));
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0 22,682 6/19/2023
1.0.0 206 6/13/2023