import {z} from 'zod' export type GetApiV1alpha1InferenceDeploymentsParametersArgs = {gatewayIds?: Array | undefined}; export type GetApiV1alpha1InferenceDeploymentsParametersOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const deploymentRuntimeParametersRuntimeVersions = z.object({versions: z.array(z.string()).optional()}); export const deploymentRuntimeParametersRuntimeConfigOptions = z.object({allowedKeys: z.array(z.string()).optional()}); export const deploymentRuntimeParametersEngineEnvOptions = z.object({allowedNames: z.array(z.string()).optional()}); export const deploymentRuntimeParameters = z.object({runtimeVersions: z.record(z.string(), deploymentRuntimeParametersRuntimeVersions).optional(), runtimeConfigOptions: z.record(z.string(), deploymentRuntimeParametersRuntimeConfigOptions).optional(), engineEnvOptions: z.record(z.string(), deploymentRuntimeParametersEngineEnvOptions).optional()}); export const deploymentResourceParameters = z.object({instanceTypes: z.array(z.string()).optional()}); export const getDeploymentParametersResponse = z.object({gatewayIds: z.array(z.string()), runtimeParameters: deploymentRuntimeParameters.optional(), resourceParameters: deploymentResourceParameters.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 parameters * * GET /v1alpha1/inference/deployments/parameters */ export const getApiV1alpha1InferenceDeploymentsParameters = async (args: GetApiV1alpha1InferenceDeploymentsParametersArgs, options?: GetApiV1alpha1InferenceDeploymentsParametersOptions) => { const {baseUrl = "https://api.coreweave.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.gatewayIds ?? []) query.append("gatewayIds", String(item)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1alpha1/inference/deployments/parameters${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(getDeploymentParametersResponse, await res.json()) };