# How Provider Overrides and Model-Specific Context Budgets Function in Reasonix

> Discover how Reasonix utilizes provider overrides and model-specific context budgets for precise token management. Learn about its hierarchical fallback system for efficient token allocation.

- Repository: [YHH/DeepSeek-Reasonix](https://github.com/esengine/DeepSeek-Reasonix)
- Tags: internals
- Published: 2026-08-07

---

**Reasonix employs a hierarchical fallback system where provider-wide `context_window` defaults are applied unless explicitly overridden by `model_overrides` entries, enabling precise per-model token budgets without modifying source code.**

The Reasonix inference engine from `esengine/DeepSeek-Reasonix` treats every LLM endpoint as a configurable provider with customizable token limits. Understanding how provider overrides and model-specific context budgets function allows you to fine-tune memory allocation across different models while maintaining sensible global defaults in your TOML configuration.

## Provider-Wide Defaults and the Fallback Chain

At the foundation of Reasonix's budget system lies the **provider-wide `context_window`**, defined in [`internal/provider/config.go`](https://github.com/esengine/DeepSeek-Reasonix/blob/main/internal/provider/config.go) within the `Config` struct. This field establishes the default token limit for every model served by that provider.

When the engine processes a request, the `Config.ResolveModel` method implements the resolution logic:

1. It first identifies the provider responsible for the requested model.
2. It checks whether the model name exists as a key in the `ModelOverrides` map.
3. If an override exists and specifies a `ContextWindow` greater than zero, that value replaces the provider default.
4. Otherwise, the system falls back to the provider's global `ContextWindow` setting.

This design ensures that new models automatically inherit the provider's default budget while allowing surgical adjustments for specific model variants.

## Model-Specific Budget Overrides in Practice

The **`model_overrides`** mechanism enables granular control through the TOML configuration structure. Under the `[provider.<name>.model_overrides."<model-name>"]` section, you can define a custom `context_window` that applies exclusively to that model.

Setting **`context_window = 0`** for a specific model disables automatic context compaction entirely, which is useful for debugging or when handling extremely long contexts manually. Positive values specify custom token budgets—for example, allocating 1,000,000 tokens for a long-context variant while keeping the provider default at 4,000 for standard models.

The same override system supports **`max_output_tokens`**, allowing you to set generation limits independently of the input context budget. This separation ensures that reasoning-step budgets remain distinct from final output constraints.

## Configuration Example

Here is a complete TOML configuration demonstrating provider defaults and per-model overrides:

```toml

# reasonix.toml

[provider.deepseek]
name = "deepseek"
base_url = "https://api.deepseek.com"
api_key_env = "DEEPSEEK_API_KEY"

# Provider-wide token budget (fallback)

context_window = 4000

# Model-specific overrides

[provider.deepseek.model_overrides."deepseek-v4-flash"]
context_window = 1_000_000   # enable long-context mode

max_output_tokens = 32_768

```

In this example, all DeepSeek models default to 4,000 tokens, but `deepseek-v4-flash` receives a one-million-token context window and a 32,768-token output limit.

## Go Implementation Details

The resolution logic lives in [`internal/provider/config.go`](https://github.com/esengine/DeepSeek-Reasonix/blob/main/internal/provider/config.go). The `ResolveModel` method performs the override check before falling back to defaults:

```go
func (c Config) ResolveModel(model string) (int, error) {
    // Find provider for the model (omitted for brevity)
    prov := c.Provider // the resolved Provider config
    
    // Check for a model-specific override
    if ov, ok := prov.ModelOverrides[model]; ok && ov.ContextWindow > 0 {
        return ov.ContextWindow, nil
    }
    
    // Fallback to the provider default
    return prov.ContextWindow, nil
}

```

When building requests, the session retrieves the effective budget and passes it to the provider's compaction logic:

```go
func (s *Session) buildRequest(model string, msgs []Message) Request {
    ctxWin, _ := s.cfg.ResolveModel(model)
    return Request{
        Model:         model,
        Messages:      msgs,
        ContextWindow: ctxWin, // passed to the provider for compaction logic
    }
}

```

## Summary

- **Provider defaults** are stored in the `ContextWindow` field within [`internal/provider/config.go`](https://github.com/esengine/DeepSeek-Reasonix/blob/main/internal/provider/config.go) and apply to all models unless superseded.
- **Model overrides** use the `model_overrides` map structure in TOML configuration to specify custom budgets per model name.
- **Zero value behavior**—setting `context_window = 0`—disables automatic context compaction for that specific model.
- **Resolution logic** is implemented in `Config.ResolveModel`, which checks overrides before falling back to provider defaults.
- **Output limits** can be configured separately via `max_output_tokens` overrides, independent of input context budgets.
- **Configuration-driven** changes require no code modification; adjusting [`reasonix.toml`](https://github.com/esengine/DeepSeek-Reasonix/blob/main/reasonix.toml) suffices for updating token limits.

## Frequently Asked Questions

### How does Reasonix determine the effective context window for a specific model?

Reasonix calls `Config.ResolveModel` in [`internal/provider/config.go`](https://github.com/esengine/DeepSeek-Reasonix/blob/main/internal/provider/config.go), which first checks if the requested model exists in the provider's `ModelOverrides` map. If a valid override exists, that value is returned; otherwise, the method falls back to the provider's global `ContextWindow` setting.

### Can I disable automatic context compaction for individual models?

Yes. Set `context_window = 0` within the `[provider.<name>.model_overrides."<model>"]` section of your TOML configuration. This zero value signals the engine to bypass automatic compaction for that specific model while leaving other models unaffected.

### Where are the provider default and model override specifications defined?

The authoritative specification resides in [`docs/SPEC.md`](https://github.com/esengine/DeepSeek-Reasonix/blob/main/docs/SPEC.md), which defines the behavior for provider-wide fallbacks and per-model overrides. The Go implementation that enforces these rules is located in [`internal/provider/config.go`](https://github.com/esengine/DeepSeek-Reasonix/blob/main/internal/provider/config.go), specifically within the `Config` struct and its `ResolveModel` method.

### Is it possible to set different output token limits for specific models?

Yes. The `model_overrides` mechanism supports an independent `max_output_tokens` field. This allows you to configure generation budgets separately from input context windows, providing fine-grained control over both reasoning-step limits and final output length on a per-model basis.