Installation
Overview
The@ai-billing/deepseek package provides middleware for tracking token usage and calculating costs when using DeepSeek models with the Vercel AI SDK.
It captures DeepSeek-specific metrics, such as inputCacheReadTokens, ensuring that Prompt Caching costs are accurately reflected.
Usage
To use the middleware, wrap your DeepSeek model usingwrapLanguageModel from the ai package and pass the createDeepSeekMiddleware.
Define model pricing
Set up a price resolver to define the costs for the models you’ll be using. For DeepSeek, you can specify costs for both standard prompt/completion tokens and cached tokens (
inputCacheReadTokens).Create the billing middleware
Initialize the DeepSeek 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 DeepSeek model.