> ## 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>
  You can install [Loops skills](/skills) to help your coding agents use the Loops CLI, API and SDKs to create campaigns, manage contacts, send events, and send transactional emails.
</Tip>

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
  title="Next.js guide"
  icon={
<svg
  xmlns="http://www.w3.org/2000/svg"
  preserveAspectRatio="xMidYMid"
  viewBox="0 0 256 256"
>
  <path
    fill="#FF4A00"
    d="M119.617.069c-.55.05-2.302.225-3.879.35-36.36 3.278-70.419 22.894-91.99 53.044-12.012 16.764-19.694 35.78-22.597 55.922C.125 116.415 0 118.492 0 128.025c0 9.533.125 11.61 1.151 18.64 6.957 48.065 41.165 88.449 87.56 103.411 8.309 2.678 17.067 4.504 27.027 5.605 3.879.425 20.645.425 24.524 0 17.192-1.902 31.756-6.155 46.12-13.486 2.202-1.126 2.628-1.426 2.327-1.677-.2-.15-9.584-12.735-20.845-27.948l-20.47-27.648-25.65-37.956c-14.114-20.868-25.725-37.932-25.825-37.932-.1-.025-.2 16.84-.25 37.431-.076 36.055-.1 37.506-.551 38.357-.65 1.226-1.151 1.727-2.202 2.277-.801.4-1.502.475-5.28.475h-4.33l-1.15-.725a4.679 4.679 0 0 1-1.677-1.827l-.526-1.126.05-50.166.075-50.192.776-.976c.4-.525 1.251-1.2 1.852-1.526 1.026-.5 1.426-.55 5.755-.55 5.105 0 5.956.2 7.282 1.651.376.4 14.264 21.318 30.88 46.514 16.617 25.195 39.34 59.599 50.5 76.488l20.27 30.7 1.026-.675c9.084-5.905 18.693-14.312 26.3-23.07 16.191-18.59 26.626-41.258 30.13-65.428 1.026-7.031 1.151-9.108 1.151-18.64 0-9.534-.125-11.61-1.151-18.641-6.957-48.065-41.165-88.449-87.56-103.411-8.184-2.652-16.892-4.479-26.652-5.58-2.402-.25-18.943-.525-21.02-.325Zm52.401 77.414c1.201.6 2.177 1.752 2.527 2.953.2.65.25 14.562.2 45.913l-.074 44.987-7.933-12.16-7.958-12.16v-32.702c0-21.143.1-33.028.25-33.603.4-1.401 1.277-2.502 2.478-3.153 1.026-.525 1.401-.575 5.33-.575 3.704 0 4.354.05 5.18.5Z"
  />
</svg>
}
  href="/sdks/javascript/nextjs"
>
  Read our guide for sending email from Next.js projects.
</Card>

## Usage

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

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

try {
  const resp = await loops.createContact("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](hhttps://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](/api-reference/intro#rate-limiting) and [error handling](/api-reference/intro#debugging).

<CardGroup>
  <Card title="npm package" icon="js" href="https://www.npmjs.com/package/loops">
    View the full documentation on npm.
  </Card>

  <Card title="GitHub" icon="github" href="https://github.com/Loops-so/loops-js">
    View the source code and release notes.
  </Card>

  <Card title="Loops API" icon="rectangle-terminal" href="/api-reference/intro">
    Read the Loops API reference.
  </Card>
</CardGroup>
