Stable Diffusion has been around longer than almost any other name in AI image generation, and it's still one of the most widely used models out there. But "Stable Diffusion API" means different things to different people. Some people mean Stability AI's own hosted service. Others mean running the open model themselves. And plenty of developers just want one simple API call that returns an image, without having to think about any of that.
This guide covers all three paths: what the API actually is, how requests work, what it costs depending on where you get it, and how it compares to other image models you might also be considering. If you want a broader look at how image APIs work in general, our AI Image API guide is a good starting point.
What Is the Stable Diffusion API?
When people say "Stable Diffusion API," they usually mean one of two hosted routes. The first is Stability AI's official REST API, which gives you access to their current image models without installing anything locally. The second is third-party access, where a provider offers the same underlying models through its own endpoint, often alongside other image and video models.
One thing worth clearing up early: the model names people use in conversation are not the ones Stability's hosted API actually serves. The current lineup is the Stable Diffusion 3.5 family (Large, Large Turbo, Medium, and Flash) plus two packaged services, Stable Image Core and Stable Image Ultra, with SDXL 1.0 still available as a legacy option. Older versions like SD 1.5 and SD 1.6 are no longer offered through the hosted API. If you specifically need SD 1.5, perhaps because you have fine-tuned work built on it, self-hosting is the only route.
Both hosted routes get you images from the same family of models. The real difference is in pricing, rate limits, and whether you want to manage yet another separate API key and billing relationship on top of everything else you're already using.
There's a third option too: running Stable Diffusion yourself, since the model weights are open. That's a real path for teams with their own GPU hardware and a good reason to want full control, but it's a much bigger project than "call an API and get an image back," so we'll treat it separately rather than mixing it in with the hosted options.
Who Should Use the Stable Diffusion API
Stable Diffusion tends to make the most sense when the openness of the model actually matters to you, not just as a nice-to-have. A few situations where that shows up:
Software products that generate images as part of a larger feature, like a design tool or a marketing platform that needs a steady stream of visuals on demand.
Online retail teams generating product mockups or lifestyle shots at a volume where per-image cost adds up fast.
Game and asset production that needs a lot of rough variations rather than one polished hero image.
Marketing and creative tools where training the model on a specific style or brand look is worth the extra setup, which in practice means self-hosting.
The open licensing is a genuine advantage here. Because the weights are published, you're not locked into one vendor's terms the way you are with a fully closed model. Teams that later want to run the model on their own hardware or train it on their own images can keep that option open from day one. For a side-by-side look at how this compares with closed alternatives, see our comparison of the Flux, Stable Diffusion, and Midjourney APIs.
How the Stable Diffusion API Works
Authentication and Getting an API Key
If you go directly through Stability AI, you create an account on their platform and generate an API key from your dashboard. New accounts come with 25 free credits, which is enough to test properly before spending anything. If you go through a unified provider instead, the process is similar: sign up, grab a key, and you're generating images with the same underlying models through a different endpoint and billing setup.
Whichever route you pick, treat the key the way you'd treat any other password: keep it out of code that runs in the browser, store it in an environment variable, and replace it if it's ever exposed.
Core Request Parameters
Stability's current image endpoints keep the request simple. The fields you will actually use most of the time:
- prompt: the text description of what you want generated
- negative_prompt: things you explicitly don't want to appear (extra limbs, watermarks, blurry edges, whatever you're trying to avoid)
- aspect_ratio: the shape of the output, chosen from a fixed set of ratios rather than by setting exact pixel dimensions
- seed: a number that makes a result repeatable, so you can regenerate the same image or tweak a prompt without everything changing at once
- style_preset: an optional shortcut for a particular look, such as photographic or line art
- model or service: which of the SD 3.5 variants or packaged services you want, each with different quality, speed, and cost
If you have read older Stable Diffusion tutorials, you have probably seen steps, cfg_scale, and sampler described as core parameters. Those controls govern how the image is built up internally, and they belong to the older generation of the API and to self-hosted setups. The current Stable Diffusion 3.5 endpoints do not expose them, so copying a request from a 2023 tutorial will not work as written. This is the single most common reason a first integration fails.
Response Format and Image Retrieval
Some providers return the image in the same response as your request. Others, especially for larger batches or higher resolutions, run the work in the background: you submit a job, then either check back for the result or have the provider notify your server when it's ready. Our walkthrough on setting up callbacks for media generation covers that second pattern. Images come back either as a long block of encoded text your code converts into a file, or as a link to a hosted file. Check your provider's documentation here, because this detail varies more than most between Stability's direct API and third-party layers.
Stable Diffusion API Pricing Breakdown (2026)
Official Stability AI Pricing
Stability AI runs on a credit system, where one credit is worth $0.01. The important detail, and the one most guides get wrong, is that current models charge a flat credit cost per successful generation. Resolution does not change the price. A Stable Image Core image costs 3 credits whichever aspect ratio you pick. What does change the price is which model you call:
| Service | Credits per image | Cost per image |
|---|---|---|
| Stable Image Ultra | 8 | $0.08 |
| Stable Diffusion 3.5 Large | 6.5 | $0.065 |
| Stable Diffusion 3.5 Large Turbo | 4 | $0.04 |
| Stable Diffusion 3.5 Medium | 3.5 | $0.035 |
| Stable Diffusion 3.5 Flash | 2.5 | $0.025 |
| Stable Image Core | 3 | $0.03 |
| SDXL 1.0 (legacy) | From 0.9 | From $0.009 |
Editing and upscaling are billed separately and can cost far more than generating. The creative upscaler is 60 credits per run, which is more than seven times the price of a top-tier image. If upscaling is part of your workflow, budget for it on its own rather than folding it into a per-image estimate.
Third-Party and Unified Provider Pricing
Providers that bundle several models together typically offer either pay-as-you-go pricing or a subscription with a set number of generations included. The appeal usually isn't that it's dramatically cheaper per image (sometimes it is, sometimes it isn't). It's that you get Stable Diffusion alongside models like Midjourney, GPT Image, or Nano Banana under one key and one bill, which is the main argument for consolidating onto one API. For teams that are going to use more than one model anyway, that convenience tends to matter more than shaving a fraction of a cent off a single provider's per-image rate. For a closer look at how these costs stack up, see our breakdown of AI image API pricing in 2026.
Free and Low-Cost Options
Because the weights are open, self-hosting is genuinely free of per-image fees if you already have or can access the GPU capacity. The catch is operational: you become responsible for uptime, handling traffic spikes, and keeping the model updated, which is a real cost even if it doesn't show up on an invoice. Stability gives new accounts 25 free credits, and most other hosted providers offer a trial allowance too. Those are useful for testing, but not something to build a production feature on long-term. If cost is your main concern, our guide to what is actually free in AI image generation APIs walks through where the real limits kick in.
Stable Diffusion API vs. Other Image APIs
| Model | Quality/style | Speed | Cost per image | Commercial licensing | Custom training |
|---|---|---|---|---|---|
| Stable Diffusion | Strong, especially when trained on your own images | Fast to moderate | $0.025 to $0.08 hosted, no per-image fee self-hosted | Open, generally permissive | Yes, but only when self-hosting |
| Midjourney | Best-in-class artistic and stylized | Moderate | Subscription based, roughly $0.02 to $0.08 effective | Commercial rights included on paid plans | No |
| GPT Image 2 | Strong photorealism, follows instructions closely | Moderate | $0.02 to $0.19 | Commercial use generally allowed | No |
| Nano Banana 2 | Strong subject consistency | Fast | $0.03 to $0.10 | Commercial use generally allowed | No |
The clearest advantage of Stable Diffusion is control. Tools built around the open weights let you guide composition and pose from a reference image, and training methods like LoRA let you teach the model a specific style, character, or brand look. Closed models such as Midjourney, GPT Image 2, and Nano Banana 2 don't offer that, because you work entirely within whatever the base model gives you. The trade is that most of this control lives in the self-hosted ecosystem rather than in Stability's hosted API, so it is a reason to run the model yourself, not a reason to pick the hosted service. If you're trying to keep a character looking the same across many images, our guide on character consistency in AI image generation covers techniques that apply well here. For a wider view of how it stacks up, see our comparison of the best AI image APIs in 2026.
Model choice matters less than most people expect once you are past the first week. How you write the prompt usually makes a bigger difference, which our piece on how prompt wording shapes photorealistic output gets into. And if your product needs to change existing images rather than create new ones, our AI image editing API guide covers that side.
Best Practices for Production Use
A few things tend to trip people up once Stable Diffusion moves from a side project into an actual production feature:
Rate limits. Whether you're direct with Stability AI or going through another provider, know how many requests your plan allows before you launch a feature that could see a sudden spike in traffic.
Content filtering. Most hosted providers block certain prompts and outputs by default. If you're self-hosting, you'll need to handle this yourself, which is easy to underestimate until the first time something inappropriate reaches a user. Our guide to AI content moderation covers this in more depth.
Caching repeated prompts. If users regenerate similar prompts often, a common pattern in creative tools, storing and reusing previous results can meaningfully cut your costs.
Grouping bulk jobs. For large generation runs, sending work in grouped batches is usually more efficient than firing off individual calls one at a time, both for cost and for staying under your request limits.
Retrying failures sensibly. Like any API, temporary failures happen. Retry a few times, waiting a little longer after each attempt, rather than failing a user-facing generation on the first hiccup.
Getting Started with Apiframe's Stable Diffusion API
Stable Diffusion is joining Apiframe's image lineup, which already covers Midjourney, GPT Image, Nano Banana, and others through a single endpoint. The pattern is the same for every model: you submit a prompt, get a job ID back right away, and collect the result when it's ready. Our getting started guide walks through account setup if this is your first time using the API, and our roundup of the best AI image generator APIs covers what else is on the platform today.
import requests
import time
headers = {
"X-API-Key": "afk_your_api_key_here",
"Content-Type": "application/json",
}
response = requests.post(
"https://api.apiframe.ai/v2/images/generate",
headers=headers,
json={
"prompt": "a quiet mountain lake at sunrise, photorealistic",
"model": "stable-diffusion-3.5",
"stableDiffusionParams": {
"negative_prompt": "blurry, low quality, watermark",
"aspect_ratio": "1:1"
}
}
)
job_id = response.json()["jobId"]
while True:
status = requests.get(f"https://api.apiframe.ai/v2/jobs/{job_id}", headers=headers).json()
if status["status"] == "COMPLETED":
image_url = status["result"]["images"][0]
print(image_url)
break
elif status["status"] == "FAILED":
raise RuntimeError(status["error"])
time.sleep(3)Because it's the same key and structure you'd use for any other model on the platform, moving between Stable Diffusion and something like GPT Image 2 later means changing the model name and its parameters block rather than rebuilding the integration. It's worth checking the models page for the current lineup, and the pricing page for up-to-date rates, before committing to a volume of usage.
FAQ
Is the Stable Diffusion API free?
Running the open model on your own hardware has no per-image fee, but you're covering the infrastructure cost yourself. Hosted access, whether direct from Stability AI or through another provider, is pay-as-you-go or credit-based. Stability gives new accounts 25 free credits to start with.
Which version should I use?
For most new projects, Stable Diffusion 3.5 Large is the quality default and 3.5 Flash is the budget one at a third of the price. Stable Image Core sits in between and is the cheapest sensible starting point at 3 credits. SDXL 1.0 is still available as a legacy option and is worth it only if you have existing work tied to it. SD 1.5 is no longer served by the hosted API at all, so you would need to run it yourself.
Can I use outputs commercially?
Generally yes, since Stable Diffusion's licensing is more permissive than most closed models, but it's worth checking the specific license tied to whichever model version you're using, since terms have shifted across releases.
Can I train Stable Diffusion on my own images through the API?
Not through Stability's hosted API. It has no upload-your-own-model option, so LoRA training means running the model on your own hardware or using a third-party host that supports custom models. What the hosted API does offer is a set of control endpoints that guide a new image using an input image, sketch, or reference style, which covers many of the cases people reach for custom training to solve.
Does image resolution change the price?
Not on Stability's current models. Each generation costs a flat number of credits regardless of the aspect ratio you request, so the only lever on cost is which model you call. That is different from several other providers, where resolution or quality tier does change the bill. Our comparison of the best AI image generation APIs lays out how each one charges.
Apiframe Team
The team behind Apiframe - making AI generation accessible to everyone.