Skip to main content
@ai-billing/xai
@ai-billing/xai / createXaiV4Middleware

Function: createXaiV4Middleware()

createXaiV4Middleware<TTags>(options): LanguageModelV4Middleware
Defined in: xai/src/ai-sdk/language-model-middleware/v4/language-model-v4-xai-billing-middleware.ts:98 Creates a V4 billing middleware for the xAI provider (@ai-sdk/xai). Deducts cache-read tokens from prompt tokens before billing — xAI charges only non-cached input at the prompt rate, and cached tokens separately at the cache-read rate.

Type Parameters

TTags

TTags extends JSONObject The shape of the tags object, extending DefaultTags.

Parameters

options

XaiV4MiddlewareOptions<TTags> Billing options; see XaiV4MiddlewareOptions. A priceResolver is required.

Returns

LanguageModelV4Middleware A V4 billing middleware instance for xAI.

Example