> This page is for NeMo Relay, version v0.10.0.
> For other versions, use one of these documentation indexes:
> - Latest (v0.10.0) (default): https://docs.nvidia.com/nemo/relay/latest/llms.txt
> - dev: https://docs.nvidia.com/nemo/relay/dev/llms.txt
> - v0.10.0: https://docs.nvidia.com/nemo/relay/v0.10.0/llms.txt
> - v0.9.4: https://docs.nvidia.com/nemo/relay/v0.9.4/llms.txt
> - v0.8.4: https://docs.nvidia.com/nemo/relay/v0.8.4/llms.txt
> - v0.7.3: https://docs.nvidia.com/nemo/relay/v0.7.3/llms.txt
> - v0.6.0: https://docs.nvidia.com/nemo/relay/v0.6.0/llms.txt
> - v0.5.0: https://docs.nvidia.com/nemo/relay/v0.5.0/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/relay/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/relay/_mcp/server.

# Trait LlmResponse Codec

> Decode-only codec for LLM API responses.

Generated from `cargo doc --no-deps -p nemo-relay -p nemo-relay-adaptive -p nemo-relay-pii-redaction -p nemo-relay-ffi -p nemo-relay-types -p nemo-relay-plugin -p nemo-relay-worker-proto -p nemo-relay-worker`.

<pre />

Decode-only codec for LLM API responses.

Unlike [`LlmCodec`](/reference/api/rust-library-reference/nemo-relay/codec/traits/trait-llmcodec) (which is bidirectional for requests), response codecs are introspection-only: they parse a raw response into structured form but never need to encode back. This matches the pipeline design where responses are observed, not modified.

## Design

* **Synchronous**: `decode_response` is a pure data transform (JSON parsing), not an I/O operation.
* **`Send + Sync`**: Required for storage in `Arc` behind `RwLock`.
* **Trait object**: Codecs are registered at runtime, stored as `Arc<dyn LlmResponseCodec>`.
* **Fallible**: Returns `Result`; managed call sites may omit annotations on decode failure, while manual lifecycle bindings may surface the error.

## Two-Phase Decode

Implementations should use a two-phase decode pattern:

1. Deserialize raw JSON into API-specific intermediate structs
2. Map intermediate structs into the normalized `AnnotatedLlmResponse`

## Required Methods

#### `decode_response`

<pre />

Parse a raw JSON response into normalized structured form.

Implementations should return `Err` only for genuinely unparseable input.

## Provided Methods

#### `codec_identity`

<pre />

Return this codec's identity for LLM sanitizer context.

Custom codecs should keep the default [`LlmCodecIdentity::Opaque`](/reference/api/rust-library-reference/nemo-relay/api/runtime/enum-llmcodecidentity) unless they have a stable runtime registration ID.

#### `allows_estimated_cost`

<pre />

Return whether aggregate response usage can be priced from its response model.

Most providers report usage for one model, so the default permits model-based cost enrichment. A provider can opt out when its response combines usage from multiple models and no provider-reported cost is available.

## Implementors

### `impl LlmResponseCodec for AnthropicMessagesCodec`

<pre />

### `impl LlmResponseCodec for GeminiGenerateContentCodec`

<pre />

### `impl LlmResponseCodec for OCIGenAIChatCodec`

<pre />

### `impl LlmResponseCodec for OpenAIChatCodec`

<pre />

### `impl LlmResponseCodec for OpenAIResponsesCodec`

<pre />