> ## Documentation Index
> Fetch the complete documentation index at: https://narev.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# CreateCohereV3Middleware

[**@ai-billing/cohere**](../index)

***

[@ai-billing/cohere](/docs/sdk/ai-billing/reference/cohere/typedoc/index) / createCohereV3Middleware

# Function: createCohereV3Middleware()

> **createCohereV3Middleware**\<`TTags`>(`options`): `LanguageModelV3Middleware`

Defined in: [cohere/src/ai-sdk/language-model-middleware/v3/language-model-v3-cohere-billing-middleware.ts:107](https://github.com/narevai/ai-billing/blob/main/packages/cohere/src/ai-sdk/language-model-middleware/v3/language-model-v3-cohere-billing-middleware.ts#L107)

Creates a V3 billing middleware for the Cohere provider (`@ai-sdk/cohere`).

Bills off `billed_units.input_tokens`/`billed_units.output_tokens` (falling back to `tokens.input_tokens`/
`tokens.output_tokens` only when `billed_units` is entirely absent from the payload) — **not** the raw
`tokens.*` totals — since Cohere only charges for `billed_units`. `cached_tokens` is surfaced on the
emitted event's `usage.cacheReadTokens` for observability, but is not subtracted from the billed prompt
total (unlike Mistral) because `billed_units` already nets out cache hits in a way that isn't
reproducible by subtracting `cached_tokens` from `tokens.input_tokens`. As a result, `usage.inputTokens`/
`usage.outputTokens` on the emitted BillingEvent reflect Cohere's *billed* token counts, which
can be substantially smaller than the AI SDK's own normalized `inputTokens`/`outputTokens` totals when a
request hits Cohere's inference cache.

## Type Parameters

### TTags

`TTags` *extends* `JSONObject`

The shape of the tags object, extending DefaultTags.

## Parameters

### options

[`CohereV3MiddlewareOptions`](/docs/sdk/ai-billing/reference/cohere/typedoc/interfaces/CohereV3MiddlewareOptions)\<`TTags`>

Billing options; see [CohereV3MiddlewareOptions](/docs/sdk/ai-billing/reference/cohere/typedoc/interfaces/CohereV3MiddlewareOptions). A `priceResolver` is required.

## Returns

`LanguageModelV3Middleware`

A V3 billing middleware instance for Cohere.

## Example

```ts theme={null}
import { createCohere } from '@ai-sdk/cohere';
import { wrapLanguageModel } from 'ai';
import { createCohereV3Middleware } from '@ai-billing/cohere';
import {
  consoleDestination,
  createObjectPriceResolver,
  type ModelPricing,
} from '@ai-billing/core';

const cohere = createCohere({ apiKey: process.env.COHERE_API_KEY });

const customPricingMap: Record<string, ModelPricing> = {
  'command-r-08-2024': {
    promptTokens: 0.15 / 1_000_000,
    completionTokens: 0.6 / 1_000_000,
  },
};

const priceResolver = createObjectPriceResolver(customPricingMap);

const billingMiddleware = createCohereV3Middleware({
  destinations: [consoleDestination()],
  priceResolver,
});

const wrappedModel = wrapLanguageModel({
  model: cohere('command-r-08-2024'),
  middleware: billingMiddleware,
});
```
