Langchain
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_url
asPORTKEY_GATEWAY_URL
- Add
default_headers
to consume the headers needed by Portkey using thecreateHeaders
helper method.
To start, get your Portkey API key by signing up here. (Click the profile icon on the bottom left, then click on ” API Key”)
We can now connect to the Portkey AI Gateway by updating the 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 between llama-3-70b
and gpt-3.5
50:50 to test the two large models. The gateway configuration for this would look like the following:
Was this page helpful?