Skip to navigation

Generated from cargo doc --no-deps -p nemo-relay-builtins -p nemo-relay-diagnostics -p nemo-relay-logging -p nemo-relay-plugin-host -p nemo-relay-codecs -p nemo-relay -p nemo-relay-runtime -p nemo-relay-model-pricing -p nemo-relay-resource-metrics -p nemo-relay-observability -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.

pub trait LlmResponseCodec: Send + Sync {
// Required method
fn decode_response(
&self,
response: &Value,
) -> Result<AnnotatedLlmResponse, FlowError>;
// Provided methods
fn redaction(&self) -> Option<&dyn LlmResponseRedaction> { ... }
fn codec_identity(&self) -> LlmCodecIdentity { ... }
fn allows_estimated_cost(&self, _response: &Value) -> bool { ... }
}

Referenced types: Send, Sync, Value, Result, AnnotatedLlmResponse, FlowError, Option, LlmResponseRedaction, LlmCodecIdentity, bool

Decode-only codec for LLM API responses.

Unlike LlmCodec (which is bidirectional for requests), response codecs parse a raw response into structured form for observation. Optional LlmResponseRedaction capabilities can materialize sanitized observability payloads; they do not rewrite the caller-visible response.

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

fn decode_response(
&self,
response: &Value,
) -> Result<AnnotatedLlmResponse, FlowError>

Referenced types: Value, Result, AnnotatedLlmResponse, FlowError

Parse a raw JSON response into normalized structured form.

Implementations should return Err only for genuinely unparseable input.

Provided Methods

redaction

fn redaction(&self) -> Option<&dyn LlmResponseRedaction>

Referenced types: Option, LlmResponseRedaction

Explicit redaction capabilities; unsupported operations fail closed.

codec_identity

fn codec_identity(&self) -> LlmCodecIdentity

Referenced types: LlmCodecIdentity

Return this codec’s identity for LLM sanitizer context.

Custom codecs should keep the default LlmCodecIdentity::Opaque unless they have a stable runtime registration ID.

allows_estimated_cost

fn allows_estimated_cost(&self, _response: &Value) -> bool

Referenced types: Value, bool

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.

Implementations on Foreign Types

impl LlmResponseCodec for AnthropicMessagesCodec

impl LlmResponseCodec for AnthropicMessagesCodec

Referenced types: LlmResponseCodec

redaction

fn redaction(&self) -> Option<&dyn LlmResponseRedaction>

Referenced types: Option, LlmResponseRedaction

codec_identity

fn codec_identity(&self) -> LlmCodecIdentity

Referenced types: LlmCodecIdentity

allows_estimated_cost

fn allows_estimated_cost(&self, response: &Value) -> bool

Referenced types: Value, bool

decode_response

fn decode_response(
&self,
response: &Value,
) -> Result<AnnotatedLlmResponse, FlowError>

Referenced types: Value, Result, AnnotatedLlmResponse, FlowError

impl LlmResponseCodec for GeminiGenerateContentCodec

impl LlmResponseCodec for GeminiGenerateContentCodec

Referenced types: LlmResponseCodec

redaction

fn redaction(&self) -> Option<&dyn LlmResponseRedaction>

Referenced types: Option, LlmResponseRedaction

codec_identity

fn codec_identity(&self) -> LlmCodecIdentity

Referenced types: LlmCodecIdentity

decode_response

fn decode_response(
&self,
response: &Value,
) -> Result<AnnotatedLlmResponse, FlowError>

Referenced types: Value, Result, AnnotatedLlmResponse, FlowError

impl LlmResponseCodec for OCIGenAIChatCodec

impl LlmResponseCodec for OCIGenAIChatCodec

Referenced types: LlmResponseCodec

redaction

fn redaction(&self) -> Option<&dyn LlmResponseRedaction>

Referenced types: Option, LlmResponseRedaction

codec_identity

fn codec_identity(&self) -> LlmCodecIdentity

Referenced types: LlmCodecIdentity

decode_response

fn decode_response(
&self,
response: &Value,
) -> Result<AnnotatedLlmResponse, FlowError>

Referenced types: Value, Result, AnnotatedLlmResponse, FlowError

impl LlmResponseCodec for OpenAIChatCodec

impl LlmResponseCodec for OpenAIChatCodec

Referenced types: LlmResponseCodec

redaction

fn redaction(&self) -> Option<&dyn LlmResponseRedaction>

Referenced types: Option, LlmResponseRedaction

codec_identity

fn codec_identity(&self) -> LlmCodecIdentity

Referenced types: LlmCodecIdentity

decode_response

fn decode_response(
&self,
response: &Value,
) -> Result<AnnotatedLlmResponse, FlowError>

Referenced types: Value, Result, AnnotatedLlmResponse, FlowError

impl LlmResponseCodec for OpenAIResponsesCodec

impl LlmResponseCodec for OpenAIResponsesCodec

Referenced types: LlmResponseCodec

redaction

fn redaction(&self) -> Option<&dyn LlmResponseRedaction>

Referenced types: Option, LlmResponseRedaction

codec_identity

fn codec_identity(&self) -> LlmCodecIdentity

Referenced types: LlmCodecIdentity

decode_response

fn decode_response(
&self,
response: &Value,
) -> Result<AnnotatedLlmResponse, FlowError>

Referenced types: Value, Result, AnnotatedLlmResponse, FlowError

Implementors