/* * 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 { Result as SafeParseResult } from "../../types/fp.js"; import * as components from "../components/index.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; /** * Group cost by model / api_key_id (tenant key) / team_id (sub-tenant within an org) / external_user_id (caller-supplied end user, X-On-Behalf-Of, for resale chargeback) / org_id */ export type GroupBy = | Array | components.CostsUsageGroupBy; export type GetCostsUsageRequest = { startTime: number; endTime: number; orgId?: string | undefined; /** * Group cost by model / api_key_id (tenant key) / team_id (sub-tenant within an org) / external_user_id (caller-supplied end user, X-On-Behalf-Of, for resale chargeback) / org_id */ groupBy?: | Array | components.CostsUsageGroupBy | undefined; /** * Optional external end-user identifier forwarded by the API gateway. */ xOnBehalfOf?: string | undefined; }; /** @internal */ export const GroupBy$inboundSchema: z.ZodType = z.union([ z.array(components.CostsUsageGroupBy$inboundSchema), components.CostsUsageGroupBy$inboundSchema, ]); /** @internal */ export type GroupBy$Outbound = Array | string; /** @internal */ export const GroupBy$outboundSchema: z.ZodType< GroupBy$Outbound, z.ZodTypeDef, GroupBy > = z.union([ z.array(components.CostsUsageGroupBy$outboundSchema), components.CostsUsageGroupBy$outboundSchema, ]); export function groupByToJSON(groupBy: GroupBy): string { return JSON.stringify(GroupBy$outboundSchema.parse(groupBy)); } export function groupByFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => GroupBy$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'GroupBy' from JSON`, ); } /** @internal */ export const GetCostsUsageRequest$inboundSchema: z.ZodType< GetCostsUsageRequest, z.ZodTypeDef, unknown > = z.object({ start_time: z.number().int(), end_time: z.number().int(), org_id: z.string().optional(), group_by: z.union([ z.array(components.CostsUsageGroupBy$inboundSchema), components.CostsUsageGroupBy$inboundSchema, ]).optional(), "X-On-Behalf-Of": z.string().optional(), }).transform((v) => { return remap$(v, { "start_time": "startTime", "end_time": "endTime", "org_id": "orgId", "group_by": "groupBy", "X-On-Behalf-Of": "xOnBehalfOf", }); }); /** @internal */ export type GetCostsUsageRequest$Outbound = { start_time: number; end_time: number; org_id?: string | undefined; group_by?: Array | string | undefined; "X-On-Behalf-Of"?: string | undefined; }; /** @internal */ export const GetCostsUsageRequest$outboundSchema: z.ZodType< GetCostsUsageRequest$Outbound, z.ZodTypeDef, GetCostsUsageRequest > = z.object({ startTime: z.number().int(), endTime: z.number().int(), orgId: z.string().optional(), groupBy: z.union([ z.array(components.CostsUsageGroupBy$outboundSchema), components.CostsUsageGroupBy$outboundSchema, ]).optional(), xOnBehalfOf: z.string().optional(), }).transform((v) => { return remap$(v, { startTime: "start_time", endTime: "end_time", orgId: "org_id", groupBy: "group_by", xOnBehalfOf: "X-On-Behalf-Of", }); }); export function getCostsUsageRequestToJSON( getCostsUsageRequest: GetCostsUsageRequest, ): string { return JSON.stringify( GetCostsUsageRequest$outboundSchema.parse(getCostsUsageRequest), ); } export function getCostsUsageRequestFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => GetCostsUsageRequest$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'GetCostsUsageRequest' from JSON`, ); }