<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [motion-sdk](./motion-sdk.md) &gt; [Motion](./motion-sdk.motion.md) &gt; [(constructor)](./motion-sdk.motion._constructor_.md)

## Motion.(constructor)

Create a Motion API client.

**Signature:**

```typescript
constructor(opts?: MotionOptions);
```

## Parameters

<table><thead><tr><th>

Parameter


</th><th>

Type


</th><th>

Description


</th></tr></thead>
<tbody><tr><td>

opts


</td><td>

[MotionOptions](./motion-sdk.motionoptions.md)


</td><td>

_(Optional)_ Object with client parameters


</td></tr>
</tbody></table>

## Remarks

Initializes a Motion API client with the provided user ID and API key. Consult the [Motion API docs](https://help.usemotion.com/integrations/integrations-101/api-docs) for how to get an API key.

If there may be multiple `Motion` clients sharing the same user, you must pass a custom request rate limiter and a custom overrun rate limiter that share the same backing store as the other `Motion` clients.

You may adjust the maximum number of queued requests; the default is [defaultQueueSize](./motion-sdk.defaultqueuesize.md)<!-- -->.

`motion-sdk` does not throw. If the constructor is called with invalid arguments or if another error occurs, the client will be closed immediately. The error will be set in [closedReason](./motion-sdk.motion.closedreason.md)<!-- -->.

## Example 1

Basic usage:

```typescript
const motion = new Motion({
  userId: 'my-user-id',
  apiKey: 'my-api-key',
});
```

## Example 2

Or, you can set the environment variables `MOTION_USER_ID` and `MOTION_API_KEY`<!-- -->. Then:

```typescript
const motion = new Motion();
```

## Example 3

To set custom rate limiters:

```typescript
// 1 request per 5 seconds
const requestLimiter = new RateLimiterMemory({
  points: 1,
  duration: 5, // seconds
});

// 2 overruns per day
const overrunLimiter = new RateLimiterMemory({
  points: 2,
  duration: 60 * 60 * 24,
});

const motion = new Motion({
  requestLimiter,
  overrunLimiter,
  maxQueueSize: 0, // Disable queue
});

await motion.fetch("/users/me");
```
The requestLimiter and overrunLimiter must be instances of the [RateLimiterAbstract](https://github.com/animir/node-rate-limiter-flexible/blob/master/lib/RateLimiterAbstract.js) class from [rate-limiter-flexible](https://www.npmjs.com/package/rate-limiter-flexible)<!-- -->.

As of this writing, `rate-limiter-flexible` provides rate limiters backed by Redis, Prisma, DynamoDB, process Memory, Cluster or PM2, Memcached, MongoDB, MySQL, and PostgreSQL. Refer to their documentation for more detailed help.

The default limiter is [RateLimiterMemory](https://github.com/animir/node-rate-limiter-flexible/blob/master/lib/RateLimiterMemory.js) with the limits from [recommendedRateLimits](./motion-sdk.recommendedratelimits.md)<!-- -->. The maximum queue size is given by [defaultQueueSize](./motion-sdk.defaultqueuesize.md)<!-- -->.

