# Window per model

Canonical URL: https://developers.iagenify.com/sdk/agent/context/window/
Language: en

The engine reads the real window from the catalogue and never lets you ask for more than it. The default stays at 200 000 whatever the model allows.

Status: read from the catalogue · cached 10 minutes · context_too_large

## How the limit is decided {#resolution}

- The model's window is read from [catalogue()](/sdk/ref/iagenify/catalogue) at the start of a run, and kept for ten minutes.
- Without `contextTokens`, the limit is the **smaller** of 200 000 and that window.
- With `contextTokens`, that is the limit — unless it is larger than the window, which is refused.

```javascript
// Default on a model with a 1 048 576-token window → limit 200 000
api.agents.create({ runtime: "local", machine: pc, model: "gemini-3.5-flash" });

// Asking for more than the model has
api.agents.create({ runtime: "local", machine: pc, model, contextTokens: 2_000_000 });
// IaGenifyError context_too_large: contextTokens (2,000,000) is larger than
// the context window of … (1,048,576 tokens).
```

## What is accepted {#validation}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `contextTokens` | integer | 200 000 | A whole number of tokens, **at least 10 000**. Anything else is refused with `invalid_context` at creation. |

The catalogue is read at run time, not at creation, so `context_too_large` surfaces on the first `run()` rather than when the object is built.

## Why the default is lower than the window {#why-default}

> **A window is what fits, not what is wise**
>
> A turn carrying 800 000 tokens is slow and expensive on every step that follows, because the whole history is re-sent each time. 200 000 is a working ceiling that keeps a step quick; raising it is a decision you make for a specific job, not a default you inherit.

## Reading it back {#reading}

```javascript
agent.context;
// { tokens: 31_204, limit: 200_000, window: 1_048_576, cachedTokens: 22_400,
//   cleared: 3, parts: { system: 2_100, tools: 3_900, memory: 180, messages: 25_024 } }
```

| Field | Is |
| --- | --- |
| `tokens` | The size of the last turn, as the provider measured it. |
| `limit` | The limit in force — your `contextTokens`, or the default. |
| `window` | The model's own window, or `null` if the catalogue could not be read. |
| `cachedTokens` | How much of the last turn the provider served from its cache. |
| `cleared` | How many tool results have been emptied so far. |
| `parts` | The breakdown: system, tools, memory, messages. |

## If the catalogue cannot be read {#unreachable}

The run continues with the limit you asked for, or the default. `window` stays `null` and nothing is refused for being too large — a transient failure reading a price list is not a reason to stop working.

## Mind it when you set fallbackModels {#fallback}

The limit is resolved from the main model. A fallback with a smaller window can refuse a history the main one accepted — so pick fallbacks of comparable size, or keep `contextTokens` at a value all of them hold.

- [Clearing tool results](/sdk/agent/context/clearing): The first thing that gives way.
- [Fallback and retry](/sdk/agent/fallback-and-retry): Why a fallback's window matters.

```python
from iagenify import IaGenifyError

# Default on a model with a 1 048 576-token window → limit 200 000
api.agents.create(runtime="local", machine=pc, model="gemini-3.5-flash")

# Asking for more than the model has: refused on the first run, once the window is read
agent = api.agents.create(runtime="local", machine=pc, model=model, context_tokens=2_000_000)
try:
    agent.run(message="…")
except IaGenifyError as error:
    print(error.code)   # "context_too_large"
```

```python
agent.context
# {"tokens": 31_204, "limit": 200_000, "window": 1_048_576, "cachedTokens": 0,
#  "cleared": 3, "parts": {"system": 2_100, "tools": 3_900, "memory": 0, "messages": 25_204}}
```
