/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { ClosedEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; /** * cluster = operator ceiling (org-admin read-only); org = self-budget */ export const SetApiKeyBudgetOwner = { Cluster: "cluster", Org: "org", } as const; /** * cluster = operator ceiling (org-admin read-only); org = self-budget */ export type SetApiKeyBudgetOwner = ClosedEnum; export const SetApiKeyBudgetPeriod = { Daily: "daily", Weekly: "weekly", Monthly: "monthly", } as const; export type SetApiKeyBudgetPeriod = ClosedEnum; export const SetApiKeyBudgetAction = { Alert: "alert", Block: "block", } as const; export type SetApiKeyBudgetAction = ClosedEnum; export type SetApiKeyBudgetThresholds = { pct: number; action: SetApiKeyBudgetAction; }; export type SetApiKeyBudgetRequestBody = { /** * cluster = operator ceiling (org-admin read-only); org = self-budget */ owner?: SetApiKeyBudgetOwner | undefined; period: SetApiKeyBudgetPeriod; /** * Spend limit in major currency units */ limit: number; thresholds: Array; webhookUrl?: string | null | undefined; webhookSecret?: string | null | undefined; }; export type SetApiKeyBudgetRequest = { apiKeyId: string; requestBody: SetApiKeyBudgetRequestBody; }; export const SetApiKeyBudgetScope = { Org: "org", Apikey: "apikey", User: "user", Team: "team", ExternalUser: "external_user", UserDefault: "user_default", TeamDefault: "team_default", ExternalUserDefault: "external_user_default", } as const; export type SetApiKeyBudgetScope = ClosedEnum; export const SetApiKeyBudgetBudgetsOwner = { Cluster: "cluster", Org: "org", } as const; export type SetApiKeyBudgetBudgetsOwner = ClosedEnum< typeof SetApiKeyBudgetBudgetsOwner >; export const SetApiKeyBudgetBudgetsPeriod = { Daily: "daily", Weekly: "weekly", Monthly: "monthly", } as const; export type SetApiKeyBudgetBudgetsPeriod = ClosedEnum< typeof SetApiKeyBudgetBudgetsPeriod >; export const SetApiKeyBudgetBudgetsAction = { Alert: "alert", Block: "block", } as const; export type SetApiKeyBudgetBudgetsAction = ClosedEnum< typeof SetApiKeyBudgetBudgetsAction >; export type SetApiKeyBudgetBudgetsThresholds = { pct: number; action: SetApiKeyBudgetBudgetsAction; }; export const SetApiKeyBudgetStatus = { Ok: "ok", Blocked: "blocked", } as const; export type SetApiKeyBudgetStatus = ClosedEnum; export type SetApiKeyBudgetSpend = { /** * Current period bucket, e.g. 2026-07 / 2026-W28 / 2026-07-07 */ window: string; /** * Live spend this window, major currency units */ costSpent: number; limit: number; pct: number; status: SetApiKeyBudgetStatus; }; /** * OK */ export type SetApiKeyBudgetResponseBody = { id: string; scope: SetApiKeyBudgetScope; scopeId: string; scopeOrgId: string | null; owner: SetApiKeyBudgetBudgetsOwner; period: SetApiKeyBudgetBudgetsPeriod; limit: number; thresholds: Array; alertWebhookUrl: string | null; spend: SetApiKeyBudgetSpend; }; /** @internal */ export const SetApiKeyBudgetOwner$inboundSchema: z.ZodNativeEnum< typeof SetApiKeyBudgetOwner > = z.nativeEnum(SetApiKeyBudgetOwner); /** @internal */ export const SetApiKeyBudgetOwner$outboundSchema: z.ZodNativeEnum< typeof SetApiKeyBudgetOwner > = SetApiKeyBudgetOwner$inboundSchema; /** @internal */ export const SetApiKeyBudgetPeriod$inboundSchema: z.ZodNativeEnum< typeof SetApiKeyBudgetPeriod > = z.nativeEnum(SetApiKeyBudgetPeriod); /** @internal */ export const SetApiKeyBudgetPeriod$outboundSchema: z.ZodNativeEnum< typeof SetApiKeyBudgetPeriod > = SetApiKeyBudgetPeriod$inboundSchema; /** @internal */ export const SetApiKeyBudgetAction$inboundSchema: z.ZodNativeEnum< typeof SetApiKeyBudgetAction > = z.nativeEnum(SetApiKeyBudgetAction); /** @internal */ export const SetApiKeyBudgetAction$outboundSchema: z.ZodNativeEnum< typeof SetApiKeyBudgetAction > = SetApiKeyBudgetAction$inboundSchema; /** @internal */ export const SetApiKeyBudgetThresholds$inboundSchema: z.ZodType< SetApiKeyBudgetThresholds, z.ZodTypeDef, unknown > = z.object({ pct: z.number().int(), action: SetApiKeyBudgetAction$inboundSchema, }); /** @internal */ export type SetApiKeyBudgetThresholds$Outbound = { pct: number; action: string; }; /** @internal */ export const SetApiKeyBudgetThresholds$outboundSchema: z.ZodType< SetApiKeyBudgetThresholds$Outbound, z.ZodTypeDef, SetApiKeyBudgetThresholds > = z.object({ pct: z.number().int(), action: SetApiKeyBudgetAction$outboundSchema, }); export function setApiKeyBudgetThresholdsToJSON( setApiKeyBudgetThresholds: SetApiKeyBudgetThresholds, ): string { return JSON.stringify( SetApiKeyBudgetThresholds$outboundSchema.parse(setApiKeyBudgetThresholds), ); } export function setApiKeyBudgetThresholdsFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => SetApiKeyBudgetThresholds$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'SetApiKeyBudgetThresholds' from JSON`, ); } /** @internal */ export const SetApiKeyBudgetRequestBody$inboundSchema: z.ZodType< SetApiKeyBudgetRequestBody, z.ZodTypeDef, unknown > = z.object({ owner: SetApiKeyBudgetOwner$inboundSchema.default("org"), period: SetApiKeyBudgetPeriod$inboundSchema, limit: z.number(), thresholds: z.array(z.lazy(() => SetApiKeyBudgetThresholds$inboundSchema)), webhook_url: z.nullable(z.string()).optional(), webhook_secret: z.nullable(z.string()).optional(), }).transform((v) => { return remap$(v, { "webhook_url": "webhookUrl", "webhook_secret": "webhookSecret", }); }); /** @internal */ export type SetApiKeyBudgetRequestBody$Outbound = { owner: string; period: string; limit: number; thresholds: Array; webhook_url?: string | null | undefined; webhook_secret?: string | null | undefined; }; /** @internal */ export const SetApiKeyBudgetRequestBody$outboundSchema: z.ZodType< SetApiKeyBudgetRequestBody$Outbound, z.ZodTypeDef, SetApiKeyBudgetRequestBody > = z.object({ owner: SetApiKeyBudgetOwner$outboundSchema.default("org"), period: SetApiKeyBudgetPeriod$outboundSchema, limit: z.number(), thresholds: z.array(z.lazy(() => SetApiKeyBudgetThresholds$outboundSchema)), webhookUrl: z.nullable(z.string()).optional(), webhookSecret: z.nullable(z.string()).optional(), }).transform((v) => { return remap$(v, { webhookUrl: "webhook_url", webhookSecret: "webhook_secret", }); }); export function setApiKeyBudgetRequestBodyToJSON( setApiKeyBudgetRequestBody: SetApiKeyBudgetRequestBody, ): string { return JSON.stringify( SetApiKeyBudgetRequestBody$outboundSchema.parse(setApiKeyBudgetRequestBody), ); } export function setApiKeyBudgetRequestBodyFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => SetApiKeyBudgetRequestBody$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'SetApiKeyBudgetRequestBody' from JSON`, ); } /** @internal */ export const SetApiKeyBudgetRequest$inboundSchema: z.ZodType< SetApiKeyBudgetRequest, z.ZodTypeDef, unknown > = z.object({ apiKeyId: z.string(), RequestBody: z.lazy(() => SetApiKeyBudgetRequestBody$inboundSchema), }).transform((v) => { return remap$(v, { "RequestBody": "requestBody", }); }); /** @internal */ export type SetApiKeyBudgetRequest$Outbound = { apiKeyId: string; RequestBody: SetApiKeyBudgetRequestBody$Outbound; }; /** @internal */ export const SetApiKeyBudgetRequest$outboundSchema: z.ZodType< SetApiKeyBudgetRequest$Outbound, z.ZodTypeDef, SetApiKeyBudgetRequest > = z.object({ apiKeyId: z.string(), requestBody: z.lazy(() => SetApiKeyBudgetRequestBody$outboundSchema), }).transform((v) => { return remap$(v, { requestBody: "RequestBody", }); }); export function setApiKeyBudgetRequestToJSON( setApiKeyBudgetRequest: SetApiKeyBudgetRequest, ): string { return JSON.stringify( SetApiKeyBudgetRequest$outboundSchema.parse(setApiKeyBudgetRequest), ); } export function setApiKeyBudgetRequestFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => SetApiKeyBudgetRequest$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'SetApiKeyBudgetRequest' from JSON`, ); } /** @internal */ export const SetApiKeyBudgetScope$inboundSchema: z.ZodNativeEnum< typeof SetApiKeyBudgetScope > = z.nativeEnum(SetApiKeyBudgetScope); /** @internal */ export const SetApiKeyBudgetScope$outboundSchema: z.ZodNativeEnum< typeof SetApiKeyBudgetScope > = SetApiKeyBudgetScope$inboundSchema; /** @internal */ export const SetApiKeyBudgetBudgetsOwner$inboundSchema: z.ZodNativeEnum< typeof SetApiKeyBudgetBudgetsOwner > = z.nativeEnum(SetApiKeyBudgetBudgetsOwner); /** @internal */ export const SetApiKeyBudgetBudgetsOwner$outboundSchema: z.ZodNativeEnum< typeof SetApiKeyBudgetBudgetsOwner > = SetApiKeyBudgetBudgetsOwner$inboundSchema; /** @internal */ export const SetApiKeyBudgetBudgetsPeriod$inboundSchema: z.ZodNativeEnum< typeof SetApiKeyBudgetBudgetsPeriod > = z.nativeEnum(SetApiKeyBudgetBudgetsPeriod); /** @internal */ export const SetApiKeyBudgetBudgetsPeriod$outboundSchema: z.ZodNativeEnum< typeof SetApiKeyBudgetBudgetsPeriod > = SetApiKeyBudgetBudgetsPeriod$inboundSchema; /** @internal */ export const SetApiKeyBudgetBudgetsAction$inboundSchema: z.ZodNativeEnum< typeof SetApiKeyBudgetBudgetsAction > = z.nativeEnum(SetApiKeyBudgetBudgetsAction); /** @internal */ export const SetApiKeyBudgetBudgetsAction$outboundSchema: z.ZodNativeEnum< typeof SetApiKeyBudgetBudgetsAction > = SetApiKeyBudgetBudgetsAction$inboundSchema; /** @internal */ export const SetApiKeyBudgetBudgetsThresholds$inboundSchema: z.ZodType< SetApiKeyBudgetBudgetsThresholds, z.ZodTypeDef, unknown > = z.object({ pct: z.number().int(), action: SetApiKeyBudgetBudgetsAction$inboundSchema, }); /** @internal */ export type SetApiKeyBudgetBudgetsThresholds$Outbound = { pct: number; action: string; }; /** @internal */ export const SetApiKeyBudgetBudgetsThresholds$outboundSchema: z.ZodType< SetApiKeyBudgetBudgetsThresholds$Outbound, z.ZodTypeDef, SetApiKeyBudgetBudgetsThresholds > = z.object({ pct: z.number().int(), action: SetApiKeyBudgetBudgetsAction$outboundSchema, }); export function setApiKeyBudgetBudgetsThresholdsToJSON( setApiKeyBudgetBudgetsThresholds: SetApiKeyBudgetBudgetsThresholds, ): string { return JSON.stringify( SetApiKeyBudgetBudgetsThresholds$outboundSchema.parse( setApiKeyBudgetBudgetsThresholds, ), ); } export function setApiKeyBudgetBudgetsThresholdsFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => SetApiKeyBudgetBudgetsThresholds$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'SetApiKeyBudgetBudgetsThresholds' from JSON`, ); } /** @internal */ export const SetApiKeyBudgetStatus$inboundSchema: z.ZodNativeEnum< typeof SetApiKeyBudgetStatus > = z.nativeEnum(SetApiKeyBudgetStatus); /** @internal */ export const SetApiKeyBudgetStatus$outboundSchema: z.ZodNativeEnum< typeof SetApiKeyBudgetStatus > = SetApiKeyBudgetStatus$inboundSchema; /** @internal */ export const SetApiKeyBudgetSpend$inboundSchema: z.ZodType< SetApiKeyBudgetSpend, z.ZodTypeDef, unknown > = z.object({ window: z.string(), cost_spent: z.number(), limit: z.number(), pct: z.number().int(), status: SetApiKeyBudgetStatus$inboundSchema, }).transform((v) => { return remap$(v, { "cost_spent": "costSpent", }); }); /** @internal */ export type SetApiKeyBudgetSpend$Outbound = { window: string; cost_spent: number; limit: number; pct: number; status: string; }; /** @internal */ export const SetApiKeyBudgetSpend$outboundSchema: z.ZodType< SetApiKeyBudgetSpend$Outbound, z.ZodTypeDef, SetApiKeyBudgetSpend > = z.object({ window: z.string(), costSpent: z.number(), limit: z.number(), pct: z.number().int(), status: SetApiKeyBudgetStatus$outboundSchema, }).transform((v) => { return remap$(v, { costSpent: "cost_spent", }); }); export function setApiKeyBudgetSpendToJSON( setApiKeyBudgetSpend: SetApiKeyBudgetSpend, ): string { return JSON.stringify( SetApiKeyBudgetSpend$outboundSchema.parse(setApiKeyBudgetSpend), ); } export function setApiKeyBudgetSpendFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => SetApiKeyBudgetSpend$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'SetApiKeyBudgetSpend' from JSON`, ); } /** @internal */ export const SetApiKeyBudgetResponseBody$inboundSchema: z.ZodType< SetApiKeyBudgetResponseBody, z.ZodTypeDef, unknown > = z.object({ id: z.string(), scope: SetApiKeyBudgetScope$inboundSchema, scope_id: z.string(), scope_org_id: z.nullable(z.string()), owner: SetApiKeyBudgetBudgetsOwner$inboundSchema, period: SetApiKeyBudgetBudgetsPeriod$inboundSchema, limit: z.number(), thresholds: z.array( z.lazy(() => SetApiKeyBudgetBudgetsThresholds$inboundSchema), ), alert_webhook_url: z.nullable(z.string()), spend: z.lazy(() => SetApiKeyBudgetSpend$inboundSchema), }).transform((v) => { return remap$(v, { "scope_id": "scopeId", "scope_org_id": "scopeOrgId", "alert_webhook_url": "alertWebhookUrl", }); }); /** @internal */ export type SetApiKeyBudgetResponseBody$Outbound = { id: string; scope: string; scope_id: string; scope_org_id: string | null; owner: string; period: string; limit: number; thresholds: Array; alert_webhook_url: string | null; spend: SetApiKeyBudgetSpend$Outbound; }; /** @internal */ export const SetApiKeyBudgetResponseBody$outboundSchema: z.ZodType< SetApiKeyBudgetResponseBody$Outbound, z.ZodTypeDef, SetApiKeyBudgetResponseBody > = z.object({ id: z.string(), scope: SetApiKeyBudgetScope$outboundSchema, scopeId: z.string(), scopeOrgId: z.nullable(z.string()), owner: SetApiKeyBudgetBudgetsOwner$outboundSchema, period: SetApiKeyBudgetBudgetsPeriod$outboundSchema, limit: z.number(), thresholds: z.array( z.lazy(() => SetApiKeyBudgetBudgetsThresholds$outboundSchema), ), alertWebhookUrl: z.nullable(z.string()), spend: z.lazy(() => SetApiKeyBudgetSpend$outboundSchema), }).transform((v) => { return remap$(v, { scopeId: "scope_id", scopeOrgId: "scope_org_id", alertWebhookUrl: "alert_webhook_url", }); }); export function setApiKeyBudgetResponseBodyToJSON( setApiKeyBudgetResponseBody: SetApiKeyBudgetResponseBody, ): string { return JSON.stringify( SetApiKeyBudgetResponseBody$outboundSchema.parse( setApiKeyBudgetResponseBody, ), ); } export function setApiKeyBudgetResponseBodyFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => SetApiKeyBudgetResponseBody$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'SetApiKeyBudgetResponseBody' from JSON`, ); }