> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lunary.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# JavaScript SDK

## Installation

The `lunary` module is lightweight and works with Node JS, Deno, Cloudflare Workers, Vercel Edge functions and even Bun.

### Node

```bash theme={null}
npm install lunary
```

If you want to monitor Anthropic with the official TypeScript SDK, install both packages:

```bash theme={null}
npm install lunary @anthropic-ai/sdk
```

> [!WARNING]
>
> ### For Cloudflare Workers
>
> In your `wrangler.toml` file, make sure to add the Node.js compatibility flag:
>
> ```toml theme={null}
> compatibility_flags = [ "nodejs_compat" ]
> ```

## Setup

Start by importing the `lunary` module:

```js theme={null}
import lunary from "lunary";
```

If you're using in the browser, import like this:

```js theme={null}
import lunary from "lunary/browser";
```

Then initialize the module with your unique app ID.

Option 1: Automatic using environment variables (recommended):

```bash theme={null}
LUNARY_PUBLIC_KEY="0x0"
```

Option 2: Manually using the `.init` method:

```ts theme={null}
// Initialize the Lunary module with your unique app ID
lunary.init({
  publicKey: "0x0",
});
```

The `.init` method accepts the following arguments:

```ts theme={null}
{
  "appId": string, // Your unique app ID obtained from the dashboard
  "apiUrl": string, // Optional: Use a custom endpoint if you're self-hosting (you can also set LUNARY_API_URL)
  "verbose": boolean // Optional: Enable verbose logging for debugging
}
```

> [card] [LangChain](https://docs.lunary.ai/integrations/langchain.md)
>
> Usage with LangChain JS.

> [card] [OpenAI](https://docs.lunary.ai/integrations/javascript/openai.md)
>
> Automatically track your OpenAI calls.

> [card] [Anthropic](https://docs.lunary.ai/integrations/javascript/anthropic.md)
>
> Automatically track your Anthropic calls.

> [card] [User Tracking](https://docs.lunary.ai/features/users.md)
>
> Identify your users.

> [card] [Tagging](https://docs.lunary.ai/features/tags.md)
>
> Segment your queries with tags.

> [card] [Chats](https://docs.lunary.ai/features/conversations.md)
>
> Record user interactions with your chatbot.

> [card] [Manual Integration](https://docs.lunary.ai/integrations/javascript/manual.md)
>
> Learn how to use .trackEvent().

> [card] [Serverless](https://docs.lunary.ai/integrations/javascript/serverless.md)
>
> Use with Lambda, Cloudflare Workers, Edge Functions, etc.

> [card] [Agents & Tools](https://docs.lunary.ai/features/observability.md)
>
> Setup tracing by tracking agents & tools.

> [card] [API Reference](https://docs.lunary.ai/api/introduction.md)
>
> Full list of methods and classes.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.