import {z} from 'zod' 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 GatewayGatewayPrepareModelBody = {precision?: DeploymentPrecision | undefined, readMask?: string | undefined, acceleratorCount?: number | undefined, abort?: boolean | undefined}; export type CreateApiV1AccountsAccountIdModelsModelIdPrepareArgs = {account_id: string, model_id: string, body: GatewayGatewayPrepareModelBody}; export type CreateApiV1AccountsAccountIdModelsModelIdPrepareOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1AccountsAccountIdModelsModelIdPrepareResponse = z.object({}); 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 }; /** * Prepare Model for different precisions * * POST /v1/accounts/{account_id}/models/{model_id}:prepare */ export const createApiV1AccountsAccountIdModelsModelIdPrepare = async (args: CreateApiV1AccountsAccountIdModelsModelIdPrepareArgs, options: CreateApiV1AccountsAccountIdModelsModelIdPrepareOptions) => { 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 (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/accounts/${encodeURIComponent(String(args.account_id))}/models/${encodeURIComponent(String(args.model_id))}:prepare${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(createApiV1AccountsAccountIdModelsModelIdPrepareResponse, await res.json()) };