import {z} from 'zod' export type GetApiV1TrainingUsageArgs = {project_id?: (string | null) | undefined}; export type GetApiV1TrainingUsageOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const storageUsageRow = z.object({checkpoint_count: z.number().int(), estimated_monthly_cost_usd: z.number(), org_user_urn: z.string(), project_id: z.string().nullable().optional(), size_bytes: z.number().int(), size_gigabytes: z.number(), user_email: z.string().nullable().optional(), user_name: z.string()}); export const storageUsageResponse = z.object({data: z.array(storageUsageRow), effective_rate_usd_per_gigabyte_month: z.number()}); 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 interactive training checkpoint storage usage * * GET /v1/training/usage * * Also accepts auth: BearerAuth */ export const getApiV1TrainingUsage = async (args: GetApiV1TrainingUsageArgs, options?: GetApiV1TrainingUsageOptions) => { const {baseUrl = "https://api.fastino.ai", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.project_id != null) query.append("project_id", String(args.project_id)) if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/training/usage${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(storageUsageResponse, await res.json()) };