Langchain Integration
How to integrate Langchain with Lytix
Use Lytix to manage your evaluation and usage diretly with the Langchain SDK. Gain access to models across providers and manage your usage and billing.
Prerequisites
Prerequisite First create a lytix account here
Create a Lytix API Key
Start by creating and noting down a lytix api key. See instructions here
OpenAI
Install the Langchain SDK
Initialize the ChatOpenAI client
🇪🇺 Note You will need to use https://eu.api.lytix.co/proxy/v1/openai
if you are in the EU region.
Continue Using Langchain Normally!
You can now continue using Langchain as you normally would and use this model as you would any other Langchain model.
Optional Fields
You can pass these fields by updating your model as follows:
Langchain supports the following optional fields with Lytix:
sessionId
: You can pass a sessionId to track usage for a specific session.userId
: You can pass a userId to track usage for a specific user.workflowName
: You can pass a workflowName to track usage for a specific workflow. Learn more about workflows here.cacheTTL
: You can pass a cacheTTL to cache the response for a specific amount of time. Learn more about caching here.
Anthopic
Install the Langchain SDK
Initialize the ChatAnthropic client
🇪🇺 Note You will need to use https://eu.api.lytix.co/proxy/v1/anthropic
if you are in the EU region.
Continue Using Langchain Normally!
You can now continue using Langchain as you normally would and use this model as you would any other Langchain model.
Optional Fields
You can pass these fields by updating your model as follows:
Langchain supports the following optional fields with Lytix:
sessionId
: You can pass a sessionId to track usage for a specific session.userId
: You can pass a userId to track usage for a specific user.workflowName
: You can pass a workflowName to track usage for a specific workflow. Learn more about workflows here.cacheTTL
: You can pass a cacheTTL to cache the response for a specific amount of time. Learn more about caching here.
Capturing RAG Metrics
Lytix also supports capturing RAG metrics directly from Langchain.
Install lytix SDK
Setup A Langchain Callback Handler
View Metrics in the Lytix Dashboard
You can view RAG metrics in the lytix dashboard when viewing an IO Event.