import {z} from 'zod' export type GetApiV1AccountsAccountIdBatchInferenceJobsBatchInferenceJobIdArgs = {readMask?: string | undefined, account_id: string, batch_inference_job_id: string}; export type GetApiV1AccountsAccountIdBatchInferenceJobsBatchInferenceJobIdOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const gatewayJobState = z.enum(["JOB_STATE_UNSPECIFIED", "JOB_STATE_CREATING", "JOB_STATE_RUNNING", "JOB_STATE_COMPLETED", "JOB_STATE_FAILED", "JOB_STATE_CANCELLED", "JOB_STATE_DELETING", "JOB_STATE_WRITING_RESULTS", "JOB_STATE_VALIDATING", "JOB_STATE_DELETING_CLEANING_UP", "JOB_STATE_PENDING", "JOB_STATE_EXPIRED", "JOB_STATE_RE_QUEUEING", "JOB_STATE_CREATING_INPUT_DATASET", "JOB_STATE_IDLE", "JOB_STATE_CANCELLING", "JOB_STATE_EARLY_STOPPED", "JOB_STATE_PAUSED", "JOB_STATE_DELETED", "JOB_STATE_ARCHIVED"]); 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 gatewayBatchInferenceJobInferenceParameters = z.object({maxTokens: z.number().int().optional(), temperature: z.number().optional(), topP: z.number().optional(), n: z.number().int().optional(), extraBody: z.string().optional(), topK: z.number().int().optional()}); 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 gatewayJobProgress = z.object({percent: z.number().int().optional(), epoch: z.number().int().optional(), totalInputRequests: z.number().int().optional(), totalProcessedRequests: z.number().int().optional(), successfullyProcessedRequests: z.number().int().optional(), failedRequests: z.number().int().optional(), outputRows: z.number().int().optional(), inputTokens: z.number().int().optional(), outputTokens: z.number().int().optional(), cachedInputTokenCount: z.number().int().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 batchInferenceJobLifecycleTimestamps = z.object({validatedTime: z.string().optional(), runStartTime: z.string().optional(), endTime: z.string().optional()}); export const gatewayBatchInferenceJob = z.object({name: z.string().optional(), displayName: z.string().optional(), createTime: z.string().optional(), expireTime: z.string().optional(), createdBy: z.string().optional(), state: gatewayJobState.optional(), status: gatewayStatus.optional(), model: z.string().optional(), inputDatasetId: z.string().optional(), outputDatasetId: z.string().optional(), systemPrompt: z.string().optional(), inferenceParameters: gatewayBatchInferenceJobInferenceParameters.optional(), updateTime: z.string().optional(), precision: deploymentPrecision.optional(), jobProgress: gatewayJobProgress.optional(), continuedFromJobName: z.string().optional(), placement: gatewayPlacement.optional(), maxJobDuration: z.string().optional(), lifecycle: batchInferenceJobLifecycleTimestamps.optional(), waitingOnCapacity: 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 Batch Inference Job * * GET /v1/accounts/{account_id}/batchInferenceJobs/{batch_inference_job_id} */ export const getApiV1AccountsAccountIdBatchInferenceJobsBatchInferenceJobId = async (args: GetApiV1AccountsAccountIdBatchInferenceJobsBatchInferenceJobIdArgs, options: GetApiV1AccountsAccountIdBatchInferenceJobsBatchInferenceJobIdOptions) => { 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))}/batchInferenceJobs/${encodeURIComponent(String(args.batch_inference_job_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(gatewayBatchInferenceJob, await res.json()) };