import {z} from 'zod' export type GetApiOrganizationsOrganizationNameGpuClassesOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const containerGroupPriority = z.enum(["high", "medium", "low", "batch"]).nullable(); export const gpuClassPrice = z.object({price: z.string().min(1).max(20), priority: containerGroupPriority}); export const gpuClass = z.object({gpu_class_type: z.enum(["community", "secure"]).optional(), gpu_count: z.number().int().gte(1).lte(512).optional(), id: z.string(), is_high_demand: z.boolean().optional(), max_ram: z.number().int().gte(0).optional(), max_storage: z.number().int().gte(0).optional(), max_vcpu: z.number().int().gte(0).optional(), min_ram: z.number().int().gte(0).optional(), min_storage: z.number().int().gte(0).optional(), min_vcpu: z.number().int().gte(0).optional(), name: z.string().min(2).max(63), prices: z.array(gpuClassPrice)}); export const gpuClassesList = z.object({items: z.array(gpuClass)}); 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 }; /** * List the GPU Classes * * GET /organizations/{organization_name}/gpu-classes */ export const getApiOrganizationsOrganizationNameGpuClasses = async (options?: GetApiOrganizationsOrganizationNameGpuClassesOptions) => { const {baseUrl = "https://api.salad.com/api/public", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("Salad-Api-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/organizations/${encodeURIComponent(String(args.organization_name))}/gpu-classes${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(gpuClassesList, await res.json()) };