> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/microsoft/onnxruntime-genai/llms.txt
> Use this file to discover all available pages before exploring further.

# Model

> Load and manage ONNX Runtime GenAI models

The `Model` class represents a loaded ONNX Runtime GenAI model. It is the primary entry point for loading models and creating other components like tokenizers and generators.

## Constructor

### Model(string modelPath)

Creates a new Model instance from a model directory.

<ParamField path="modelPath" type="string" required>
  Path to the directory containing the model files
</ParamField>

```csharp Model.cs:14-17 theme={null}
using Microsoft.ML.OnnxRuntimeGenAI;

using Model model = new Model("/path/to/model");
```

### Model(Config config)

Creates a new Model instance from a configuration object.

<ParamField path="config" type="Config" required>
  Configuration object with model settings and provider options
</ParamField>

```csharp Model.cs:19-22 theme={null}
using Microsoft.ML.OnnxRuntimeGenAI;

using Config config = new Config("/path/to/model");
config.AppendProvider("cuda");
using Model model = new Model(config);
```

## Methods

### GetModelType()

Returns the type of the model (e.g., "phi3v", "phi4mm", "qwen2\_5\_vl").

**Returns:** `string` - The model type identifier

```csharp Model.cs:26-38 theme={null}
string modelType = model.GetModelType();
Console.WriteLine($"Model type: {modelType}");
```

### Dispose()

Releases the resources used by the model. Models implement `IDisposable` and should be disposed when no longer needed.

```csharp theme={null}
model.Dispose();
// Or use 'using' statement for automatic disposal
using Model model = new Model("/path/to/model");
```

## Complete Example

Here's a complete example of loading a model and using it with a tokenizer and generator:

```csharp theme={null}
using Microsoft.ML.OnnxRuntimeGenAI;

string modelPath = "/path/to/model";

// Load model with default configuration
using Model model = new Model(modelPath);

// Get model type
string modelType = model.GetModelType();
Console.WriteLine($"Loaded model type: {modelType}");

// Create tokenizer from model
using Tokenizer tokenizer = new Tokenizer(model);

// Create generator params
using GeneratorParams generatorParams = new GeneratorParams(model);
generatorParams.SetSearchOption("max_length", 1024);

// Create generator
using Generator generator = new Generator(model, generatorParams);

// Model is automatically disposed when leaving the 'using' scope
```

## Example with Custom Configuration

Load a model with custom execution provider settings:

```csharp examples/csharp/ModelChat/Program.cs:586-590 theme={null}
using Microsoft.ML.OnnxRuntimeGenAI;

string modelPath = "/path/to/model";
string executionProvider = "cuda";

// Create configuration
using Config config = new Config(modelPath);
config.ClearProviders();
config.AppendProvider(executionProvider);

// Create model from configuration
using Model model = new Model(config);
Console.WriteLine($"Model loaded with {executionProvider} provider");
```

## See Also

* [Tokenizer](/api/csharp/tokenizer) - Create tokenizers from models
* [Generator](/api/csharp/generator) - Generate text with models
* [GeneratorParams](/api/csharp/params) - Configure generation parameters
