Image Generation using the Portkey AI Gateway
Portkey’s AI gateway supports making calls to multiple Image models to generate images through a unified API. This notebook showcases the following functionality:- Generating an image through OpenAI
- Use the same request to generate an image using Stability AI
- Setup a load balance between OpenAI and Stability, with a fallback to OpenAI’s dall-e-2
- Cache image requests for super fast loading
1. Generate an image using OpenAI
Let’s try to make an image generation request to OpenAI through Portkey.2. Generate an image using Stability AI
Let’s try to make an image generation request to Stability through Portkey. Notice that we’re going to use the OpenAI SDK itself to make calls to Stability AI as well3. Use a config with load balancing & fallbacks
The AI gateway allows us to create routing configurations for better reliability across our requests. Lets take an example where we might want to loadbalance our requests equally between OpenAI’sdall-e-3
and Stability’s stable-diffusion-v1-6
with a overall fallback to dall-e-2
This requires us to create a config with a structure like this