Portkey supports the OpenAI signature to make text-to-image requests.
import Portkey from 'portkey-ai';// Initialize the Portkey clientconst 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();
import Portkey from 'portkey-ai';// Initialize the Portkey clientconst 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();
from portkey_ai import Portkeyfrom IPython.display import display, Image# Initialize the Portkey clientportkey = Portkey( api_key="PORTKEY_API_KEY", # Replace with your Portkey API key virtual_key="VIRTUAL_KEY" # Add your provider's virtual key)image = portkey.images.generate( model="dall-e-3", prompt="Lucy in the sky with diamonds")# Display the imagedisplay(Image(url=image.data[0].url))
import OpenAI from 'openai'; // We're using the v4 SDKimport { PORTKEY_GATEWAY_URL, createHeaders } from 'portkey-ai'const openai = new OpenAI({ apiKey: 'OPENAI_API_KEY', // defaults to process.env["OPENAI_API_KEY"], baseURL: PORTKEY_GATEWAY_URL, defaultHeaders: createHeaders({ provider: "openai", apiKey: "PORTKEY_API_KEY" // defaults to process.env["PORTKEY_API_KEY"] })});async function main() { const image = await openai.images.generate({ model: "dall-e-3", prompt: "Lucy in the sky with diamonds" }); console.log(image.data);}main();
from openai import OpenAIfrom portkey_ai import PORTKEY_GATEWAY_URL, createHeadersfrom IPython.display import display, Imageclient = OpenAI( api_key='OPENAI_API_KEY', base_url=PORTKEY_GATEWAY_URL, default_headers=createHeaders( provider="openai", api_key="PORTKEY_API_KEY" ))image = client.images.generate( model="dall-e-3", prompt="Lucy in the sky with diamonds", n=1, size="1024x1024")# Display the imagedisplay(Image(url=image.data[0].url))
curl "https://api.portkey.ai/v1/images/generations" \ -H "Content-Type: application/json" \ -H "x-portkey-api-key: $PORTKEY_API_KEY" \ -H "x-portkey-virtual-key: $OPENAI_VIRTUAL_KEY" \ -d '{ "model": "dall-e-3", "prompt": "Lucy in the sky with diamonds" }'
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.