Skip to main content
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

Python

Initialize the ChatOpenAI client

Python
🇪🇺 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.
Python

Optional Fields

You can pass these fields by updating your model as follows:
Python
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

Python

Initialize the ChatAnthropic client

Python
🇪🇺 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.
Python

Optional Fields

You can pass these fields by updating your model as follows:
Python
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

Python

Setup A Langchain Callback Handler

Python

View Metrics in the Lytix Dashboard

You can view RAG metrics in the lytix dashboard when viewing an IO Event. RAG Metrics On IO Event