import {z} from 'zod' export type DatatypesJSON = Record; export type ModelPrice = {context_limit?: number | undefined, currency?: string | undefined, effective_from?: string | undefined, effective_to?: string | undefined, fetched_at?: string | undefined, host?: string | undefined, id?: string | undefined, modalities_input?: Array | undefined, modalities_output?: Array | undefined, model?: string | undefined, model_id?: string | undefined, open_weights?: boolean | undefined, output_limit?: number | undefined, provider?: string | undefined, publisher?: string | undefined, raw_pricing_data?: DatatypesJSON | undefined, reasoning?: boolean | undefined, region?: string | undefined, sku_price_id?: string | undefined, source?: string | undefined, source_url?: string | undefined, structured_output?: boolean | undefined, tags?: DatatypesJSON | undefined, token_bucket?: ('input' | 'output' | 'cache_read' | 'cache_write') | undefined, tool_call?: boolean | undefined, unit_price_per_mtok?: number | undefined}; export type ModelPricesRequest = {entries: Array}; export type CreateApiMarketplaceProvidersModelsArgs = {body: ModelPricesRequest}; export type CreateApiMarketplaceProvidersModelsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const datatypesJSON = z.object({}); export const modelPrice = z.object({context_limit: z.number().int().optional(), currency: z.string().optional(), effective_from: z.string().optional(), effective_to: z.string().optional(), fetched_at: z.string().optional(), host: z.string().optional(), id: z.string().optional(), modalities_input: z.array(z.string()).optional(), modalities_output: z.array(z.string()).optional(), model: z.string().optional(), model_id: z.string().optional(), open_weights: z.boolean().optional(), output_limit: z.number().int().optional(), provider: z.string().optional(), publisher: z.string().optional(), raw_pricing_data: datatypesJSON.optional(), reasoning: z.boolean().optional(), region: z.string().optional(), sku_price_id: z.string().optional(), source: z.string().optional(), source_url: z.string().optional(), structured_output: z.boolean().optional(), tags: datatypesJSON.optional(), token_bucket: z.enum(["input", "output", "cache_read", "cache_write"]).optional(), tool_call: z.boolean().optional(), unit_price_per_mtok: z.number().optional()}); export const registrationStatus = z.enum(["Registered", "Deleted"]); export const registeredModelPrices = z.object({entries: z.array(modelPrice).optional(), status: registrationStatus.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 }; /** * Register custom model pricing * * POST /marketplace/providers/models * * Also accepts auth: BearerAuth */ export const createApiMarketplaceProvidersModels = async (args: CreateApiMarketplaceProvidersModelsArgs, options?: CreateApiMarketplaceProvidersModelsOptions) => { 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(/\/+$/, '')}/marketplace/providers/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(registeredModelPrices, await res.json()) };