import {z} from 'zod' export type GetApiV1PricingModelsArgs = {modelId?: string | undefined, planId?: string | undefined, page?: number | undefined, pageSize?: number | undefined}; export type GetApiV1PricingModelsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const pricingV1ModelPriceInfo = z.object({cachedInputPrice: z.string().optional(), currency: z.string().optional(), effectiveFrom: z.string().optional(), effectiveTo: z.string().optional(), id: z.string().optional(), inputPrice: z.string().optional(), internalCostInput: z.string().optional(), internalCostOutput: z.string().optional(), modelId: z.string().optional(), officialPriceCurrency: z.string().optional(), officialPriceUsd: z.string().optional(), outputPrice: z.string().optional(), perAudioSecondPrice: z.string().optional(), perImagePrice: z.string().optional(), perRequestPrice: z.string().optional(), perVideoSecondPrice: z.string().optional(), planId: z.string().optional(), version: z.number().int().optional()}); export const pricingV1ListModelPricesReply = z.object({prices: z.array(pricingV1ModelPriceInfo).optional(), total: z.number().int().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 }; /** * ListModelPrices 列出模型价格列表(支持按 model_id / plan_id 过滤)。 * * GET /v1/pricing/models */ export const getApiV1PricingModels = async (args: GetApiV1PricingModelsArgs, options: GetApiV1PricingModelsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.modelId != null) query.append("modelId", String(args.modelId)) if (args.planId != null) query.append("planId", String(args.planId)) if (args.page != null) query.append("page", String(args.page)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/pricing/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(pricingV1ListModelPricesReply, await res.json()) };