# Compute and snapshot

> Read the computed values of a Layerz model over REST, and download or upload the whole model as one JSON document with optimistic locking.

## Compute

`GET /models/:id/compute` computes the model and returns every line's series. `?items=uid1,uid2` limits the response to some lines.

```json
{
  "values": { "a1b2c3d4": [100, 120, 140] },
  "periods": { "yearly": ["2027", "2028", "2029"], "constant": ["constant"] },
  "item_timelines": { "a1b2c3d4": "yearly" },
  "order": ["e5f6a7b8", "a1b2c3d4"],
  "errors": {}
}
```

- `values[uid]` aligns with `periods[item_timelines[uid]]`.
- A line computed once (a constant, an `IRR`, an `NPV`) has one value, on the `constant` timeline.
- When the model cannot compute (a cycle, a broken reference), the response adds `computable: false` and `compute_errors` (`code`, `message`, `item_uids`), and the affected series read zero. Fix the model before reading its numbers.

Values are the base plan. Scenario views, values at another grain and the check report are available over MCP (`layerz_read` with `branch_id`, `granularity`, `health`).

## Snapshot

The snapshot is the whole model in its [stored format](/docs/reference/model-format): `{ manifest, schema, inputs }`.

- `GET /models/:id/snapshot` returns it with an `ETag` (a hash of its content).
- `PUT /models/:id/snapshot` replaces the model with the document you send. Headers:

| Header            |                                                                                      |
| ----------------- | ------------------------------------------------------------------------------------ |
| `X-Version-Label` | Required: the label of the version this write records                                |
| `If-Match`        | Optional: the `ETag` you read; the write fails with `409` if the model changed since |

The model is validated and repaired at write time like any other write. Use the snapshot to keep a model in a repository, diff it in code review, or move it between accounts.
