import {z} from 'zod' export type GetApiV1AccountsAccountIdPricingPlansPricingPlanIdArgs = {readMask?: string | undefined, account_id: string, pricing_plan_id: string}; export type GetApiV1AccountsAccountIdPricingPlansPricingPlanIdOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const pricingPlanBillingType = z.enum(["BILLING_TYPE_UNSPECIFIED", "TOKEN_USAGE", "ACCELERATOR_HOURS"]); export const typeMoney = z.object({currencyCode: z.string().optional(), units: z.string().optional(), nanos: z.number().int().optional()}); export const pricingPlanTokenBillingConfig = z.object({baseModelName: z.string(), inputTokenPricePerMillion: typeMoney.optional(), outputTokenPricePerMillion: typeMoney, uncachedInputTokenPricePerMillion: typeMoney.optional(), cachedInputTokenPricePerMillion: typeMoney.optional()}); export const gatewayAcceleratorType = z.enum(["ACCELERATOR_TYPE_UNSPECIFIED", "NVIDIA_A100_80GB", "NVIDIA_H100_80GB", "AMD_MI300X_192GB", "NVIDIA_A10G_24GB", "NVIDIA_A100_40GB", "NVIDIA_L4_24GB", "NVIDIA_H200_141GB", "NVIDIA_B200_180GB", "AMD_MI325X_256GB", "AMD_MI350X_288GB", "NVIDIA_B300_288GB", "NVIDIA_GB200", "NVIDIA_GB300"]); export const pricingPlanAcceleratorHourBillingConfig = z.object({acceleratorType: gatewayAcceleratorType, acceleratorHourPrice: typeMoney}); export const gatewayPricingPlanState = z.enum(["STATE_UNSPECIFIED", "CREATING", "READY"]); export const gatewayPricingPlan = z.object({name: z.string().optional(), billingType: pricingPlanBillingType, tokenConfig: z.array(pricingPlanTokenBillingConfig).optional(), acceleratorHourConfig: z.array(pricingPlanAcceleratorHourBillingConfig).optional(), startTime: z.string(), endTime: z.string().optional(), createTime: z.string().optional(), updateTime: z.string().optional(), state: gatewayPricingPlanState.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 }; /** * CRUD APIs for pricing plans. * Get Pricing Plan * * GET /v1/accounts/{account_id}/pricingPlans/{pricing_plan_id} */ export const getApiV1AccountsAccountIdPricingPlansPricingPlanId = async (args: GetApiV1AccountsAccountIdPricingPlansPricingPlanIdArgs, options: GetApiV1AccountsAccountIdPricingPlansPricingPlanIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.readMask != null) query.append("readMask", String(args.readMask)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/accounts/${encodeURIComponent(String(args.account_id))}/pricingPlans/${encodeURIComponent(String(args.pricing_plan_id))}${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(gatewayPricingPlan, await res.json()) };