import {z} from 'zod' export type GetApiV0DedicatedEndpointsArgs = {ai_project_id?: (string | null) | undefined}; export type GetApiV0DedicatedEndpointsOptions = {baseUrl?: string | undefined, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const supportedGPU = z.enum(["gpu-l40s-d", "gpu-l40s-a", "gpu-h100-sxm", "gpu-h200-sxm", "gpu-b200-sxm", "gpu-b200-sxm-a", "gpu-b300-sxm"]); export const endpointScaling = z.object({min_replicas: z.number().int().gte(1), max_replicas: z.number().int().gte(1)}); export const deploymentStatus = z.enum(["starting", "running", "updating", "stopping", "stopped", "error"]); export const deploymentReadiness = z.enum(["ready", "partially_ready", "not_ready"]); export const endpointDeploymentStatus = z.object({ready_replicas: z.number().int(), status: deploymentStatus, readiness: deploymentReadiness}); export const dedicatedEndpoint = z.object({id: z.string(), name: z.string(), description: z.string(), enabled: z.boolean(), routing_key: z.string(), model_name: z.string(), flavor_name: z.string(), region: z.string(), gpu_type: supportedGPU, gpu_count: z.number().int(), custom_weights_id: z.string().nullable(), scaling: endpointScaling, deployment: endpointDeploymentStatus, created_at: z.string()}); export const dedicatedEndpointsListResponse = z.object({data: z.array(dedicatedEndpoint), object: 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 }; /** * List Dedicated Endpoints * * GET /v0/dedicated_endpoints */ export const getApiV0DedicatedEndpoints = async (args: GetApiV0DedicatedEndpointsArgs, options?: GetApiV0DedicatedEndpointsOptions) => { const {baseUrl = "https://api.tokenfactory.nebius.com", fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.ai_project_id != null) query.append("ai_project_id", String(args.ai_project_id)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v0/dedicated_endpoints${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(dedicatedEndpointsListResponse, await res.json()) };