---
title: "TypeScript"
description: "Integrate OpenLIT SDK for TypeScript with Middleware LLM Observability to monitor AI workflows, analyze traces, and optimize application performance."
section: "LLM Observability"
breadcrumb: "LLM Observability > Openlit > TypeScript"
canonical: "https://docs.middleware.io/features/llm/openlit-typescript"
---
# TypeScript

This guide walks you through wiring the OpenLIT SDK to Middleware so you can observe TypeScript LLM workloads end-to-end. You’ll learn how to install the SDK, initialize it (via function args or environment variables), and then run a first request so traces/metrics appear in LLM Observability.

## Before you begin

- Have credentials ready: Your Middleware UID (for the OTLP endpoint) and Middleware API key (for the `Authorization` header).
- Choose one init style: Configure via function arguments or via environment variables. Both are supported and shown below.
- Metrics toggle: You can disable metrics with `disableMetrics: true` or set `OPENLIT_DISABLE_METRICS=true`.

## 1. Install the SDK

Run this in your project to add OpenLIT:

```bash
npm install openlit
```

## 2. Initialize the SDK

Choose between function arguments or environment variables, and stick with one for consistency.

### Set up using function arguments

In your LLM application, initialise the OpenLIT SDK like this:

```js
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",
  },
})
```

### Set up using Environment Variables

First, export the required variables so OpenLIT can auto-read them at runtime:

```js
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, call init() with no arguments (it will use the env vars):

```js
import Openlit from "openlit"

Openlit.init()
```

You can disable metrics collection by passing `disableMetrics: true` to init or setting the `OPENLIT_DISABLE_METRICS=true` environment variable.

## 3. Use the SDK

Start with the basic usage example as shown below to send your first telemetry:

```ts
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 initialisation and at least one real LLM request, [open the LLM Observability section in Middleware](https://app.middleware.io/llm/traces?) to see traces and metrics for your TypeScript service.

For advanced options and patterns, refer to the [OpenLIT TypeScript SDK documentation](https://docs.openlit.io/latest/overview).

## Troubleshooting

- No data appearing: Make sure an actual LLM request ran after `Openlit.init(...)`, and verify network access to `https://<MW_UID>.middleware.io:443`.
- Auth/tenant issues: Re-check the exact `Authorization` value (Middleware API key) and that `otlpEndpoint` (or `OPENLIT_OTLP_ENDPOINT`) includes your correct tenant UID.
- Env-var setup not picked up: Confirm variable names (`OPENLIT_OTLP_ENDPOINT`, `OPENLIT_APPLICATION_NAME`, `OPENLIT_OTLP_HEADERS`) and then call `Openlit.init()` with no arguments.
- Only traces, no metrics: Ensure you haven’t set `disableMetrics: true` or `OPENLIT_DISABLE_METRICS=true` unintentionally.

> **Note:** Need assistance or want to learn more about using Traceloop with Middleware? Get in touch with us via our [Contact Us](https://middleware.io/contact-us/).
