@ai-billing/moonshotai / createMoonshotaiV4Middleware
Function: createMoonshotaiV4Middleware()
createMoonshotaiV4Middleware<Defined in: moonshotai/src/ai-sdk/language-model-middleware/v4/language-model-v4-moonshotai-billing-middleware.ts:96 Creates a V4 billing middleware for the Moonshot AI provider (TTags>(options):LanguageModelV4Middleware
@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
MoonshotaiV4MiddlewareOptions<TTags>
Billing options; see MoonshotaiV4MiddlewareOptions. A priceResolver is required.
Returns
LanguageModelV4Middleware
A V4 billing middleware instance for Moonshot AI.