ONNX Runtime JavaScript API
    Preparing search index...

    Interface SessionOptions

    A set of configurations for session behavior.

    interface SessionOptions {
        enableCpuMemArena?: boolean;
        enableGraphCapture?: boolean;
        enableMemPattern?: boolean;
        enableProfiling?: boolean;
        epContextDataRead?: {
            callback: (name: string) => Uint8Array;
            maxDataSize: number;
        };
        executionMode?: "sequential"
        | "parallel";
        executionProviders?: readonly ExecutionProviderConfig[];
        externalData?: readonly ExternalDataFileType[];
        extra?: Record<string, unknown>;
        freeDimensionOverrides?: { readonly [dimensionName: string]: number };
        graphOptimizationLevel?:
            | "basic"
            | "all"
            | "disabled"
            | "extended"
            | "layout";
        interOpNumThreads?: number;
        intraOpNumThreads?: number;
        logId?: string;
        logSeverityLevel?: 0
        | 2
        | 1
        | 3
        | 4;
        logVerbosityLevel?: number;
        optimizedModelFilePath?: string;
        preferredOutputLocation?:
            | DataLocation
            | { readonly [outputName: string]: DataLocation };
        profileFilePrefix?: string;
    }

    Hierarchy (View Summary)

    Index

    Properties

    enableCpuMemArena?: boolean

    Whether enable CPU memory arena.

    This setting is available only in ONNXRuntime (Node.js binding and react-native) or WebAssembly backend

    enableGraphCapture?: boolean

    Whether enable graph capture. This setting is available only in ONNXRuntime Web for WebGPU EP.

    enableMemPattern?: boolean

    Whether enable memory pattern.

    This setting is available only in ONNXRuntime (Node.js binding and react-native) or WebAssembly backend

    enableProfiling?: boolean

    Whether enable profiling.

    This setting is a placeholder for a future use.

    epContextDataRead?: {
        callback: (name: string) => Uint8Array;
        maxDataSize: number;
    }

    Configure loading external data referenced by EPContext nodes.

    The callback is invoked synchronously with the external data name and must return a Uint8Array. The returned bytes are copied into ONNX Runtime-owned memory during the enclosing native operation. Do not modify or reuse the returned view's backing storage until that operation completes; return a fresh array when using mutable shared storage. Empty arrays are supported. Callback invocations may originate from multiple ONNX Runtime threads; the native JavaScript bindings serialize calls before invoking JavaScript.

    maxDataSize is a required, finite, positive safe integer. Session creation fails if the callback throws, returns another type, or returns more bytes than this limit. ONNX Runtime does not fall back to loading the data from disk after a callback failure.

    The binding retains and enforces this limit in its callback state before allocating the native output buffer. It is not configured in the native API and does not constrain allocations made inside the JavaScript callback.

    This setting is available only in the Node.js and React Native bindings. ONNX Runtime Web rejects it because a JavaScript callback cannot currently be registered safely through the WebAssembly ABI.

    JavaScript does not currently expose model compilation, so the corresponding EPContext data write callback is not available.

    executionMode?: "sequential" | "parallel"

    Execution mode.

    This setting is available only in ONNXRuntime (Node.js binding and react-native) or WebAssembly backend

    executionProviders?: readonly ExecutionProviderConfig[]

    An array of execution provider options.

    An execution provider option can be a string indicating the name of the execution provider, or an object of corresponding type.

    externalData?: readonly ExternalDataFileType[]

    Specifying a list of files that represents the external data.

    extra?: Record<string, unknown>

    Store configurations for a session. See https://github.com/microsoft/onnxruntime/blob/main/include/onnxruntime/core/session/ onnxruntime_session_options_config_keys.h

    This setting is available only in WebAssembly backend. Will support Node.js binding and react-native later

    extra: {
    session: {
    set_denormal_as_zero: "1",
    disable_prepacking: "1"
    },
    optimization: {
    enable_gelu_approximation: "1"
    }
    }
    freeDimensionOverrides?: { readonly [dimensionName: string]: number }

    The free dimension override.

    This setting is available only in ONNXRuntime (Node.js binding and react-native) or WebAssembly backend

    graphOptimizationLevel?: "basic" | "all" | "disabled" | "extended" | "layout"

    The optimization level.

    This setting is available only in ONNXRuntime (Node.js binding and react-native) or WebAssembly backend

    interOpNumThreads?: number

    The inter OP threads number.

    This setting is available only in ONNXRuntime (Node.js binding and react-native).

    intraOpNumThreads?: number

    The intra OP threads number.

    This setting is available only in ONNXRuntime (Node.js binding and react-native).

    logId?: string

    Log ID.

    This setting is available only in ONNXRuntime (Node.js binding and react-native) or WebAssembly backend

    logSeverityLevel?: 0 | 2 | 1 | 3 | 4

    Log severity level. See https://github.com/microsoft/onnxruntime/blob/main/include/onnxruntime/core/common/logging/severity.h

    This setting is available only in ONNXRuntime (Node.js binding and react-native) or WebAssembly backend

    logVerbosityLevel?: number

    Log verbosity level.

    This setting is available only in WebAssembly backend. Will support Node.js binding and react-native later

    optimizedModelFilePath?: string

    Optimized model file path.

    If this setting is specified, the optimized model will be dumped. In browser, a blob will be created with a pop-up window.

    preferredOutputLocation?:
        | DataLocation
        | { readonly [outputName: string]: DataLocation }

    Specify string as a preferred data location for all outputs, or an object that use output names as keys and a preferred data location as corresponding values.

    This setting is available only in ONNXRuntime Web for WebGL and WebGPU EP.

    profileFilePrefix?: string

    File prefix for profiling.

    This setting is a placeholder for a future use.