/stability

Primary LanguageDartApache License 2.0Apache-2.0

Stability AI API client

This package prepared by using the documentation.

All endpoints are implemented.

Available Endpoints

Group Endpoint Status
Engines
List Engines ☑️
User
Account ☑️
Balance ☑️
SDXL & SD1.6
Text to Image
Image to Image with Prompt ☑️
Image to Image with Mask ☑️
Image to Image upscale ☑️
3D
Stable Fast 3D ☑️
Video
Start Generation ☑️
Fetch Generation Result ☑️
Stable Image - Generate
Ultra ☑️
Core ☑️
Diffusion 3 - text2image
Diffusion 3 - image2image ☑️
Stable Image - Upscale
Conservative ☑️
Start Upscale ☑️
Fetch Upscale Result ☑️
Stable Image - Edit
Erase ☑️
Inpaint ☑️
Outpaint ☑️
Search & Replace ☑️
Remove Background ☑️
Stable Image - Control
Sketch ☑️
Structure ☑️
Style ☑️
  • ❌ : not finished
  • ☑️ : Not Tested
  • ✅ : finished

Example:

import 'package:stability/stability.dart';

void main() async {
 final stability = Stability(apiKey: "YOUR_API_KEY");
 // or
 final stability = Stability(); // apiKey will be read from STABILITY_API_KEY environment variable or --stability-api-key argument

 final engines = await stability.engines.list();

 print(engines);

 final FileHandler file = stability.image.generate.diffusion3Image2Image(
     image: FileFrom.path("path/to/image.jpg"),
     strength: 0.5
 );

 await file.writeToFile("path/to/output.jpg");
 // or
 final Uint8List bytes = await file.readAsBytes();

 final (seed, finishReason) = await file.readHeaders();

 print(seed);
}

Providing Files

Anywhere a file is required, you can provide it in the following ways:

doIt() {
  FileFrom.path("path/to/file.jpg");

  FileFrom.bytes(Uint8List.fromList([1, 2, 3]));

  FileFrom.base64("base64encodedstring");
}

Handling Files

Anywhere a file is returned, you can handle it in the following ways:

If the endpoint returns single file:

doIt() async {
  final FileHandler file = stability.image.generate.diffusion3Image2Image(
      image: FileFrom.path("path/to/image.jpg"),
      strength: 0.5
  );


  await file.writeToFile("path/to/output.jpg");

// or

  final Uint8List bytes = await file.readAsBytes();
}

If the endpoint returns multiple files:

doIt() async {
  final res = await stability.sdxlV1.textToImage();

  final Base64File file1 = res.files[0];

  await file1.writeToFile("path/to/output1.jpg");

  final bytes = file1.readAsBytes();
}

Handling Errors

doIt() async {
  try {
    final res = await stability.sdxlV1.textToImage();
  } on StabilityError catch (e) {
    print(e.status); // 404
    print(e.statusText); // Not Found
    print(e.body); // {"foo": "bar"}  
  }
}

That's it! You're ready to use the Stability AI API client.

NOTE: This package is not an official package of Stability AI. It is created by Mehmet Yaz.

Support

"Buy Me A Coffee"