import {z} from 'zod' export type GetApiOrganizationsOrganizationIdReservationsGpuTrackingArgs = {organization_id: string, product_line?: Array | undefined, region?: Array | undefined, start_time?: string | undefined, end_time?: string | undefined}; export type GetApiOrganizationsOrganizationIdReservationsGpuTrackingOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const gPUTrackingDatum = z.object({event_time: z.string().optional(), global_capacity: z.number().int().optional(), gpu_usage: z.number().int().optional(), on_demand_count: z.number().int().optional(), organization_id: z.string().optional(), price: z.number().optional(), product_line: z.string().optional(), region: z.string().optional(), regional_capacity: z.number().int().optional()}); export const gPUTrackingResponse = z.object({data: z.array(gPUTrackingDatum).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 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 */ export const getApiOrganizationsOrganizationIdReservationsGpuTracking = async (args: GetApiOrganizationsOrganizationIdReservationsGpuTrackingArgs, options?: GetApiOrganizationsOrganizationIdReservationsGpuTrackingOptions) => { 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)) if (args.start_time != null) query.append("start_time", String(args.start_time)) if (args.end_time != null) query.append("end_time", String(args.end_time)) const url = `${baseUrl.replace(/\/+$/, '')}/organizations/${encodeURIComponent(String(args.organization_id))}/reservations/gpu-tracking${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(gPUTrackingResponse, await res.json()) };