API Directory › 🤖 AI & Machine Learning › Stability AI
API KeyHTTPSCORS

Stability AI API

Image generation (Stable Diffusion) and related generative media APIs.

Auth
API Key
HTTPS
Yes
CORS
Yes
Open Stability AI docs ↗

What it does

Stability AI’s REST API generates and edits images with the Stable Diffusion / Stable Image family — text-to-image, image-to-image, inpainting, outpainting, upscaling, background removal and control (sketch, structure, style). Requests are simple multipart POSTs that return a PNG or JPEG.

Base URL

https://api.stability.ai

Authentication

Sign up at platform.stability.ai and create a key (sk-…). Send it as Authorization: Bearer sk-…. Billing is a prepaid credit balance; new accounts get a small amount of free credits to start.

Code examples

curl
curl -f -X POST https://api.stability.ai/v2beta/stable-image/generate/core \
  -H "Authorization: Bearer $STABILITY_KEY" \
  -H "Accept: image/*" \
  -F prompt="a lighthouse at dawn, watercolor" \
  -F output_format="png" \
  -o result.png
Python
import requests

r = requests.post(
    "https://api.stability.ai/v2beta/stable-image/generate/core",
    headers={"Authorization": f"Bearer {KEY}", "Accept": "image/*"},
    files={"none": ""},
    data={"prompt": "a lighthouse at dawn, watercolor", "output_format": "png"},
    timeout=60)
r.raise_for_status()
open("result.png", "wb").write(r.content)

Rate limits & quotas

Default account limit is around 150 requests every 10 seconds across the API; going over returns HTTP 429. The practical limit is your credit balance — each endpoint has a fixed credit cost (the fast Core model is a few credits per image, Ultra and SD3 cost more). Failed generations are not charged.

Key response fields

(body)The generated image bytes when Accept: image/*
imageBase64 image string when Accept: application/json
finish_reasonSUCCESS or CONTENT_FILTERED
seedSeed used — reuse it to reproduce or vary an image

Common errors

401Invalid or missing key.
402Not enough credits — top up the balance.
403 content_moderationPrompt or image was blocked by the safety filter.
429Request rate exceeded — throttle and retry.

When to use it (and alternatives)

Pick Stability when you want direct, low-level control of Stable Diffusion-style generation and editing at a predictable per-image price. For a wider model zoo (including non-Stability image models) use Replicate; for image generation bundled with a chat stack see the OpenAI API.

FAQ

How much does one image cost?

It depends on the endpoint. The fast Core model is a few credits per image, SD3 and Ultra cost more, and edit operations vary. Check the current credit table in the docs — credits are bought in prepaid bundles.

Why did I get a 403 with finish_reason CONTENT_FILTERED?

The safety system flagged the prompt or the output. Rephrase the prompt; note you are not charged credits for a filtered result.

Can I get JSON instead of raw image bytes?

Yes — set Accept: application/json and the response contains a base64 image field plus metadata.

New to APIs?

Short guides for working with this API — and any other.

🛠️ Handy LarzOS tools

Free tools to help you work with this API.

Prompt ImproverLearn Prompt Engineering

Related AI & Machine Learning APIs

← Back

More AI & Machine Learning APIs · All 196 APIs