Before you start
You need a server-side TypeScript app, a DeepSeek API key, and access to the model you select. Keep the key inDEEPSEEK_API_KEY on the server. The example below targets AI SDK 6 and its V3 language-model interface; the V3 middleware suffix refers to that interface, not to the DeepSeek model generation.
Install a compatible set of dependencies. The Narev DeepSeek package also provides V4 middleware for the AI SDK 7 interface; use the version that matches your model rather than mixing the two.
Configure the model and price resolver
Createdeepseek-billing.ts on the server. Supply DEEPSEEK_MODEL_ID and the three rate environment variables using USD per million tokens from your verified price lookup. The code validates these values and converts them to the USD-per-token units expected by ModelPricing. Explicit configuration avoids embedding an outdated price in a runnable example.
Using generateText
Import the wrapped model into your server handler. This small Next.js-style route makes one generation, waits for its result, and returns only the answer. Use it to verify the configuration with a bounded test request before adapting it to user-supplied messages.
Using streamText
Streaming uses the same wrapped model. Keep the response stream running to completion so the integration can receive final usage. In a Next.js-style route, return the stream response as shown below.
Verify cost before sending customer charges
If no event appears, confirm that the route importsbilledModel, the destination is configured, and the server receives provider usage. If an event lacks cost, check the exact model-map key and resolver configuration. An unexpectedly low or high total usually warrants checking rate units and the cached-token breakdown first.
Once the console result is correct, choose a billing destination and add Customer Tagging from authenticated server state. Follow its customer mapping and meter-unit requirements. Recording provider cost and charging a customer are separate steps; this console example performs only the first.