> This page is for NeMo Relay, version v1.0.0.
> For other versions, use one of these documentation indexes:
> - Latest (v0.11.2) (default): https://docs.nvidia.com/nemo/relay/latest/llms.txt
> - dev: https://docs.nvidia.com/nemo/relay/dev/llms.txt
> - v1.0.0: https://docs.nvidia.com/nemo/relay/v1.0.0/llms.txt
> - v0.11.2: https://docs.nvidia.com/nemo/relay/v0.11.2/llms.txt
> - v0.10.4: https://docs.nvidia.com/nemo/relay/v0.10.4/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

> For clean Markdown of any page, append .md to the page URL. For a task-oriented documentation index, fetch https://docs.nvidia.com/nemo/relay/llms.txt. Use the documentation version matching the installed NeMo Relay package: latest follows the latest stable release, vX.Y.Z identifies a retained release snapshot, and dev documents development changes. Preserve the selected version when following links; do not mix examples or API contracts from different versions. Fetch the relevant section's /llms.txt before individual pages instead of loading a complete version index.

# Typed Helpers

> Typed wrappers for the execute APIs, converting values with a `Codec&lt;T&gt;`.

Generated from `crates/node/dist/typed.d.ts`.

Import from `nemo-relay-node/typed`.

Typed wrappers for the execute APIs, converting values with a `Codec&amp;lt;T&amp;gt;`.

## Interfaces

### `ToolExecutionResult`

Result returned to the application after tool execution.

```ts
export interface ToolExecutionResult<TResult> {
    result: TResult;
    annotation?: JsonValue;
}
```

### `Codec`

Converts between a typed value `T` and JSON.

```ts
export interface Codec<T, TJson extends JsonCompatible<TJson> = JsonValue> {
    /** Converts a typed value to JSON. */
    toJson: (value: T) => TJson;
    /** Rebuilds a typed value from JSON. */
    fromJson: (data: JsonValue) => T;
}
```

### `TypedToolExecuteOptions`

Options for `typedToolExecute`.

```ts
export interface TypedToolExecuteOptions<TData extends JsonCompatible<TData> = JsonValue, TMetadata extends JsonCompatible<TMetadata> = JsonValue> {
    handle?: ScopeHandle | null;
    attributes?: number | null;
    data?: TData;
    metadata?: TMetadata;
    toolCallId?: string | null;
    /** Host-supplied context for execution intercepts: at most 16 KiB and 64 object/array levels (root is level 1); never event metadata. */
    executionContext?: ApplicationExecutionContext | null;
    executionOptions?: ExecutionOptions | null;
}
```

### `TypedLlmExecuteOptions`

Options for `typedLlmExecute`.

```ts
export interface TypedLlmExecuteOptions<TData extends JsonCompatible<TData> = JsonValue, TMetadata extends JsonCompatible<TMetadata> = JsonValue, TAnnotated extends JsonCompatible<TAnnotated> = JsonValue, TEncoded extends LlmRequestCompatible<TEncoded> = LlmRequestShape, TDecodedResponse extends JsonCompatible<TDecodedResponse> = JsonValue> {
    handle?: ScopeHandle | null;
    attributes?: number | null;
    data?: TData;
    metadata?: TMetadata;
    modelName?: string | null;
    codec?: LlmCodec<TAnnotated, TEncoded> | null;
    responseCodec?: LlmResponseCodec<TDecodedResponse> | null;
    executionOptions?: ExecutionOptions | null;
    executionContext?: LlmApplicationExecutionContext | null;
}
```

### `TypedLlmStreamExecuteOptions`

Options for `typedLlmStreamExecute`.

```ts
export interface TypedLlmStreamExecuteOptions<TData extends JsonCompatible<TData> = JsonValue, TMetadata extends JsonCompatible<TMetadata> = JsonValue, TAnnotated extends JsonCompatible<TAnnotated> = JsonValue, TEncoded extends LlmRequestCompatible<TEncoded> = LlmRequestShape, TDecodedResponse extends JsonCompatible<TDecodedResponse> = JsonValue> {
    handle?: ScopeHandle | null;
    attributes?: number | null;
    data?: TData;
    metadata?: TMetadata;
    modelName?: string | null;
    codec?: LlmCodec<TAnnotated, TEncoded> | null;
    responseCodec?: LlmResponseCodec<TDecodedResponse> | null;
    executionOptions?: ExecutionOptions | null;
    executionContext?: LlmApplicationExecutionContext | null;
}
```

## Classes

### `JsonPassthrough`

Codec that returns values unchanged.

```ts
export declare class JsonPassthrough implements Codec<JsonValue> {
    toJson(value: JsonValue): JsonValue;
    fromJson(data: JsonValue): JsonValue;
}
```

## Functions

### `typedToolExecute`

Executes a tool call with typed arguments and result.

`args` is encoded with `argsCodec` before the tool lifecycle runs, and the JSON result is decoded with `resultCodec` afterwards. The annotation is returned as the pipeline produced it.

**Parameters**

* `name`: Tool name.
* `args`: Typed tool arguments.
* `func`: The tool. It may return the result directly or in a promise.
* `argsCodec`: Converts the arguments to and from JSON.
* `resultCodec`: Converts the result to and from JSON.
* `options`: Scope handle, attributes, data, metadata, tool call id, and host execution context.

**Returns**

The decoded result and its annotation.

**Remarks**

A codec error or an execution error rejects the returned promise.

```ts
export declare function typedToolExecute<TArgs, TResult, TArgsJson extends JsonCompatible<TArgsJson> = JsonValue, TResultJson extends JsonCompatible<TResultJson> = JsonValue, TData extends JsonCompatible<TData> = JsonValue, TMetadata extends JsonCompatible<TMetadata> = JsonValue>(name: string, args: TArgs, func: (args: TArgs, signal: AbortSignal) => ToolExecutionResult<TResult> | Promise<ToolExecutionResult<TResult>>, argsCodec: Codec<TArgs, TArgsJson>, resultCodec: Codec<TResult, TResultJson>, options?: TypedToolExecuteOptions<TData, TMetadata>): Promise<ToolExecutionResult<TResult>>;
```

### `typedLlmExecute`

Executes an LLM call with a typed response.

The LLM lifecycle runs on `request`, and the JSON response is decoded with `responseCodec` before it is returned.

**Parameters**

* `name`: Provider name.
* `request`: Request with `headers` and `content`.
* `func`: The LLM call. It may return the response directly or in a promise.
* `responseCodec`: Converts the response to and from JSON.
* `options`: Scope handle, attributes, data, metadata, model name, and codecs.

**Returns**

The decoded response.

**Remarks**

`options.responseCodec` decodes the response copied into events. It does not change the returned response.

```ts
export declare function typedLlmExecute<TRequest extends LlmRequestCompatible<TRequest>, TResponse, TResponseJson extends JsonCompatible<TResponseJson> = JsonValue, TData extends JsonCompatible<TData> = JsonValue, TMetadata extends JsonCompatible<TMetadata> = JsonValue, TAnnotated extends JsonCompatible<TAnnotated> = JsonValue, TEncoded extends LlmRequestCompatible<TEncoded> = LlmRequestShape, TDecodedResponse extends JsonCompatible<TDecodedResponse> = JsonValue>(name: string, request: TRequest, func: (request: LlmRequestShape, signal: AbortSignal) => TResponse | Promise<TResponse>, responseCodec: Codec<TResponse, TResponseJson>, options?: TypedLlmExecuteOptions<TData, TMetadata, TAnnotated, TEncoded, TDecodedResponse>): Promise<TResponse>;
```

### `typedLlmStreamExecute`

Executes a streaming LLM call with typed chunks and response.

Each chunk from `func` is encoded with `chunkCodec` before middleware sees it and decoded again before `collector` receives it. The value from `finalizer` is encoded with `responseCodec`.

**Parameters**

* `name`: Provider name.
* `request`: Request with `headers` and `content`.
* `func`: The streaming LLM call. It receives the request and an `AbortSignal` and returns an async iterable of chunks.
* `collector`: Receives one decoded chunk at a time. It may return a promise.
* `finalizer`: Returns the final response once the stream ends. It may return a promise.
* `chunkCodec`: Converts chunks to and from JSON.
* `responseCodec`: Converts the final response to and from JSON.
* `options`: Scope handle, attributes, data, metadata, model name, and codecs.

**Returns**

The `LlmStream` to read chunks from.

**Remarks**

An error in `collector` fails the stream. An error in `finalizer` is thrown by `stream.close()`. A reader that stops early must await `stream.close()`, which aborts the signal and waits for cleanup.

```ts
export declare function typedLlmStreamExecute<TRequest extends LlmRequestCompatible<TRequest>, TChunk, TResponse, TChunkJson extends JsonCompatible<TChunkJson> = JsonValue, TResponseJson extends JsonCompatible<TResponseJson> = JsonValue, TData extends JsonCompatible<TData> = JsonValue, TMetadata extends JsonCompatible<TMetadata> = JsonValue, TAnnotated extends JsonCompatible<TAnnotated> = JsonValue, TEncoded extends LlmRequestCompatible<TEncoded> = LlmRequestShape, TDecodedResponse extends JsonCompatible<TDecodedResponse> = JsonValue>(name: string, request: TRequest, func: (request: LlmRequestShape, signal: AbortSignal) => AsyncIterable<TChunk> | Promise<AsyncIterable<TChunk>>, collector: (chunk: TChunk) => void | Promise<void>, finalizer: () => TResponse | Promise<TResponse>, chunkCodec: Codec<TChunk, TChunkJson>, responseCodec: Codec<TResponse, TResponseJson>, options?: TypedLlmStreamExecuteOptions<TData, TMetadata, TAnnotated, TEncoded, TDecodedResponse>): Promise<LlmStream>;
```

## Re-exports

* `ApplicationExecutionContext`
* `Json`
* `JsonArray`
* `JsonCompatible`
* `JsonObject`
* `JsonPrimitive`
* `JsonValue`
* `LlmCodec`
* `LlmRequestCompatible`
* `LlmRequestShape`
* `LlmResponseCodec`