import {z} from 'zod' export type GetApiV1AccountsAccountIdDeploymentsDeploymentIdArgs = {readMask?: string | undefined, account_id: string, deployment_id: string}; export type GetApiV1AccountsAccountIdDeploymentsDeploymentIdOptions = {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 }; /** * Get Deployment * * GET /v1/accounts/{account_id}/deployments/{deployment_id} */ export const getApiV1AccountsAccountIdDeploymentsDeploymentId = async (args: GetApiV1AccountsAccountIdDeploymentsDeploymentIdArgs, options: GetApiV1AccountsAccountIdDeploymentsDeploymentIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.readMask != null) query.append("readMask", String(args.readMask)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/accounts/${encodeURIComponent(String(args.account_id))}/deployments/${encodeURIComponent(String(args.deployment_id))}${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(gatewayDeployment, await res.json()) };