Integrating OpenAI with Your Applications via Vortex
Integrating OpenAI's cutting-edge AI capabilities into your applications can significantly enhance user experiences by extending your app's features. Vortex acts as a conduit for this integration, facilitating a seamless connection between your applications and OpenAI's powerful functionalities.
This documentation focuses on leveraging the Vortex Admin API to programmatically create consumers and issue keys for each consumer. While the Vortex UI is user-friendly for certain tasks, the Admin API provides a higher degree of flexibility for more complex use cases.
Prerequisites
Before you begin, ensure you have access to the following:
- Vortex proxy URL
- Vortex admin URL
- Admin API key for Vortex
If any of these prerequisites are missing, please consult the Developers section to get started.
Applying Different Usage Limits Based on User Tiers
Imagine you have an application that incorporates AI features using OpenAI's GPT models. To manage costs effectively, you want to limit usage for free users while allowing paid users (Pro and Enterprise tiers) higher usage limits.
Assuming there are three user tiers: Free, Pro, and Enterprise, the usage limits are as follows:
- Free users: 500 tokens/hour
- Pro users: 1500 tokens/hour
- Enterprise users: 10000 tokens/hour
These limits apply across the gpt-3.5-turbo, gpt-4, and gpt-4-turbo models. You also want to block access to all other models.
Steps:
Channel Creation: Create a channel named
openai
using the Vortex UI. This channel does not need to be created dynamically and can be reused for all user tiers. Create a ChannelConsumer Creation: Dynamically create consumers on Vortex for each user as they sign up. Utilise the Vortex Admin API to Create a Consumer.
Vortex Key Generation: Similar to consumers, Generate a Vortex API key for each user dynamically. This key enables users to access OpenAI features through Vortex.
Access Granting and Usage Limit Configuration: With the Vortex key generated for every user, grant them access to the
openai
channel and apply the appropriate usage limits based on their tier. To manage operational costs and allocate resources efficiently, Configure Access and Usage Limits for each API key according to user tiers.Resource Limits
Implement the following resource limits when generating the key:
For Free Users:
- Model: gpt-3.5-turbo, Token limit: 500, Duration: 1h
- Model: gpt-4-turbo, Token limit: 500, Duration: 1h
- Model: gpt-4, Token limit: 500, Duration: 1h
For Pro Users:
- Model: gpt-3.5-turbo, Token limit: 1500, Duration: 1h
- Model: gpt-4-turbo, Token limit: 1500, Duration: 1h
- Model: gpt-4, Token limit: 1500, Duration: 1h
For Enterprise Users:
- Model: gpt-3.5-turbo, Token limit: 10000, Duration: 1h
- Model: gpt-4-turbo, Token limit: 10000, Duration: 1h
- Model: gpt-4, Token limit: 10000, Duration: 1h :::
If you have done all the steps successfully so far, you should see the new consumer and the Vortex key on the Vortex UI.
Connecting to LLM: Use the Vortex key and the Vortex proxy URL to connect to OpenAI from within your application. Connect to LLM to utilise OpenAI LLM APIs through Vortex.
Request Logging: On Vortex, monitor each request made by your application to OpenAI. Use Request Logs to track each request facilitated by Vortex. If previous steps have been successful then you should see the request on the Vortex UI
Cost Monitoring: Keep an eye on the costs associated with OpenAI integration. Use the insights dashboard to Monitor Costs and understand the financial implications of LLM integration per user.
By following these steps, you can efficiently integrate OpenAI's functionalities into your application, enhancing the overall user experience while maintaining control over usage and costs.