> 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 full documentation content, see https://docs.nvidia.com/nemo/relay/llms-full.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/relay/_mcp/server.

# Trait LlmCodec

> A bidirectional translator between opaque `LlmRequest` content and structured `AnnotatedLlmRequest`.

Generated from `cargo doc --no-deps -p nemo-relay -p nemo-relay-adaptive -p nemo-relay-ffi`.

<pre />

A bidirectional translator between opaque [`LlmRequest`](/reference/api/rust-library-reference/nemo-relay/api/llm/struct-llmrequest) content and structured [`AnnotatedLlmRequest`](/reference/api/rust-library-reference/nemo-relay/codec/request/struct-annotatedllmrequest).

Codecs are implemented by integration patches (LangChain, LangChain-NVIDIA, LangGraph, etc.) since each SDK has its own request format. They are registered by name in the global codec registry.

## Design

* **Synchronous**: `decode`/`encode` are pure data transforms (JSON restructuring), not I/O operations. This matches existing guardrails and request intercepts.
* **`Send + Sync`**: Required because [`NemoRelayContextState`](/reference/api/rust-library-reference/nemo-relay/api/runtime/state/struct-nemorelaycontextstate) is behind `Arc<RwLock<>>` and accessed from async contexts.
* **Trait object**: Codecs are registered at runtime (e.g., by Python patches), so the Rust core cannot know concrete types at compile time. Store as `Arc<dyn LlmCodec>`.

## Required Methods

#### `decode`

<pre />

Parse opaque request content into structured form.

#### `encode`

<pre />

Merge structured changes back into the opaque request.

The `original` parameter is the pre-intercept [`LlmRequest`](/reference/api/rust-library-reference/nemo-relay/api/llm/struct-llmrequest), used to preserve fields that the Codec does not structurally model. Implementations MUST use merge-not-replace semantics: overlay structured changes onto the original content, do not construct a fresh content object.

## Implementors

### `impl LlmCodec for AnthropicMessagesCodec`

<pre />

### `impl LlmCodec for OpenAIChatCodec`

<pre />

### `impl LlmCodec for OpenAIResponsesCodec`

<pre />