Skip to main content
Use the Narev SDK when you want DeepSeek usage and cost recorded as part of an app call. The provider executes inference, the middleware reads its reported usage, a price resolver supplies rates, and a destination receives the calculated event. Start with a console destination so you can inspect the result before connecting customer billing.

Before you start

You need a server-side TypeScript app, a DeepSeek API key, and access to the model you select. Keep the key in DEEPSEEK_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.
Before setting rates, look up the direct DeepSeek model price. The object resolver below is a static map: it does not refresh itself from Narev Cloud. Store the lookup time with your configuration and update the values when the applicable price changes.

Configure the model and price resolver

Create deepseek-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.
The map key must exactly match the model you call. For direct DeepSeek V4 text pricing checked in the pricing guide, cache writes have no separate charge and reasoning is already part of completion usage. The explicit zero reasoning surcharge avoids charging those tokens again. Revisit those settings if you change the pricing contract or provider. The middleware reads raw DeepSeek usage, including cache hits, rather than estimating tokens from text. See the V3 middleware reference for the integration contract. Passing an unwrapped model bypasses this billing configuration.

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.
Inspect the server console for the billing event and compare its model, usage, and cost with the provider response. Use the same token totals in the Narev Cloud cost endpoint as a cross-check, accounting for any rate difference between your static map and the current catalog. A visible answer alone does not prove that a billing event was produced.

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 both a completed stream and your application’s cancellation path. Do not assume that a disconnected client yields the same usage evidence as a completed generation. Check the server’s event logs before using streaming totals for billing reconciliation.

Verify cost before sending customer charges

If no event appears, confirm that the route imports billedModel, 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.