Image Generation
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
This notebook uses the OpenAI SDK to showcase the functionality. We’re using the hosted AI gateway on portkey.ai, but you could swap it for an internally hosted gateway as well.
1. Generate an image using OpenAI
Let’s try to make an image generation request to OpenAI through Portkey.
This request went through Portkey’s fast AI gateway which also then captures the information about the request on your Portkey Dashboard.
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 well
3. 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’s dall-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
Let’s define this using Portkey’s configuration to achieve the same result. You can find more about configs here.
The above image generated will follow your fallback and load balancing configurations making your app very resilient.
4. Cache Image Requests
The AI gateway also supports caching requests making them extremely fast. We could add cache to the above config and try the requests again.
Was this page helpful?