How to hit the Stability AI API

Stability AI's image API lives at https://api.stability.ai. The generate endpoints take multipart form fields (curl's -F; in PostTaco, the Body tab's Form mode). Accept: application/json returns the image as base64 in JSON; Accept: image/* returns the image bytes.

Authentication

Create a key at platform.stability.ai and send it as Authorization: Bearer <key>. In the examples it's written {{STABILITY_API_KEY}}. Endpoints that edit an existing image need a file upload, which PostTaco doesn't support yet.

Full reference: https://platform.stability.ai/docs/api-reference

Generate an image (Stable Image Core)

The fast, inexpensive tier. aspect_ratio defaults to 1:1.

curl -X POST https://api.stability.ai/v2beta/stable-image/generate/core \
  -H "Authorization: Bearer {{STABILITY_API_KEY}}" \
  -H "Accept: application/json" \
  -F prompt="a taco food truck on the moon, photo" \
  -F aspect_ratio=16:9 \
  -F output_format=png
Run in PostTaco

Generate an image (Stable Image Ultra)

The highest-quality tier.

curl -X POST https://api.stability.ai/v2beta/stable-image/generate/ultra \
  -H "Authorization: Bearer {{STABILITY_API_KEY}}" \
  -H "Accept: application/json" \
  -F prompt="a lighthouse at dawn, watercolor" \
  -F output_format=webp
Run in PostTaco

Check your credit balance

curl https://api.stability.ai/v1/user/balance \
  -H "Authorization: Bearer {{STABILITY_API_KEY}}"
Run in PostTaco