import {z} from 'zod' export type ListLLMCostPricesParamsFilter = {provider?: ({eq?: string | undefined, contains: string, ocontains: string, oeq: string, neq: string}) | undefined, model_id?: ({eq?: string | undefined, contains: string, ocontains: string, oeq: string, neq: string}) | undefined, model_name?: ({eq?: string | undefined, contains: string, ocontains: string, oeq: string, neq: string}) | undefined, currency?: ({eq?: string | undefined, contains: string, ocontains: string, oeq: string, neq: string}) | undefined, source?: ({eq?: string | undefined, contains: string, ocontains: string, oeq: string, neq: string}) | undefined}; export type GetApiV3OpenmeterLlmCostOverridesArgs = {filter?: ListLLMCostPricesParamsFilter | undefined, page?: ({size?: number | undefined, number?: number | undefined}) | undefined}; export type GetApiV3OpenmeterLlmCostOverridesOptions = {baseUrl?: string | undefined, personalAccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const lLMCostPrice = z.object({id: z.string(), provider: z.object({id: z.string(), name: z.string()}), model: z.object({id: z.string(), name: z.string()}), pricing: z.object({input_per_token: z.string(), output_per_token: z.string(), cache_read_per_token: z.string().optional(), cache_write_per_token: z.string().optional(), reasoning_per_token: z.string().optional()}), currency: z.string().min(3).max(3), source: z.enum(["manual", "system"]), effective_from: z.string(), effective_to: z.string().optional(), created_at: z.string(), updated_at: z.string()}); export const pageMeta = z.object({number: z.number(), size: z.number(), total: z.number()}); export const paginatedMeta = z.object({page: pageMeta}); export const pricePagePaginatedResponse = z.object({data: z.array(lLMCostPrice), meta: paginatedMeta}); 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 }; /** * List LLM cost overrides * * GET /v3/openmeter/llm-cost/overrides * * Also accepts auth: systemAccountAccessToken, konnectAccessToken, serviceAccessToken */ export const getApiV3OpenmeterLlmCostOverrides = async (args: GetApiV3OpenmeterLlmCostOverridesArgs, options?: GetApiV3OpenmeterLlmCostOverridesOptions) => { const {baseUrl = "https://global.api.konghq.com", fetch: fetchFn = fetch, personalAccessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.filter != null) query.append("filter", JSON.stringify(args.filter)) if (args.page != null) query.append("page", JSON.stringify(args.page)) if (personalAccessToken !== undefined) headers.set('authorization', `Bearer ${personalAccessToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/openmeter/llm-cost/overrides${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(pricePagePaginatedResponse, await res.json()) };