import {z} from 'zod' export type GetApiOrganizationsOrganizationIdReservationsGpuTrackingLatestArgs = {organization_id: string, product_line?: Array | undefined, region?: Array | undefined}; export type GetApiOrganizationsOrganizationIdReservationsGpuTrackingLatestOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const gPUTrackingDatumMod = z.object({event_time: z.string().optional(), global_reservation_capacity: z.number().int().optional(), organization_id: z.string().optional(), overage_count: z.number().int().optional(), price: z.number().optional(), product_line: z.string().optional(), region: z.string().optional(), regional_reservation_capacity: z.number().int().optional(), running_compute_unit_count: z.number().int().optional()}); export const latestGPUTracking = z.object({data: z.array(gPUTrackingDatumMod).optional(), reservation_id: z.array(z.string()).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 }; /** * Get latest GPU tracking data for the specified organization. User must be part of the organization and have reservations feature access. * * GET /organizations/{organization_id}/reservations/gpu-tracking/latest */ export const getApiOrganizationsOrganizationIdReservationsGpuTrackingLatest = async (args: GetApiOrganizationsOrganizationIdReservationsGpuTrackingLatestArgs, options?: GetApiOrganizationsOrganizationIdReservationsGpuTrackingLatestOptions) => { const {baseUrl = "https://api.cloud.crusoe.ai/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.product_line ?? []) query.append("product_line", String(item)) for (const item of args.region ?? []) query.append("region", String(item)) const url = `${baseUrl.replace(/\/+$/, '')}/organizations/${encodeURIComponent(String(args.organization_id))}/reservations/gpu-tracking/latest${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(latestGPUTracking, await res.json()) };