Skip to main content
@ai-billing/moonshotai
@ai-billing/moonshotai / createMoonshotaiV3Middleware

Function: createMoonshotaiV3Middleware()

createMoonshotaiV3Middleware<TTags>(options): LanguageModelV3Middleware
Defined in: moonshotai/src/ai-sdk/language-model-middleware/v3/language-model-v3-moonshotai-billing-middleware.ts:96 Creates a V3 billing middleware for the Moonshot AI provider (@ai-sdk/moonshotai). Moonshot AI’s chat-completions usage payload is OpenAI-compatible. Reasoning models (e.g. kimi-k3) report completion_tokens_details.reasoning_tokens as a subset of completion_tokens, so this middleware subtracts reasoning tokens out of completion_tokens before billing them as completionTokens, and bills the reasoning tokens separately as reasoningTokens — avoiding double-counting reasoning cost.

Type Parameters

TTags

TTags extends JSONObject The shape of the tags object, extending DefaultTags.

Parameters

options

MoonshotaiV3MiddlewareOptions<TTags> Billing options; see MoonshotaiV3MiddlewareOptions. A priceResolver is required.

Returns

LanguageModelV3Middleware A V3 billing middleware instance for Moonshot AI.

Example