Portkey + Langchain
Portkey is the Control Panel for AI apps. With it’s popular AI Gateway and Observability Suite, hundreds of teams ship reliable, cost-efficient, and fast apps. Portkey brings production readiness to Langchain. With Portkey, you can- Connect to 150+ models through a unified API,
- View 42+ metrics & logs for all requests,
- Enable semantic cache to reduce latency & costs,
- Implement automatic retries & fallbacks for failed requests,
- Add custom tags to requests for better tracking and analysis and more.
Quickstart
Since Portkey is fully compatible with the OpenAI signature, you can connect to the Portkey AI Gateway through the ChatOpenAI interface.- Set the base_urlasPORTKEY_GATEWAY_URL
- Add default_headersto consume the headers needed by Portkey using thecreateHeadershelper method.
ChatOpenAI model in Langchain
Using OpenAI models with Portkey + ChatOpenAI
Using Together AI models with Portkey + ChatOpenAI
Advanced Routing - Load Balancing, Fallbacks, Retries
The Portkey AI Gateway brings capabilities like load-balancing, fallbacks, experimentation and canary testing to Langchain through a configuration-first approach. Let’s take an example where we might want to split traffic betweenllama-3-70b and gpt-3.5 50:50 to test the two large models. The gateway configuration for this would look like the following:

