import {z} from 'zod' export type SupportedGPU = 'gpu-l40s-d' | 'gpu-l40s-a' | 'gpu-h100-sxm' | 'gpu-h200-sxm' | 'gpu-b200-sxm' | 'gpu-b200-sxm-a' | 'gpu-b300-sxm'; export type EndpointScaling = {min_replicas: number, max_replicas: number}; export type DedicatedEndpointUpdateRequest = {name?: (string | null) | undefined, description?: (string | null) | undefined, enabled?: (boolean | null) | undefined, gpu_type?: (SupportedGPU | null) | undefined, gpu_count?: (number | null) | undefined, custom_weights_id?: (string | null) | undefined, scaling?: (EndpointScaling | null) | undefined}; export type PatchApiV0DedicatedEndpointsEndpointIdArgs = {endpoint_id: string, body: DedicatedEndpointUpdateRequest}; export type PatchApiV0DedicatedEndpointsEndpointIdOptions = {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 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 }; /** * Update Dedicated Endpoint * * PATCH /v0/dedicated_endpoints/{endpoint_id} */ export const patchApiV0DedicatedEndpointsEndpointId = async (args: PatchApiV0DedicatedEndpointsEndpointIdArgs, options?: PatchApiV0DedicatedEndpointsEndpointIdOptions) => { const {baseUrl = "https://api.tokenfactory.nebius.com", fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v0/dedicated_endpoints/${encodeURIComponent(String(args.endpoint_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(dedicatedEndpoint, await res.json()) };