@unkey/api
Version:
Developer-friendly & type-safe Typescript SDK specifically catered to leverage *@unkey/api* API.
413 lines (300 loc) • 31.9 kB
Markdown
# Ratelimit
(*ratelimit*)
## Overview
### Available Operations
* [limit](#limit)
* [setOverride](#setoverride)
* [getOverride](#getoverride)
* [listOverrides](#listoverrides)
* [deleteOverride](#deleteoverride)
## limit
### Example Usage
```typescript
import { Unkey } from "@unkey/api";
const unkey = new Unkey({
rootKey: "UNKEY_ROOT_KEY",
});
async function run() {
const result = await unkey.ratelimit.limit({
namespace: "sms.sign_up",
duration: 711276,
identifier: "<value>",
limit: 581877,
});
// Handle the result
console.log(result);
}
run();
```
### Standalone function
The standalone function version of this method:
```typescript
import { UnkeyCore } from "@unkey/api/core.js";
import { ratelimitLimit } from "@unkey/api/funcs/ratelimitLimit.js";
// Use `UnkeyCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const unkey = new UnkeyCore({
rootKey: "UNKEY_ROOT_KEY",
});
async function run() {
const res = await ratelimitLimit(unkey, {
namespace: "sms.sign_up",
duration: 711276,
identifier: "<value>",
limit: 581877,
});
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result);
}
run();
```
### Parameters
| Parameter | Type | Required | Description |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `request` | [components.V2RatelimitLimitRequestBody](../../models/components/v2ratelimitlimitrequestbody.md) | :heavy_check_mark: | The request object to use for the request. |
| `options` | RequestOptions | :heavy_minus_sign: | Used to set various options for making HTTP requests. |
| `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy_minus_sign: | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. |
| `options.retries` | [RetryConfig](../../lib/utils/retryconfig.md) | :heavy_minus_sign: | Enables retrying HTTP requests under certain failure conditions. |
### Response
**Promise\<[components.V2RatelimitLimitResponseBody](../../models/components/v2ratelimitlimitresponsebody.md)\>**
### Errors
| Error Type | Status Code | Content Type |
| ---------------------------------- | ---------------------------------- | ---------------------------------- |
| errors.BadRequestErrorResponse | 400 | application/json |
| errors.UnauthorizedErrorResponse | 401 | application/json |
| errors.ForbiddenErrorResponse | 403 | application/json |
| errors.NotFoundErrorResponse | 404 | application/json |
| errors.InternalServerErrorResponse | 500 | application/json |
| errors.APIError | 4XX, 5XX | \*/\* |
## setOverride
### Example Usage
```typescript
import { Unkey } from "@unkey/api";
const unkey = new Unkey({
rootKey: "UNKEY_ROOT_KEY",
});
async function run() {
const result = await unkey.ratelimit.setOverride({
duration: 629394,
identifier: "<value>",
limit: 925291,
});
// Handle the result
console.log(result);
}
run();
```
### Standalone function
The standalone function version of this method:
```typescript
import { UnkeyCore } from "@unkey/api/core.js";
import { ratelimitSetOverride } from "@unkey/api/funcs/ratelimitSetOverride.js";
// Use `UnkeyCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const unkey = new UnkeyCore({
rootKey: "UNKEY_ROOT_KEY",
});
async function run() {
const res = await ratelimitSetOverride(unkey, {
duration: 629394,
identifier: "<value>",
limit: 925291,
});
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result);
}
run();
```
### Parameters
| Parameter | Type | Required | Description |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `request` | [components.V2RatelimitSetOverrideRequestBody](../../models/components/v2ratelimitsetoverriderequestbody.md) | :heavy_check_mark: | The request object to use for the request. |
| `options` | RequestOptions | :heavy_minus_sign: | Used to set various options for making HTTP requests. |
| `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy_minus_sign: | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. |
| `options.retries` | [RetryConfig](../../lib/utils/retryconfig.md) | :heavy_minus_sign: | Enables retrying HTTP requests under certain failure conditions. |
### Response
**Promise\<[components.V2RatelimitSetOverrideResponseBody](../../models/components/v2ratelimitsetoverrideresponsebody.md)\>**
### Errors
| Error Type | Status Code | Content Type |
| ---------------------------------- | ---------------------------------- | ---------------------------------- |
| errors.BadRequestErrorResponse | 400 | application/json |
| errors.UnauthorizedErrorResponse | 401 | application/json |
| errors.ForbiddenErrorResponse | 403 | application/json |
| errors.NotFoundErrorResponse | 404 | application/json |
| errors.InternalServerErrorResponse | 500 | application/json |
| errors.APIError | 4XX, 5XX | \*/\* |
## getOverride
### Example Usage
```typescript
import { Unkey } from "@unkey/api";
const unkey = new Unkey({
rootKey: "UNKEY_ROOT_KEY",
});
async function run() {
const result = await unkey.ratelimit.getOverride({
identifier: "<value>",
});
// Handle the result
console.log(result);
}
run();
```
### Standalone function
The standalone function version of this method:
```typescript
import { UnkeyCore } from "@unkey/api/core.js";
import { ratelimitGetOverride } from "@unkey/api/funcs/ratelimitGetOverride.js";
// Use `UnkeyCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const unkey = new UnkeyCore({
rootKey: "UNKEY_ROOT_KEY",
});
async function run() {
const res = await ratelimitGetOverride(unkey, {
identifier: "<value>",
});
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result);
}
run();
```
### Parameters
| Parameter | Type | Required | Description |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `request` | [components.V2RatelimitGetOverrideRequestBody](../../models/components/v2ratelimitgetoverriderequestbody.md) | :heavy_check_mark: | The request object to use for the request. |
| `options` | RequestOptions | :heavy_minus_sign: | Used to set various options for making HTTP requests. |
| `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy_minus_sign: | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. |
| `options.retries` | [RetryConfig](../../lib/utils/retryconfig.md) | :heavy_minus_sign: | Enables retrying HTTP requests under certain failure conditions. |
### Response
**Promise\<[components.V2RatelimitGetOverrideResponseBody](../../models/components/v2ratelimitgetoverrideresponsebody.md)\>**
### Errors
| Error Type | Status Code | Content Type |
| ---------------------------------- | ---------------------------------- | ---------------------------------- |
| errors.BadRequestErrorResponse | 400 | application/json |
| errors.UnauthorizedErrorResponse | 401 | application/json |
| errors.ForbiddenErrorResponse | 403 | application/json |
| errors.NotFoundErrorResponse | 404 | application/json |
| errors.InternalServerErrorResponse | 500 | application/json |
| errors.APIError | 4XX, 5XX | \*/\* |
## listOverrides
### Example Usage
```typescript
import { Unkey } from "@unkey/api";
const unkey = new Unkey({
rootKey: "UNKEY_ROOT_KEY",
});
async function run() {
const result = await unkey.ratelimit.listOverrides({});
// Handle the result
console.log(result);
}
run();
```
### Standalone function
The standalone function version of this method:
```typescript
import { UnkeyCore } from "@unkey/api/core.js";
import { ratelimitListOverrides } from "@unkey/api/funcs/ratelimitListOverrides.js";
// Use `UnkeyCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const unkey = new UnkeyCore({
rootKey: "UNKEY_ROOT_KEY",
});
async function run() {
const res = await ratelimitListOverrides(unkey, {});
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result);
}
run();
```
### Parameters
| Parameter | Type | Required | Description |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `request` | [components.V2RatelimitListOverridesRequestBody](../../models/components/v2ratelimitlistoverridesrequestbody.md) | :heavy_check_mark: | The request object to use for the request. |
| `options` | RequestOptions | :heavy_minus_sign: | Used to set various options for making HTTP requests. |
| `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy_minus_sign: | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. |
| `options.retries` | [RetryConfig](../../lib/utils/retryconfig.md) | :heavy_minus_sign: | Enables retrying HTTP requests under certain failure conditions. |
### Response
**Promise\<[components.V2RatelimitListOverridesResponseBody](../../models/components/v2ratelimitlistoverridesresponsebody.md)\>**
### Errors
| Error Type | Status Code | Content Type |
| ---------------------------------- | ---------------------------------- | ---------------------------------- |
| errors.BadRequestErrorResponse | 400 | application/json |
| errors.UnauthorizedErrorResponse | 401 | application/json |
| errors.ForbiddenErrorResponse | 403 | application/json |
| errors.NotFoundErrorResponse | 404 | application/json |
| errors.InternalServerErrorResponse | 500 | application/json |
| errors.APIError | 4XX, 5XX | \*/\* |
## deleteOverride
### Example Usage
```typescript
import { Unkey } from "@unkey/api";
const unkey = new Unkey({
rootKey: "UNKEY_ROOT_KEY",
});
async function run() {
const result = await unkey.ratelimit.deleteOverride({
identifier: "<value>",
});
// Handle the result
console.log(result);
}
run();
```
### Standalone function
The standalone function version of this method:
```typescript
import { UnkeyCore } from "@unkey/api/core.js";
import { ratelimitDeleteOverride } from "@unkey/api/funcs/ratelimitDeleteOverride.js";
// Use `UnkeyCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const unkey = new UnkeyCore({
rootKey: "UNKEY_ROOT_KEY",
});
async function run() {
const res = await ratelimitDeleteOverride(unkey, {
identifier: "<value>",
});
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result);
}
run();
```
### Parameters
| Parameter | Type | Required | Description |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `request` | [components.V2RatelimitDeleteOverrideRequestBody](../../models/components/v2ratelimitdeleteoverriderequestbody.md) | :heavy_check_mark: | The request object to use for the request. |
| `options` | RequestOptions | :heavy_minus_sign: | Used to set various options for making HTTP requests. |
| `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy_minus_sign: | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. |
| `options.retries` | [RetryConfig](../../lib/utils/retryconfig.md) | :heavy_minus_sign: | Enables retrying HTTP requests under certain failure conditions. |
### Response
**Promise\<[components.V2RatelimitDeleteOverrideResponseBody](../../models/components/v2ratelimitdeleteoverrideresponsebody.md)\>**
### Errors
| Error Type | Status Code | Content Type |
| ---------------------------------- | ---------------------------------- | ---------------------------------- |
| errors.BadRequestErrorResponse | 400 | application/json |
| errors.UnauthorizedErrorResponse | 401 | application/json |
| errors.ForbiddenErrorResponse | 403 | application/json |
| errors.NotFoundErrorResponse | 404 | application/json |
| errors.InternalServerErrorResponse | 500 | application/json |
| errors.APIError | 4XX, 5XX | \*/\* |