import {z} from 'zod' export type GatewayModelState = 'STATE_UNSPECIFIED' | 'UPLOADING' | 'READY'; 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 ModelKind = 'KIND_UNSPECIFIED' | 'HF_BASE_MODEL' | 'HF_PEFT_ADDON' | 'HF_TEFT_ADDON' | 'FLUMINA_BASE_MODEL' | 'FLUMINA_ADDON' | 'DRAFT_ADDON' | 'LIVE_MERGE' | 'CUSTOM_MODEL' | 'EMBEDDING_MODEL' | 'SNAPSHOT_MODEL'; export type BaseModelDetailsCheckpointFormat = 'CHECKPOINT_FORMAT_UNSPECIFIED' | 'NATIVE' | 'HUGGINGFACE' | 'UNINITIALIZED'; 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 GatewayBaseModelDetails = {worldSize?: number | undefined, checkpointFormat?: BaseModelDetailsCheckpointFormat | undefined, huggingfaceFiles?: Array | undefined, parameterCount?: unknown | undefined, moe?: boolean | undefined, tunable?: boolean | undefined, modelType?: string | undefined, supportsFireattention?: boolean | undefined, defaultPrecision?: DeploymentPrecision | undefined, supportsMtp?: boolean | undefined}; export type GatewayPEFTDetails = {baseModel: string, r: number, targetModules: Array, baseModelType?: string | undefined, mergeAddonModelName?: string | undefined}; export type GatewayTEFTDetails = Record; export type GatewayConversationConfig = {style: string, system?: string | undefined, template?: string | undefined}; export type GatewayDeployedModelState = 'STATE_UNSPECIFIED' | 'UNDEPLOYING' | 'DEPLOYING' | 'DEPLOYED' | 'UPDATING'; export type GatewayDeployedModelRef = {name?: string | undefined, deployment?: string | undefined, state?: GatewayDeployedModelState | undefined, default?: boolean | undefined, public?: boolean | undefined}; export type TypeDate = {year?: number | undefined, month?: number | undefined, day?: number | undefined}; export type ModelSnapshotType = 'FULL_SNAPSHOT' | 'INCREMENTAL_SNAPSHOT'; export type GatewayEncryptionState = 'ENCRYPTION_STATE_UNSPECIFIED' | 'ENCRYPTION_STATE_PLAINTEXT' | 'ENCRYPTION_STATE_CMEK'; export type TypeMoney = {currencyCode?: string | undefined, units?: unknown | undefined, nanos?: number | undefined}; export type GatewaySKUInfo = {sku?: string | undefined, amount?: TypeMoney | undefined, unit?: string | undefined}; export type GatewayServerlessMode = {name?: string | undefined, usageIdentifier?: string | undefined, serviceTier?: string | undefined, skuInfos?: Array | undefined, useCases?: Array | undefined, updatedBy?: string | undefined, createTime?: string | undefined, updateTime?: string | undefined}; export type GatewayModel = {name?: string | undefined, displayName?: string | undefined, description?: string | undefined, createTime?: string | undefined, state?: GatewayModelState | undefined, status?: GatewayStatus | undefined, kind?: ModelKind | undefined, githubUrl?: string | undefined, huggingFaceUrl?: string | undefined, baseModelDetails?: GatewayBaseModelDetails | undefined, peftDetails?: GatewayPEFTDetails | undefined, teftDetails?: GatewayTEFTDetails | undefined, public?: boolean | undefined, conversationConfig?: GatewayConversationConfig | undefined, contextLength?: number | undefined, supportsImageInput?: boolean | undefined, supportsTools?: boolean | undefined, importedFrom?: string | undefined, fineTuningJob?: string | undefined, defaultDraftModel?: string | undefined, defaultDraftTokenCount?: number | undefined, deployedModelRefs?: Array | undefined, cluster?: string | undefined, deprecationDate?: TypeDate | undefined, calibrated?: boolean | undefined, tunable?: boolean | undefined, supportsLora?: boolean | undefined, useHfApplyChatTemplate?: boolean | undefined, updateTime?: string | undefined, defaultSamplingParams?: {[key: string]: number} | undefined, rlTunable?: boolean | undefined, trainingContextLength?: number | undefined, snapshotType?: ModelSnapshotType | undefined, supportsServerless?: boolean | undefined, useTrainingV2?: boolean | undefined, supervisedLoraTunable?: boolean | undefined, supervisedFullParameterTunable?: boolean | undefined, rlLoraTunable?: boolean | undefined, rlFullParameterTunable?: boolean | undefined, encryptionState?: GatewayEncryptionState | undefined, serverlessModes?: Array | undefined}; export type GatewayGatewayCreateModelBody = {model?: GatewayModel | undefined, modelId: string, cluster?: string | undefined}; export type CreateApiV1AccountsAccountIdModelsArgs = {account_id: string, body: GatewayGatewayCreateModelBody}; export type CreateApiV1AccountsAccountIdModelsOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const gatewayModelState = z.enum(["STATE_UNSPECIFIED", "UPLOADING", "READY"]); 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 modelKind = z.enum(["KIND_UNSPECIFIED", "HF_BASE_MODEL", "HF_PEFT_ADDON", "HF_TEFT_ADDON", "FLUMINA_BASE_MODEL", "FLUMINA_ADDON", "DRAFT_ADDON", "LIVE_MERGE", "CUSTOM_MODEL", "EMBEDDING_MODEL", "SNAPSHOT_MODEL"]); export const baseModelDetailsCheckpointFormat = z.enum(["CHECKPOINT_FORMAT_UNSPECIFIED", "NATIVE", "HUGGINGFACE", "UNINITIALIZED"]); 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 gatewayBaseModelDetails = z.object({worldSize: z.number().int().optional(), checkpointFormat: baseModelDetailsCheckpointFormat.optional(), huggingfaceFiles: z.array(z.string()).optional(), parameterCount: z.string().optional(), moe: z.boolean().optional(), tunable: z.boolean().optional(), modelType: z.string().optional(), supportsFireattention: z.boolean().optional(), defaultPrecision: deploymentPrecision.optional(), supportsMtp: z.boolean().optional()}); export const gatewayPEFTDetails = z.object({baseModel: z.string(), r: z.number().int(), targetModules: z.array(z.string()), baseModelType: z.string().optional(), mergeAddonModelName: z.string().optional()}); export const gatewayTEFTDetails = z.object({}); export const gatewayConversationConfig = z.object({style: z.string(), system: z.string().optional(), template: z.string().optional()}); export const gatewayDeployedModelState = z.enum(["STATE_UNSPECIFIED", "UNDEPLOYING", "DEPLOYING", "DEPLOYED", "UPDATING"]); export const gatewayDeployedModelRef = z.object({name: z.string().optional(), deployment: z.string().optional(), state: gatewayDeployedModelState.optional(), default: z.boolean().optional(), public: z.boolean().optional()}); export const typeDate = z.object({year: z.number().int().optional(), month: z.number().int().optional(), day: z.number().int().optional()}); export const modelSnapshotType = z.enum(["FULL_SNAPSHOT", "INCREMENTAL_SNAPSHOT"]); export const gatewayEncryptionState = z.enum(["ENCRYPTION_STATE_UNSPECIFIED", "ENCRYPTION_STATE_PLAINTEXT", "ENCRYPTION_STATE_CMEK"]); export const typeMoney = z.object({currencyCode: z.string().optional(), units: z.string().optional(), nanos: z.number().int().optional()}); export const gatewaySKUInfo = z.object({sku: z.string().optional(), amount: typeMoney.optional(), unit: z.string().optional()}); export const gatewayServerlessMode = z.object({name: z.string().optional(), usageIdentifier: z.string().optional(), serviceTier: z.string().optional(), skuInfos: z.array(gatewaySKUInfo).optional(), useCases: z.array(z.string()).optional(), updatedBy: z.string().optional(), createTime: z.string().optional(), updateTime: z.string().optional()}); export const gatewayModel = z.object({name: z.string().optional(), displayName: z.string().optional(), description: z.string().optional(), createTime: z.string().optional(), state: gatewayModelState.optional(), status: gatewayStatus.optional(), kind: modelKind.optional(), githubUrl: z.string().optional(), huggingFaceUrl: z.string().optional(), baseModelDetails: gatewayBaseModelDetails.optional(), peftDetails: gatewayPEFTDetails.optional(), teftDetails: gatewayTEFTDetails.optional(), public: z.boolean().optional(), conversationConfig: gatewayConversationConfig.optional(), contextLength: z.number().int().optional(), supportsImageInput: z.boolean().optional(), supportsTools: z.boolean().optional(), importedFrom: z.string().optional(), fineTuningJob: z.string().optional(), defaultDraftModel: z.string().optional(), defaultDraftTokenCount: z.number().int().optional(), deployedModelRefs: z.array(gatewayDeployedModelRef).optional(), cluster: z.string().optional(), deprecationDate: typeDate.optional(), calibrated: z.boolean().optional(), tunable: z.boolean().optional(), supportsLora: z.boolean().optional(), useHfApplyChatTemplate: z.boolean().optional(), updateTime: z.string().optional(), defaultSamplingParams: z.record(z.string(), z.number()).optional(), rlTunable: z.boolean().optional(), trainingContextLength: z.number().int().optional(), snapshotType: modelSnapshotType.optional(), supportsServerless: z.boolean().optional(), useTrainingV2: z.boolean().optional(), supervisedLoraTunable: z.boolean().optional(), supervisedFullParameterTunable: z.boolean().optional(), rlLoraTunable: z.boolean().optional(), rlFullParameterTunable: z.boolean().optional(), encryptionState: gatewayEncryptionState.optional(), serverlessModes: z.array(gatewayServerlessMode).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 Model * * POST /v1/accounts/{account_id}/models */ export const createApiV1AccountsAccountIdModels = async (args: CreateApiV1AccountsAccountIdModelsArgs, options: CreateApiV1AccountsAccountIdModelsOptions) => { 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${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(gatewayModel, await res.json()) };