Using Portkey Gateway, you can route your requests to different provider targets based on custom conditions you define. These can be conditions like:
If this user is on the paid plan, route their request to a custom fine-tuned model
If this user is an EU resident, call an EU hosted model
If this user is a beta tester, send their request to the preview model
If the request is coming from testing environment with a llm-pass-through flag, route it to the cheapest model
..and more!
Using this strategy, you can set up various conditional checks on the metadata keys you're passing with your requests and route requests to the appropriate target — all happening very fast on the gateway, on edge.
Enabling Conditional Routing
Conditional routing is one of the strategies in Portkey's . (others being fallback and loadbalance). To use it in your app,
You need to create a conditional config in Portkey UI.
Save the Config and get an associated Config ID.
And just pass the Config ID along with your requests using the config param.
1. Creating the conditional Config
Here's how a sample conditional config looks (along with its simpler, tree view).
Now, while instantiating your Portkey client or while sending headers, you just need to pass the Config ID and all your requests will start getting routed according to your conditions.
Conditional routing happens on Portkey's on-the-edge stateless AI Gateway. We scan for the given query field in your request body, apply the query condition, and route to the specified target based on it.
Currently, we support Metadata based routing — i.e. routing your requests based on the metadata values you're sending along with your request.
Soon, Portkey will also support routing based on other critical parameters like input character count, input token count, prompt type, tool support, and more.
Similarly, we will also add support for smart routing to wider targets, like fastest, cheapest, highest uptime, lowest error rate, etc.
Based on the conditions and the Config structure described above, you can create your , and save it to get Config ID. The UI also helps you autofill and autoformat your Config.
.
to share your thoughts on this feature and get early access to more routing capabilities.