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

# JavaScript SDK

> The official Loops SDK for JavaScript, with full TypeScript support.

[![NPM downloads](https://img.shields.io/npm/dt/loops?style=social\&label=Downloads)](https://www.npmjs.com/package/loops)

## Installation

Install the package [from npm](https://www.npmjs.com/package/loops):

```bash theme={"dark"}
npm install loops
```

> [!TIP]
>
> Want your coding agent to help with Loops? Install the Loops CLI and
> [skills](https://loops.so/docs/skills.md) with one command:
>
> ```bash theme={"dark"}
> curl -fsSL https://install.loops.so/wizard | sh
> ```

Minimum Node version required: 18.0.0.

You will need a Loops API key to use the SDK.

In your Loops account, go to the [API Settings page](https://app.loops.so/settings?page=api) and click **Generate key**.

Copy this key and save it in your application code (for example as `LOOPS_API_KEY` in an `.env` file).

> [card] [Next.js guide](https://loops.so/docs/sdks/javascript/nextjs.md)
>
> Read our guide for sending email from Next.js projects.

## Usage

```javascript theme={"dark"}
import { LoopsClient, APIError } from "loops";

const loops = new LoopsClient(process.env.LOOPS_API_KEY);

try {
  const resp = await loops.createContact({
    email: "test@example.com",
  });
  // resp.success and resp.id available when successful
} catch (error) {
  if (error instanceof APIError) {
    console.log(error.json);
    console.log(error.statusCode);
  }
}
```

Import `RateLimitExceededError` to handle rate limits. See the [SDK docs](https://www.npmjs.com/package/loops) for every method, TypeScript types, rate limiting, and error handling.

See the API documentation to learn more about [rate limiting](https://loops.so/docs/api-reference/intro.md#rate-limiting) and [error handling](https://loops.so/docs/api-reference/intro.md#debugging).

> [card] [npm package](https://www.npmjs.com/package/loops)
>
> View the full documentation on npm.

> [card] [GitHub](https://github.com/loops-so/loops-js)
>
> View the source code and release notes.

> [card] [Loops API](https://loops.so/docs/api-reference/intro.md)
>
> Read the Loops API reference.


## Related topics

- [Set up Loops in Next.js](https://loops.so/docs/guides/nextjs.md)
- [Nuxt module](https://loops.so/docs/sdks/nuxt.md)
- [Create and send your first campaign with the API or an agent](https://loops.so/docs/guides/first-campaign-api.md)
- [Recipe: Active 30-day users segment](https://loops.so/docs/guides/active-30-day-users.md)
- [Custom form](https://loops.so/docs/forms/custom-form.md)
