import * as _ai_sdk_provider from '@ai-sdk/provider'; import { DefaultTags, BaseBillingMiddlewareOptions, PriceResolver } from '@ai-billing/types'; /** * Configuration for {@link createOpenAIV4Middleware}. * * Extends {@link BaseBillingMiddlewareOptions} (`destinations`, `defaultTags`, `waitUntil`, `onError`) and * requires a {@link PriceResolver}. Usage is taken from the AI SDK's normalized OpenAI usage fields; cost is * computed from that usage and the resolved {@link ModelPricing} using the same rules as the package's cost * helper. * * @typeParam TTags - The shape of the tags object, extending {@link DefaultTags}. */ interface OpenAIV4MiddlewareOptions extends BaseBillingMiddlewareOptions { priceResolver: PriceResolver; } /** * Creates a V4 billing middleware for the OpenAI provider (`@ai-sdk/openai`). * Maps AI SDK usage into billing fields and resolves cost from pricing plus usage. * * @typeParam TTags - The shape of the tags object, extending {@link DefaultTags}. * @param options - Billing options; see {@link OpenAIV4MiddlewareOptions}. * @returns A V4 billing middleware instance for OpenAI. * * @example * Targets AI SDK v7 (`LanguageModelV4Middleware`). * * ```ts * import { createOpenAI } from '@ai-sdk/openai'; * import { wrapLanguageModel } from 'ai'; * import { createOpenAIV4Middleware } from '@ai-billing/openai'; * import { * consoleDestination, * createObjectPriceResolver, * type ModelPricing, * } from '@ai-billing/core'; * * const openai = createOpenAI({ apiKey: process.env.OPENAI_API_KEY }); * * const customPricingMap: Record = { * 'gpt-5': { * promptTokens: 1.25 / 1_000_000, * completionTokens: 10.0 / 1_000_000, * inputCacheReadTokens: 0.125 / 1_000_000, * }, * 'gpt-4o': { * promptTokens: 5.0 / 1_000_000, * completionTokens: 15.0 / 1_000_000, * }, * }; * * const priceResolver = createObjectPriceResolver(customPricingMap); * * const billingMiddleware = createOpenAIV4Middleware({ * destinations: [consoleDestination()], * priceResolver, * }); * * const wrappedModel = wrapLanguageModel({ * model: openai('gpt-5'), * middleware: billingMiddleware, * }); * ``` */ declare function createOpenAIV4Middleware(options: OpenAIV4MiddlewareOptions): _ai_sdk_provider.LanguageModelV4Middleware; export { type OpenAIV4MiddlewareOptions, createOpenAIV4Middleware };