import {z} from 'zod' export type GetApiProjectsProjectIdFoundryDeployedModelsArgs = {project_id: string}; export type GetApiProjectsProjectIdFoundryDeployedModelsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const foundryArchitecture = z.object({instruct_type: z.string().optional(), modality: z.string().optional(), parameter_count: z.number().int().optional(), tokenizer: z.string().optional()}); export const deployedModelEntry = z.object({architecture: foundryArchitecture.optional(), context_length: z.number().int().optional(), description: z.string().optional(), icon: z.string().optional(), id: z.string().optional(), is_available_to_rolling_deployment: z.boolean().optional(), is_billed_by_token: z.boolean().optional(), is_single_replica: z.boolean().optional(), model_name: z.string().optional(), name: z.string().optional(), owned_by: z.string().optional(), quantization: z.string().optional(), region: z.string().optional(), status: z.string().optional(), supported_parameters: z.array(z.string()).optional(), tags: z.array(z.string()).optional(), type: z.string().optional()}); export const listModelsResponse = z.object({deployments: z.array(deployedModelEntry).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 }; /** * Lists the models deployed and available for inference in the project. * * GET /projects/{project_id}/foundry/deployed-models */ export const getApiProjectsProjectIdFoundryDeployedModels = async (args: GetApiProjectsProjectIdFoundryDeployedModelsArgs, options?: GetApiProjectsProjectIdFoundryDeployedModelsOptions) => { const {baseUrl = "https://api.cloud.crusoe.ai/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/projects/${encodeURIComponent(String(args.project_id))}/foundry/deployed-models${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(listModelsResponse, await res.json()) };