import {z} from 'zod' export type GetApiV1BillingSubscriptionsPlansOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const featuresForSubscriptionDescriptions = z.object({max_tokens_readable: z.string(), max_apps_readable: z.string(), support_level_readable: z.string(), llm_routing: z.string(), prompts: z.string(), prompt_models: z.string(), personalized_llm_routing: z.string(), fine_tuning: z.string(), customer_success: z.string()}); export const subscriptionSettings = z.object({max_tokens: z.number().int().gt(0), max_apps: z.number().int(), llm_routing: z.boolean().optional(), prompts: z.boolean(), prompt_models: z.boolean(), personalized_llm_routing: z.boolean(), fine_tuning: z.boolean(), support_level: z.enum(["community", "all"]), customer_success: z.boolean(), max_tokens_readable: z.string(), max_apps_readable: z.string(), support_level_readable: z.string(), is_trial: z.boolean().optional(), is_none: z.boolean().optional(), tier: z.enum(["_NONE_", "_TRIAL_", "_INTERNAL_", "STARTUP", "GROWTH", "SCALE", "ENTERPRISE"]), name: z.string(), monthly_price_usd: z.number().nullable(), yearly_price_usd: z.number().nullable(), monthly_discounted_usd: z.number().nullable().optional(), yearly_discounted_usd: z.number().nullable().optional(), monthly_price_id: z.string().nullable(), yearly_price_id: z.string().nullable(), monthly_price_label: z.string().nullable().optional(), yearly_price_label: z.string().nullable().optional(), monthly_contact_sales: z.boolean().optional(), yearly_contact_sales: z.boolean().optional(), monthly_button_label: z.string().nullable().optional(), yearly_button_label: z.string().nullable().optional()}); export const subscriptionPricingTable = z.object({descriptions: featuresForSubscriptionDescriptions, tooltips: featuresForSubscriptionDescriptions, table: z.record(z.string(), subscriptionSettings), subscription_price_id: z.string().nullable()}); 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 }; /** * Get Subscription Tiers Table * * GET /v1/billing/subscriptions/plans */ export const getApiV1BillingSubscriptionsPlans = async (options: GetApiV1BillingSubscriptionsPlansOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/billing/subscriptions/plans${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(subscriptionPricingTable, await res.json()) };