Skip to main content

Stability AI

Setup

  1. You can get an API key from Stability AI.
  2. The API key can be configured as an environment variable (STABILITY_API_KEY) or passed in as an option into the model constructor.

Model Functions

Examples

Generate Image

StabilityImageGenerationModel API

import { stability, generateImage } from "modelfusion";

const imageBase64 = await generateImage({
model: stability.ImageGenerator({
model: "stable-diffusion-v1-6",
cfgScale: 7,
clipGuidancePreset: "FAST_BLUE",
height: 512,
width: 512,
steps: 30,
}),

prompt: [
{ text: "the wicked witch of the west" },
{ text: "style of early 19th century painting", weight: 0.5 },
],
});

Prompt Template

Basic text prompt

You an use mapBasicPromptToStabilityFormat() to use text prompts with Stability models. It is available as a shorthand method:

const image = await generateImage({
model: stability
.ImageGenerator({
//...
})
.withTextPrompt(),

prompt:
"the wicked witch of the west in the style of early 19th century painting",
});

Configuration

API Configuration

Stability API Configuration

const api = stability.Api({
apiKey: "my-api-key",
// ...
});

const model = stability.ImageGenerator({
api,
// ...
});