import {z} from 'zod' export type GithubComBaselinehqGolangSharedTypesProvider = 'GCP' | 'AWS' | 'DigitalOcean' | 'Azure' | 'Hetzner' | 'OVHCloud' | 'PlanetScale' | 'STACKIT' | 'Linode' | 'Base' | 'Akash' | 'Alibaba' | 'Baseten' | 'Beam' | 'Cerebrium' | 'CIRunners' | 'Civo' | 'Clore' | 'CoreWeave' | 'Crusoe' | 'CUDO' | 'DataCrunch' | 'DeepInfra' | 'Denvr' | 'E2ENetworks' | 'Exoscale' | 'Fal' | 'HotAisle' | 'Hyperbolic' | 'Hyperstack' | 'IBM' | 'Lambda' | 'Latitude' | 'MassedCompute' | 'Modal' | 'Nebius' | 'Novita' | 'Oblivus' | 'OCI' | 'OpenTelekom' | 'PrimeIntellect' | 'Replicate' | 'RunPod' | 'Salad' | 'Scaleway' | 'Sesterce' | 'Shadeform' | 'ThunderCompute' | 'UpCloud' | 'Vast' | 'Vultr'; export type TypesService = 'ComputeEngine' | 'AmazonEC2' | 'Droplet' | 'AzureCompute' | 'AzureManagedDisks' | 'HetznerCompute' | 'OVHPublicCloud' | 'BaseCompute' | 'BaseDisks' | 'AmazonEBS' | 'AmazonRDS' | 'AuroraDSQL' | 'CloudSQL' | 'AlloyDB' | 'CloudSpanner' | 'AzureDatabaseForPostgreSQL' | 'AzureDatabaseForMySQL' | 'AzureSQLDatabase' | 'AzureSQLManagedInstance' | 'PlanetScale' | 'ComputeEnginePersistentDisk' | 'STACKITCompute' | 'STACKITBlockStorage' | 'STACKITDatabase' | 'AkamaiLinode' | 'AkamaiBlockStorage' | 'AkamaiDatabase' | 'AkashCompute' | 'AlibabaCompute' | 'AlibabaBlockStorage' | 'BasetenCompute' | 'BeamCompute' | 'CerebriumCompute' | 'CivoCompute' | 'CivoBlockStorage' | 'CloreCompute' | 'CoreWeaveCompute' | 'CrusoeCompute' | 'CUDOCompute' | 'DataCrunchCompute' | 'DeepInfraCompute' | 'DenvrCompute' | 'E2ENetworksCompute' | 'ExoscaleCompute' | 'ExoscaleBlockStorage' | 'FalCompute' | 'HotAisleCompute' | 'HyperbolicCompute' | 'HyperstackCompute' | 'IBMCompute' | 'IBMBlockStorage' | 'LambdaCompute' | 'LatitudeCompute' | 'MassedComputeCompute' | 'ModalCompute' | 'NebiusCompute' | 'NovitaCompute' | 'OblivusCompute' | 'OCICompute' | 'OCIBlockStorage' | 'OpenTelekomCompute' | 'PrimeIntellectCompute' | 'ReplicateCompute' | 'RunPodCompute' | 'SaladCompute' | 'ScalewayCompute' | 'ScalewayBlockStorage' | 'SesterceCompute' | 'ShadeformCompute' | 'ThunderComputeCompute' | 'UpCloudCompute' | 'UpCloudBlockStorage' | 'VastCompute' | 'VultrCompute' | 'VultrBlockStorage'; export type GithubComBaselinehqGolangSharedTypesUsageType = 'SPOT_PREEMPTIBLE' | 'ONDEMAND' | 'RESERVED' | 'ONDEMAND_CUSTOM' | 'SPOT_PREEMPTIBLE_CUSTOM' | 'RESERVED_CUSTOM' | 'SOLE_TENANCY' | 'CUSTOM' | 'EXTENDED'; export type GithubComBaselinehqGolangSharedTypesVM = {cpu_cores?: number | undefined, ram_gb?: number | undefined}; export type GithubComBaselinehqGolangSharedTypesInstance = {availability_zone?: string | undefined, fallback_to_base_pricing?: boolean | undefined, id?: string | undefined, instance_type?: string | undefined, operating_system?: string | undefined, provider?: GithubComBaselinehqGolangSharedTypesProvider | undefined, region?: string | undefined, service?: TypesService | undefined, usage_type?: GithubComBaselinehqGolangSharedTypesUsageType | undefined, vm?: GithubComBaselinehqGolangSharedTypesVM | undefined}; export type TypesPredicates = {availability_zones?: Array | undefined, disk_types?: Array | undefined, instance_types?: Array | undefined, operating_systems?: Array | undefined, providers?: Array | undefined, regions?: Array | undefined, services?: Array | undefined, usage_types?: Array | undefined}; export type ComputeRecommendationRequest = {include_metadata?: boolean | undefined, instance?: GithubComBaselinehqGolangSharedTypesInstance | undefined, predicates?: TypesPredicates | undefined, usage?: GithubComBaselinehqGolangSharedTypesVM | undefined, workload_class?: string | undefined}; export type CreateApiV1RecommendationsComputeArgs = {body: ComputeRecommendationRequest}; export type CreateApiV1RecommendationsComputeOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const computePrice = z.object({architecture: z.string().optional(), availability_zone: z.string().optional(), cost_per_hour: z.number().optional(), cpu_cores: z.number().optional(), cpu_cores_cost_per_hour: z.number().optional(), created_at: z.string().optional(), currency: z.string().optional(), gpu_cost_per_hour: z.number().optional(), gpu_count: z.number().optional(), gpu_type: z.string().optional(), id: z.string().optional(), instance_type: z.string().optional(), native_cost_per_hour: z.number().optional(), operating_system: z.string().optional(), period_billing_hours: z.number().optional(), provider: z.string().optional(), ram_gb: z.number().optional(), ram_gb_cost_per_hour: z.number().optional(), raw_pricing_data: z.object({}).optional(), region: z.string().optional(), resizable: z.boolean().optional(), service: z.string().optional(), tags: z.object({}).optional(), updated_at: z.string().optional(), usage_type: z.string().optional()}); export const typesSavings = z.object({amount_per_hour: z.number().optional(), amount_per_month: z.number().optional(), amount_per_year: z.number().optional(), percentage: z.number().optional()}); export const computeRecommendation = z.object({cost_per_work_unit: z.number().optional(), cpu_class: z.string().optional(), pricing: computePrice.optional(), savings: typesSavings.optional(), work_unit: z.string().optional()}); export const createApiV1RecommendationsComputeResponse = z.array(computeRecommendation); 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 }; /** * Find cheaper machines * * POST /v1/recommendations/compute * * Also accepts auth: BearerAuth */ export const createApiV1RecommendationsCompute = async (args: CreateApiV1RecommendationsComputeArgs, options?: CreateApiV1RecommendationsComputeOptions) => { const {baseUrl = "https://pricing.baselinehq.cloud", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/recommendations/compute${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(createApiV1RecommendationsComputeResponse, await res.json()) };