Skip to content

Latest commit

 

History

History
116 lines (76 loc) · 3.48 KB

File metadata and controls

116 lines (76 loc) · 3.48 KB
title Use ONNX APIs in Windows ML
description Learn how to use the ONNX APIs shipped in Windows Machine Learning (ML) to use local AI ONNX models in your Windows apps.
ms.date 03/10/2026
ms.topic how-to

Use ONNX APIs in Windows ML

Windows Machine Learning (ML) includes a shared copy of the ONNX Runtime, including its APIs. That means when you install Windows ML via Windows App SDK, your app will have access to the full ONNX API surface.

To see what version of ONNX Runtime is included in specific Windows ML versions, see ONNX Runtime versions shipped in Windows ML.

This page covers how to use the ONNX APIs included in Windows ML.

Prerequisites

Namespaces / headers

The namespaces / headers for the ONNX APIs within Windows ML are as follows:

In C#, the namespaces of the ONNX APIs are the same as when using ONNX Runtime directly.

using Microsoft.ML.OnnxRuntime;

In C++/WinRT, the ONNX Runtime headers are included in a winml/ directory to avoid conflicts with other versions of ONNX Runtime.

#include <winml/onnxruntime_cxx_api.h>

If you have existing code that uses ONNX headers and do not want to update your includes, you can tell Windows ML to expose the headers without the winml/ prefix by setting the WinMLEnableDefaultOrtHeaderIncludePath property in your project:

<PropertyGroup>
  <WinMLEnableDefaultOrtHeaderIncludePath>true</WinMLEnableDefaultOrtHeaderIncludePath>
</PropertyGroup>

Then, the headers will be the same as standalone ONNX Runtime:

#include <onnxruntime_cxx_api.h>

Note

In the pre-GA releases of Windows ML, the C++ ONNX Runtime headers were prefixed by win_ rather than within a winml/ subdirectory, and the WinMLEnableDefaultOrtHeaderIncludePath property didn't exist.

With the C APIs, the ONNX Runtime headers are included in the directory you configure them for (often your root directory).

#include <onnxruntime_cxx_api.h> // Or <onnxruntime_c_api.h> if just using C

In Python, the name of the ONNX Runtime module is the same as when using ONNX Runtime directly.

import onnxruntime as ort

APIs

The ONNX APIs are the same as when using ONNX Runtime directly. For example, to create an inference session:

// Create inference session using compiled model
using InferenceSession session = new(compiledModelPath, sessionOptions);
// Create inference session using compiled model
Ort::Session session(env, compiledModelPath.c_str(), sessionOptions);
// Create inference session using compiled model
Ort::Session session(env, compiledModelPath.c_str(), sessionOptions);
# Create inference session using compiled model
session = ort.InferenceSession(output_model_path, sess_options=options)

We suggest reading the ONNX Runtime docs for more info about how to use the ONNX Runtime APIs within Windows ML.

See also