Skip to main content

Quick Start

Get started with Stability AI in under 2 minutes:
from portkey_ai import Portkey

# 1. Install: pip install portkey-ai
# 2. Add @stability-ai provider in model catalog
# 3. Use it:

portkey = Portkey(api_key="PORTKEY_API_KEY")

image = portkey.images.generate(
    model="@stability-ai/stable-diffusion-v1-6",
    prompt="A serene landscape with mountains",
    size="1024x1024"
)

print(image.data[0].url)
import Portkey from 'portkey-ai'

// 1. Install: npm install portkey-ai
// 2. Add @stability-ai provider in model catalog
// 3. Use it:

const portkey = new Portkey({
    apiKey: "PORTKEY_API_KEY"
})

const image = await portkey.images.generate({
    model: "@stability-ai/stable-diffusion-v1-6",
    prompt: "A serene landscape with mountains",
    size: "1024x1024"
})

console.log(image.data[0].url)
from openai import OpenAI
from portkey_ai import PORTKEY_GATEWAY_URL

# 1. Install: pip install openai portkey-ai
# 2. Add @stability-ai provider in model catalog
# 3. Use it:

client = OpenAI(
    api_key="PORTKEY_API_KEY",  # Portkey API key
    base_url=PORTKEY_GATEWAY_URL
)

image = client.images.generate(
    model="@stability-ai/stable-diffusion-v1-6",
    prompt="A serene landscape with mountains",
    size="1024x1024"
)

print(image.data[0].url)
import OpenAI from "openai"
import { PORTKEY_GATEWAY_URL } from "portkey-ai"

// 1. Install: npm install openai portkey-ai
// 2. Add @stability-ai provider in model catalog
// 3. Use it:

const client = new OpenAI({
    apiKey: "PORTKEY_API_KEY",  // Portkey API key
    baseURL: PORTKEY_GATEWAY_URL
})

const image = await client.images.generate({
    model: "@stability-ai/stable-diffusion-v1-6",
    prompt: "A serene landscape with mountains",
    size: "1024x1024"
})

console.log(image.data[0].url)
# 1. Add @stability-ai provider in model catalog
# 2. Use it:

curl https://api.portkey.ai/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "x-portkey-api-key: $PORTKEY_API_KEY" \
  -d '{
    "model": "@stability-ai/stable-diffusion-v1-6",
    "prompt": "A serene landscape with mountains",
    "size": "1024x1024"
  }'
Tip: You can also set provider="@stability-ai" in Portkey() and use just model="stable-diffusion-v1-6" in the request.

Add Provider in Model Catalog

Before making requests, add Stability AI to your Model Catalog:
  1. Go to Model Catalog → Add Provider
  2. Select Stability AI
  3. Enter your Stability AI API key
  4. Name your provider (e.g., stability-ai)

Complete Setup Guide

See all setup options and detailed configuration instructions

Image Generation

Generate high-quality images with Stable Diffusion:
from portkey_ai import Portkey

portkey = Portkey(api_key="PORTKEY_API_KEY", provider="@stability-ai")

image = portkey.images.generate(
  model="stable-diffusion-v1-6",
    prompt="A serene landscape with mountains and a lake at sunset",
  size="1024x1024"
)

print(image.data[0].url)
import Portkey from 'portkey-ai';

const portkey = new Portkey({
    apiKey: 'PORTKEY_API_KEY',
    provider: '@stability-ai'
});

const image = await portkey.images.generate({
    model: "stable-diffusion-v1-6",
    prompt: "A serene landscape with mountains and a lake at sunset",
    size: "1024x1024"
});

console.log(image.data[0].url);
Portkey uses the OpenAI image generation signature for Stability AI, allowing you to easily switch between providers.

Supported Models

Stability AI offers powerful image generation models:
ModelDescription
stable-diffusion-v1-6High-quality general-purpose image generation
stable-diffusion-xl-1024-v1-0XL model for larger, more detailed images
Check Stability AI’s documentation for the complete model list.

Next Steps

Gateway Configs

Add fallbacks, load balancing, and more

Observability

Monitor and trace your Stability AI requests

Caching

Cache generated images

Metadata

Add custom metadata to requests
For complete SDK documentation:

SDK Reference

Complete Portkey SDK documentation
Last modified on April 2, 2026