UNPKG

@unkey/api

Version:

Developer-friendly & type-safe Typescript SDK specifically catered to leverage *@unkey/api* API.

82 lines (76 loc) 2.86 kB
/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; export type V2RatelimitLimitRequestBody = { /** * The id or name of the namespace. */ namespace: string; /** * Sets how much of the rate limit quota this request consumes, enabling weighted rate limiting. * * @remarks * Use higher values for resource-intensive operations and 0 for tracking without limiting. * When accumulated cost exceeds the limit within the duration window, subsequent requests are rejected. * Essential for implementing fair usage policies and preventing resource abuse through expensive operations. */ cost?: number | undefined; /** * Sets the rate limit window duration in milliseconds after which the counter resets. * * @remarks * Shorter durations enable faster recovery but may be less effective against sustained abuse. * Common values include 60000 (1 minute), 3600000 (1 hour), and 86400000 (24 hours). * Balance user experience with protection needs when choosing window sizes. */ duration: number; /** * Defines the scope of rate limiting by identifying the entity being limited. * * @remarks * Use user IDs for per-user limits, IP addresses for anonymous limiting, or API key IDs for per-key limits. * Accepts letters, numbers, underscores, dots, colons, slashes, and hyphens for flexible identifier formats. * The same identifier can be used across different namespaces to apply multiple rate limit types. * Choose identifiers that provide appropriate granularity for your rate limiting strategy. */ identifier: string; /** * Sets the maximum operations allowed within the duration window before requests are rejected. * * @remarks * When this limit is reached, subsequent requests fail with `RATE_LIMITED` until the window resets. * Balance user experience with resource protection when setting limits for different user tiers. * Consider system capacity, business requirements, and fair usage policies in limit determination. */ limit: number; }; /** @internal */ export type V2RatelimitLimitRequestBody$Outbound = { namespace: string; cost: number; duration: number; identifier: string; limit: number; }; /** @internal */ export const V2RatelimitLimitRequestBody$outboundSchema: z.ZodType< V2RatelimitLimitRequestBody$Outbound, z.ZodTypeDef, V2RatelimitLimitRequestBody > = z.object({ namespace: z.string(), cost: z.number().int().default(1), duration: z.number().int(), identifier: z.string(), limit: z.number().int(), }); export function v2RatelimitLimitRequestBodyToJSON( v2RatelimitLimitRequestBody: V2RatelimitLimitRequestBody, ): string { return JSON.stringify( V2RatelimitLimitRequestBody$outboundSchema.parse( v2RatelimitLimitRequestBody, ), ); }