Installation
Overview
The@ai-billing/groq package provides middleware for tracking token usage and calculating costs when using Groq models with the Vercel AI SDK.
Usage
To use the middleware, wrap your Groq model usingwrapLanguageModel from the ai package and pass the createGroqMiddleware.
Define model pricing
Set up a price resolver to define the costs for the models you’ll be using. You can use either the dynamic Narev price resolver or a manual object price resolver.
- Using Narev Pricing (Recommended)
- Using Manual Pricing
The Narev price resolver automatically fetches the latest pricing for Groq models.
Create the billing middleware
Initialize the Groq 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 Groq model.