import {z} from 'zod' export type GatewayDeploymentState = 'STATE_UNSPECIFIED' | 'CREATING' | 'READY' | 'DELETING' | 'FAILED' | 'UPDATING' | 'DELETED'; export type GatewayCode = 'OK' | 'CANCELLED' | 'UNKNOWN' | 'INVALID_ARGUMENT' | 'DEADLINE_EXCEEDED' | 'NOT_FOUND' | 'ALREADY_EXISTS' | 'PERMISSION_DENIED' | 'UNAUTHENTICATED' | 'RESOURCE_EXHAUSTED' | 'FAILED_PRECONDITION' | 'ABORTED' | 'OUT_OF_RANGE' | 'UNIMPLEMENTED' | 'INTERNAL' | 'UNAVAILABLE' | 'DATA_LOSS'; export type GatewayStatus = {code?: GatewayCode | undefined, message?: string | undefined}; export type GatewayScalingSchedule = {minReplicaCount: number, schedule: string, duration: string, timezone: string, description?: string | undefined, disabled?: boolean | undefined}; export type GatewayAutoscalingPolicy = {scaleUpWindow?: string | undefined, scaleDownWindow?: string | undefined, scaleToZeroWindow?: string | undefined, loadTargets?: {[key: string]: number} | undefined, scalingSchedules?: {[key: string]: GatewayScalingSchedule} | undefined}; export type GatewayAcceleratorType = 'ACCELERATOR_TYPE_UNSPECIFIED' | 'NVIDIA_A100_80GB' | 'NVIDIA_H100_80GB' | 'AMD_MI300X_192GB' | 'NVIDIA_A10G_24GB' | 'NVIDIA_A100_40GB' | 'NVIDIA_L4_24GB' | 'NVIDIA_H200_141GB' | 'NVIDIA_B200_180GB' | 'AMD_MI325X_256GB' | 'AMD_MI350X_288GB' | 'NVIDIA_B300_288GB' | 'NVIDIA_GB200' | 'NVIDIA_GB300'; export type DeploymentPrecision = 'PRECISION_UNSPECIFIED' | 'FP16' | 'FP8' | 'FP8_MM' | 'FP8_AR' | 'FP8_MM_KV_ATTN' | 'FP8_KV' | 'FP8_MM_V2' | 'FP8_V2' | 'FP8_MM_KV_ATTN_V2' | 'NF4' | 'FP4' | 'BF16' | 'FP4_BLOCKSCALED_MM' | 'FP4_MX_MOE'; export type GatewayDirectRouteType = 'DIRECT_ROUTE_TYPE_UNSPECIFIED' | 'INTERNET' | 'GCP_PRIVATE_SERVICE_CONNECT' | 'AWS_PRIVATELINK'; export type GatewayAutoTune = {longPrompt?: boolean | undefined}; export type GatewayRegion = 'REGION_UNSPECIFIED' | 'US_IOWA_1' | 'US_VIRGINIA_1' | 'US_VIRGINIA_2' | 'US_ILLINOIS_1' | 'AP_TOKYO_1' | 'US_ARIZONA_1' | 'US_TEXAS_1' | 'US_ILLINOIS_2' | 'EU_FRANKFURT_1' | 'US_TEXAS_2' | 'EU_ICELAND_1' | 'EU_ICELAND_2' | 'US_WASHINGTON_1' | 'US_WASHINGTON_2' | 'US_WASHINGTON_3' | 'AP_TOKYO_2' | 'US_CALIFORNIA_1' | 'US_UTAH_1' | 'US_ARIZONA_3' | 'US_GEORGIA_1' | 'US_GEORGIA_2' | 'US_WASHINGTON_4' | 'US_GEORGIA_3' | 'NA_BRITISHCOLUMBIA_1' | 'US_GEORGIA_4' | 'US_OHIO_1' | 'US_NEWYORK_1' | 'EU_NETHERLANDS_1' | 'US_WASHINGTON_5' | 'US_MINNESOTA_1' | 'US_CALIFORNIA_2' | 'NA_BRITISHCOLUMBIA_2' | 'AP_MALAYSIA_2' | 'US_OREGON_1' | 'NA_BRITISHCOLUMBIA_3' | 'AP_NEWSOUTHWALES_1' | 'AP_TAIWAN_1'; export type GatewayMultiRegion = 'MULTI_REGION_UNSPECIFIED' | 'GLOBAL' | 'US' | 'CANADA' | 'EUROPE' | 'APAC'; export type GatewayPlacement = {region?: GatewayRegion | undefined, multiRegion?: GatewayMultiRegion | undefined, regions?: Array | undefined}; export type DeploymentHotLoadBucketType = 'BUCKET_TYPE_UNSPECIFIED' | 'MINIO' | 'S3' | 'NEBIUS' | 'FW_HOSTED'; export type GatewayReplicaStats = {pendingSchedulingReplicaCount?: number | undefined, downloadingModelReplicaCount?: number | undefined, initializingReplicaCount?: number | undefined, readyReplicaCount?: number | undefined, revocableReplicaCount?: number | undefined, effectiveReplicaCount?: number | undefined}; export type DeploymentHotLoadTransitionType = 'HOT_LOAD_TRANSITION_TYPE_UNSPECIFIED' | 'ASYNC' | 'SYNC'; export type GatewayDeployment = {name?: string | undefined, displayName?: string | undefined, description?: string | undefined, createTime?: string | undefined, expireTime?: string | undefined, purgeTime?: string | undefined, deleteTime?: string | undefined, state?: GatewayDeploymentState | undefined, status?: GatewayStatus | undefined, annotations?: {[key: string]: string} | undefined, minReplicaCount?: number | undefined, maxReplicaCount?: number | undefined, maxWithRevocableReplicaCount?: number | undefined, desiredReplicaCount?: number | undefined, replicaCount?: number | undefined, autoscalingPolicy?: GatewayAutoscalingPolicy | undefined, baseModel: string, acceleratorCount?: number | undefined, acceleratorType?: GatewayAcceleratorType | undefined, precision?: DeploymentPrecision | undefined, maxConcurrencyPerReplica?: number | undefined, cluster?: string | undefined, enableAddons?: boolean | undefined, draftTokenCount?: number | undefined, draftModel?: string | undefined, ngramSpeculationLength?: number | undefined, enableSessionAffinity?: boolean | undefined, directRouteApiKeys?: Array | undefined, numPeftDeviceCached?: number | undefined, directRouteType?: GatewayDirectRouteType | undefined, directRouteHandle?: string | undefined, deploymentTemplate?: string | undefined, autoTune?: GatewayAutoTune | undefined, placement?: GatewayPlacement | undefined, region?: GatewayRegion | undefined, maxContextLength?: number | undefined, updateTime?: string | undefined, disableDeploymentSizeValidation?: boolean | undefined, enableHotLoad?: boolean | undefined, hotLoadBucketType?: DeploymentHotLoadBucketType | undefined, enableHotReloadLatestAddon?: boolean | undefined, deploymentShape?: string | undefined, activeModelVersion?: string | undefined, targetModelVersion?: string | undefined, replicaStats?: GatewayReplicaStats | undefined, hotLoadBucketUrl?: string | undefined, pricingPlanId?: string | undefined, hotLoadTrainerJob?: string | undefined, hotLoadTransitionType?: DeploymentHotLoadTransitionType | undefined, preemptible?: boolean | undefined}; export type CreateApiV1AccountsAccountIdDeploymentsArgs = {disableAutoDeploy?: boolean | undefined, disableSpeculativeDecoding?: boolean | undefined, deploymentId?: string | undefined, validateOnly?: boolean | undefined, skipShapeValidation?: boolean | undefined, skipImageTagValidation?: boolean | undefined, account_id: string, body: GatewayDeployment}; export type CreateApiV1AccountsAccountIdDeploymentsOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const gatewayDeploymentState = z.enum(["STATE_UNSPECIFIED", "CREATING", "READY", "DELETING", "FAILED", "UPDATING", "DELETED"]); export const gatewayCode = z.enum(["OK", "CANCELLED", "UNKNOWN", "INVALID_ARGUMENT", "DEADLINE_EXCEEDED", "NOT_FOUND", "ALREADY_EXISTS", "PERMISSION_DENIED", "UNAUTHENTICATED", "RESOURCE_EXHAUSTED", "FAILED_PRECONDITION", "ABORTED", "OUT_OF_RANGE", "UNIMPLEMENTED", "INTERNAL", "UNAVAILABLE", "DATA_LOSS"]); export const gatewayStatus = z.object({code: gatewayCode.optional(), message: z.string().optional()}); export const gatewayScalingSchedule = z.object({minReplicaCount: z.number().int(), schedule: z.string(), duration: z.string(), timezone: z.string(), description: z.string().optional(), disabled: z.boolean().optional()}); export const gatewayAutoscalingPolicy = z.object({scaleUpWindow: z.string().optional(), scaleDownWindow: z.string().optional(), scaleToZeroWindow: z.string().optional(), loadTargets: z.record(z.string(), z.number()).optional(), scalingSchedules: z.record(z.string(), gatewayScalingSchedule).optional()}); export const gatewayAcceleratorType = z.enum(["ACCELERATOR_TYPE_UNSPECIFIED", "NVIDIA_A100_80GB", "NVIDIA_H100_80GB", "AMD_MI300X_192GB", "NVIDIA_A10G_24GB", "NVIDIA_A100_40GB", "NVIDIA_L4_24GB", "NVIDIA_H200_141GB", "NVIDIA_B200_180GB", "AMD_MI325X_256GB", "AMD_MI350X_288GB", "NVIDIA_B300_288GB", "NVIDIA_GB200", "NVIDIA_GB300"]); export const deploymentPrecision = z.enum(["PRECISION_UNSPECIFIED", "FP16", "FP8", "FP8_MM", "FP8_AR", "FP8_MM_KV_ATTN", "FP8_KV", "FP8_MM_V2", "FP8_V2", "FP8_MM_KV_ATTN_V2", "NF4", "FP4", "BF16", "FP4_BLOCKSCALED_MM", "FP4_MX_MOE"]); export const gatewayDirectRouteType = z.enum(["DIRECT_ROUTE_TYPE_UNSPECIFIED", "INTERNET", "GCP_PRIVATE_SERVICE_CONNECT", "AWS_PRIVATELINK"]); export const gatewayAutoTune = z.object({longPrompt: z.boolean().optional()}); export const gatewayRegion = z.enum(["REGION_UNSPECIFIED", "US_IOWA_1", "US_VIRGINIA_1", "US_VIRGINIA_2", "US_ILLINOIS_1", "AP_TOKYO_1", "US_ARIZONA_1", "US_TEXAS_1", "US_ILLINOIS_2", "EU_FRANKFURT_1", "US_TEXAS_2", "EU_ICELAND_1", "EU_ICELAND_2", "US_WASHINGTON_1", "US_WASHINGTON_2", "US_WASHINGTON_3", "AP_TOKYO_2", "US_CALIFORNIA_1", "US_UTAH_1", "US_ARIZONA_3", "US_GEORGIA_1", "US_GEORGIA_2", "US_WASHINGTON_4", "US_GEORGIA_3", "NA_BRITISHCOLUMBIA_1", "US_GEORGIA_4", "US_OHIO_1", "US_NEWYORK_1", "EU_NETHERLANDS_1", "US_WASHINGTON_5", "US_MINNESOTA_1", "US_CALIFORNIA_2", "NA_BRITISHCOLUMBIA_2", "AP_MALAYSIA_2", "US_OREGON_1", "NA_BRITISHCOLUMBIA_3", "AP_NEWSOUTHWALES_1", "AP_TAIWAN_1"]); export const gatewayMultiRegion = z.enum(["MULTI_REGION_UNSPECIFIED", "GLOBAL", "US", "CANADA", "EUROPE", "APAC"]); export const gatewayPlacement = z.object({region: gatewayRegion.optional(), multiRegion: gatewayMultiRegion.optional(), regions: z.array(gatewayRegion).optional()}); export const deploymentHotLoadBucketType = z.enum(["BUCKET_TYPE_UNSPECIFIED", "MINIO", "S3", "NEBIUS", "FW_HOSTED"]); export const gatewayReplicaStats = z.object({pendingSchedulingReplicaCount: z.number().int().optional(), downloadingModelReplicaCount: z.number().int().optional(), initializingReplicaCount: z.number().int().optional(), readyReplicaCount: z.number().int().optional(), revocableReplicaCount: z.number().int().optional(), effectiveReplicaCount: z.number().optional()}); export const deploymentHotLoadTransitionType = z.enum(["HOT_LOAD_TRANSITION_TYPE_UNSPECIFIED", "ASYNC", "SYNC"]); export const gatewayDeployment = z.object({name: z.string().optional(), displayName: z.string().optional(), description: z.string().optional(), createTime: z.string().optional(), expireTime: z.string().optional(), purgeTime: z.string().optional(), deleteTime: z.string().optional(), state: gatewayDeploymentState.optional(), status: gatewayStatus.optional(), annotations: z.record(z.string(), z.string()).optional(), minReplicaCount: z.number().int().optional(), maxReplicaCount: z.number().int().optional(), maxWithRevocableReplicaCount: z.number().int().optional(), desiredReplicaCount: z.number().int().optional(), replicaCount: z.number().int().optional(), autoscalingPolicy: gatewayAutoscalingPolicy.optional(), baseModel: z.string(), acceleratorCount: z.number().int().optional(), acceleratorType: gatewayAcceleratorType.optional(), precision: deploymentPrecision.optional(), maxConcurrencyPerReplica: z.number().int().optional(), cluster: z.string().optional(), enableAddons: z.boolean().optional(), draftTokenCount: z.number().int().optional(), draftModel: z.string().optional(), ngramSpeculationLength: z.number().int().optional(), enableSessionAffinity: z.boolean().optional(), directRouteApiKeys: z.array(z.string()).optional(), numPeftDeviceCached: z.number().int().optional(), directRouteType: gatewayDirectRouteType.optional(), directRouteHandle: z.string().optional(), deploymentTemplate: z.string().optional(), autoTune: gatewayAutoTune.optional(), placement: gatewayPlacement.optional(), region: gatewayRegion.optional(), maxContextLength: z.number().int().optional(), updateTime: z.string().optional(), disableDeploymentSizeValidation: z.boolean().optional(), enableHotLoad: z.boolean().optional(), hotLoadBucketType: deploymentHotLoadBucketType.optional(), enableHotReloadLatestAddon: z.boolean().optional(), deploymentShape: z.string().optional(), activeModelVersion: z.string().optional(), targetModelVersion: z.string().optional(), replicaStats: gatewayReplicaStats.optional(), hotLoadBucketUrl: z.string().optional(), pricingPlanId: z.string().optional(), hotLoadTrainerJob: z.string().optional(), hotLoadTransitionType: deploymentHotLoadTransitionType.optional(), preemptible: z.boolean().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 }; /** * Create Deployment * * POST /v1/accounts/{account_id}/deployments */ export const createApiV1AccountsAccountIdDeployments = async (args: CreateApiV1AccountsAccountIdDeploymentsArgs, options: CreateApiV1AccountsAccountIdDeploymentsOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.disableAutoDeploy != null) query.append("disableAutoDeploy", String(args.disableAutoDeploy)) if (args.disableSpeculativeDecoding != null) query.append("disableSpeculativeDecoding", String(args.disableSpeculativeDecoding)) if (args.deploymentId != null) query.append("deploymentId", String(args.deploymentId)) if (args.validateOnly != null) query.append("validateOnly", String(args.validateOnly)) if (args.skipShapeValidation != null) query.append("skipShapeValidation", String(args.skipShapeValidation)) if (args.skipImageTagValidation != null) query.append("skipImageTagValidation", String(args.skipImageTagValidation)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/accounts/${encodeURIComponent(String(args.account_id))}/deployments${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(gatewayDeployment, await res.json()) };