The most common use case is that of text-to-image where the user sends a prompt which the image model processes and returns an image.

The guide for vision models is available here.

Text-to-Image Usage

Portkey supports the OpenAI signature to make text-to-image requests.

import Portkey from 'portkey-ai';

// Initialize the Portkey client
const portkey = new Portkey({
    apiKey: "PORTKEY_API_KEY",  // Replace with your Portkey API key
    virtualKey: "VIRTUAL_KEY"   // Add your provider's virtual key
});

async function main() {
  const image = await portkey.images.generate({
    model: "dall-e-3",
    prompt: "Lucy in the sky with diamonds"
  });

  console.log(image.data);
}

main();

API Reference

Create Image

On completion, the request will get logged in the logs UI where the image can be viewed.

(Note that providers may remove the hosted image after a period of time, so some logs might only contain the url)

Supported Providers and Models

The following providers are supported for image generation with more providers getting added soon. Please raise a request or a PR to add model or provider to the AI gateway.

ProviderModelsFunctions
OpenAIdall-e-2, dall-e-3Create Image (text to image)
Azure OpenAIdall-e-2, dall-e-3Create Image (text to image)
Stabilitystable-diffusion-v1-6, stable-diffusion-xl-1024-v1-0Create Image (text to image)
AWS BedrockStable Image Ultra, Stable Diffusion 3 Large (SD3 Large), Stable Image Core, Stable Diffusion XL 1.0Create Image (text to image)
SegmindRefer hereCreate Image (text to image)
Together AI (Coming Soon)
Monster API (Coming Soon)
Replicate (Coming Soon)

Cookbook

Here’s a detailed cookbook on image generation using Portkey which demonstrates the use of multiple providers and routing between them through Configs.