> ## Documentation Index
> Fetch the complete documentation index at: https://docs.portkey.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Stability AI

> Use Stability AI's Stable Diffusion models for image generation through Portkey.

## Quick Start

Get started with Stability AI in under 2 minutes:

```python Python icon="python" theme={"system"}
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)
```

```js Javascript icon="square-js" theme={"system"}
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)
```

```python OpenAI Py icon="python" theme={"system"}
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)
```

```js OpenAI JS icon="square-js" theme={"system"}
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)
```

```bash cURL icon="square-terminal" theme={"system"}
# 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"
  }'
```

> [!NOTE]
>
> **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**](https://app.portkey.ai/model-catalog/providers)
2. Select **Stability AI**
3. Enter your [Stability AI API key](https://platform.stability.ai/account/keys)
4. Name your provider (e.g., `stability-ai`)

> [card] [Complete Setup Guide](https://docs.portkey.ai/docs/product/model-catalog.md)
>
> See all setup options and detailed configuration instructions

***

## Image Generation

Generate high-quality images with Stable Diffusion:

```python Python theme={"system"}
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)
```

```javascript Node.js theme={"system"}
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);
```

> [!NOTE]
>
> 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:

| Model | Description |
| - | - |
| stable-diffusion-v1-6 | High-quality general-purpose image generation |
| stable-diffusion-xl-1024-v1-0 | XL model for larger, more detailed images |

Check [Stability AI's documentation](https://platform.stability.ai/docs) for the complete model list.

***

## Next Steps

> [card] [Gateway Configs](https://docs.portkey.ai/docs/product/ai-gateway.md)
>
> Add fallbacks, load balancing, and more

> [card] [Observability](https://docs.portkey.ai/docs/product/observability.md)
>
> Monitor and trace your Stability AI requests

> [card] [Caching](https://docs.portkey.ai/docs/product/ai-gateway/cache-simple-and-semantic.md)
>
> Cache generated images

> [card] [Metadata](https://docs.portkey.ai/docs/product/observability/metadata.md)
>
> Add custom metadata to requests

For complete SDK documentation:

> [card] [SDK Reference](https://docs.portkey.ai/docs/api-reference/sdk/list.md)
>
> Complete Portkey SDK documentation

***

> [card] [Portkey is now PRISMA AIRS AI Gateway. See it in action.](https://www.paloaltonetworks.in/ai-security/ai-gateway?utm_source=portkey\&utm_medium=referral\&utm_campaign=prisma_airs\&utm_content=docs_nav#contact)
>
> Contact Us


## Related topics

- [Image Generation](https://docs.portkey.ai/docs/guides/getting-started/image-generation.md)
- [Portkey Models](https://docs.portkey.ai/docs/product/model-catalog/portkey-models.md)
- [Fallback from SDXL to Dall-e-3](https://docs.portkey.ai/docs/guides/use-cases/fallback-from-sdxl-to-dall-e-3.md)
- [Overview](https://docs.portkey.ai/docs/integrations/llms.md)
- [Multimodal Capabilities](https://docs.portkey.ai/docs/product/ai-gateway/multimodal-capabilities.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.