Installation
Overview
The@ai-billing/minimax package provides middleware for tracking token usage and calculating costs when using Minimax models with the Vercel AI SDK.
It captures Minimax-specific metrics, such as internalReasoningTokens, ensuring that reasoning costs are accurately reflected.
Usage
To use the middleware, wrap your Minimax model (which is accessed via the Anthropic provider) usingwrapLanguageModel from the ai package and pass the createMinimaxMiddleware.
Initialize the Minimax provider
First, set up the provider using the Anthropic SDK with the Minimax base URL and your API key.
Define model pricing
Set up a price resolver to define the costs for the models you’ll be using. For Minimax, you can specify costs for standard prompt/completion tokens and reasoning tokens (
internalReasoningTokens).Create the billing middleware
Initialize the Minimax billing middleware. You need to provide a destination (such as
consoleDestination) where billing events will be sent, along with your priceResolver.Wrap the model
Use
wrapLanguageModel from the ai package to apply the billing middleware to your Minimax model.