import {z} from 'zod' export type GetApiV1AccountsAccountIdServerlessRateLimitsArgs = {deployment?: string | undefined, start?: string | undefined, end?: string | undefined, interval?: string | undefined, account_id: string}; export type GetApiV1AccountsAccountIdServerlessRateLimitsOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const accountRateLimitMetric = z.enum(["METRIC_UNSPECIFIED", "TOKENS_GENERATED", "TOKENS_PROMPT", "TOKENS_CACHE_ADJUSTED_PROMPT", "TOKENS_CACHED_PROMPT", "TOKENS_UNCACHED_PROMPT"]); export const gatewayAccountRateLimit = z.object({deployment: z.string(), metric: accountRateLimitMetric, effectiveLimit: z.number()}); export const gatewayTimeSeriesPoint = z.object({timestamp: z.string().optional(), value: z.string().optional()}); export const gatewayTimeSeries = z.object({labels: z.record(z.string(), z.string()).optional(), values: z.array(gatewayTimeSeriesPoint).optional()}); export const gatewayListAccountServerlessRateLimitsResponse = z.object({rateLimits: z.array(gatewayAccountRateLimit).optional(), series: z.array(gatewayTimeSeries).optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Lists effective global rate limits for shared serverless pool deployments (fireworks-owned). * Values reflect configured limits as observed in production monitoring. * * GET /v1/accounts/{account_id}/serverlessRateLimits */ export const getApiV1AccountsAccountIdServerlessRateLimits = async (args: GetApiV1AccountsAccountIdServerlessRateLimitsArgs, options: GetApiV1AccountsAccountIdServerlessRateLimitsOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.deployment != null) query.append("deployment", String(args.deployment)) if (args.start != null) query.append("start", String(args.start)) if (args.end != null) query.append("end", String(args.end)) if (args.interval != null) query.append("interval", String(args.interval)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/accounts/${encodeURIComponent(String(args.account_id))}/serverlessRateLimits${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(gatewayListAccountServerlessRateLimitsResponse, await res.json()) };