Setting up OpenLIT SDK for Middleware (TypeScript)
This guide will walk you through the process of setting up the OpenLIT SDK to work with Middleware for LLM Observability in a TypeScript environment.
1. Install the SDK
Run the following command in your terminal:
npm install openlit
2. Initialize the SDK
You can initialize the OpenLIT SDK using either function arguments or environment variables:
Setup using function arguments
In your LLM application, initialize the OpenLIT SDK like this:
import Openlit from "openlit" Openlit.init({ otlpEndpoint: "https://<MW_UID>.middleware.io:443", applicationName: "YOUR_APPLICATION_NAME", otlpHeaders: { "Authorization": "<MW_API_KEY>", "X-Trace-Source": "openlit", }, })
Setup using Environment Variables
Set the following environment variables:
export OPENLIT_OTLP_ENDPOINT="https://<MW_UID>.middleware.io:443" export OPENLIT_APPLICATION_NAME="YOUR_APPLICATION_NAME" export OPENLIT_OTLP_HEADERS='{"Authorization": "<MW_API_KEY>", "X-Trace-Source": "openlit"}'
Then, in your TypeScript code, simply call:
import Openlit from "openlit" Openlit.init()
The SDK will automatically use the environment variables for configuration.
You can disable metrics collection by setting disableMetrics: true
in the init
function or by setting the OPENLIT_DISABLE_METRICS=true
environment variable.
3. Use the SDK
Here are two examples of how to use OpenLIT to monitor OpenAI usage:
Example 1: Basic Usage
import Openlit from "openlit" Openlit.init({ otlpEndpoint: "https://<MW_UID>.middleware.io:443", applicationName: "YOUR_APPLICATION_NAME", otlpHeaders: { "Authorization": "<MW_API_KEY>", "X-Trace-Source": "openlit", }, })
Viewing Your Traces and Metrics
After setting up the Traceloop SDK with Middleware, you'll be able to view your LLM application traces in your Middleware LLM Observability Section.
This integration provides instant visibility into everything happening within your LLM, including performance metrics and usage patterns.
For more advanced configurations and use cases, please refer to the OpenLIT TypeScript SDK documentation.
Need assistance or want to learn more about using OpenLIT with Middleware? Refer to the OpenLIT documentation or contact our support team in Slack.