> ## Documentation Index
> Fetch the complete documentation index at: https://weights.fyi/run/llms.txt

# POST /v1/compute/plans/{plan_id}/stages/{stage_id}/materialize

```text
POST https://weights.fyi/run/v1/compute/plans/{plan_id}/stages/{stage_id}/materialize
Authorization: Bearer <token>                    scope: submit
Content-Type: application/json
```

**Available since:** 2026-10-28: included in this build; see [What is live](/run/docs/what-is-live.md) for deployment status.

**Answer time:** synchronous registration of the next pack window; does not wait for processing or upload input bytes.

Fills a stream's pending-pack lookahead using its `lazy_materializer` policy. Existing lazy packs are promoted first, in ordinal order; additional registrations can be generated from a manifest or templates up to the declared total. Here materialization makes pack metadata runnable; it does not create or verify the remote data those registrations name.

The stage must be ready or actively executing, its dependencies satisfied, its tenant grant valid and its scheduling window open. A terminal plan, non-stream stage, missing or disabled policy, or ineligible stage produces zero work. `force_fill` lifts the policy's batch-size limit while preserving eligibility, lookahead, admission and total-pack limits.

## Request

| Name | Where | Required | Meaning |
|---|---|---|---|
| `Authorization` | header | yes | Bearer token with `submit`. |
| `plan_id`, `stage_id` | path | yes | Your plan and stream stage identifiers. |
| `force_fill` | JSON body | no | Boolean, default false. True fills the available lookahead in this call. |

Send `{}` or an object containing only `force_fill`, at most 1 MiB. An empty body is invalid JSON. Configure the policy during [plan admission](/run/docs/reference/compute-plans-create.md):

| Policy field | Meaning |
|---|---|
| `lazy_materializer` | Object on stage, metadata or workload; the first declaration in that order wins. |
| `enabled`, `auto_seal` | Optional booleans, effective default true. Sealing occurs once the declared total is registered beyond the lazy state. |
| `lookahead_packs`, `batch_size` | Positive integers. Lookahead defaults to 16 pending packs; omitted batch size permits the full gap. |
| `packs_total` | Positive integer; otherwise workload `packs_total`, `expected_packs`, or manifest length supplies the total. Without a total, only existing lazy packs are promoted. |
| `manifest`, `shards`, `packs` | Alternative arrays of pack objects, considered in this order. Entries override generated defaults. |
| `start_index`, `pack_id_template` | Positive index, default 1; ordinal defaults to index minus one. Identifier template defaults to `pack-{index:04d}`; a literal prefix gets `-{index:04d}` appended. A template containing placeholders must include `index` or `pack_index`. |
| Template bindings | `index`, `pack_index`, `plan_id`, authored `stage_id`, policy `source_uri`, and generated `pack_id` for input/output/digest templates. |
| Input templates | First of `r2_input_uri_template`, `input_uri_template`, `source_uri_template`, `source_uri`. With placeholders, format directly; otherwise append `/<pack_id>.jsonl.zst`. The result is `r2_input_uri` and must pass tenant storage validation. |
| Output/digest templates | `r2_output_uri_template` or `output_uri_template`; `sha256_template` unless each entry supplies `sha256`. Supply actual source paths and digests. Absent path templates generate paths under `r2://tenants/<tenant_id>/campaigns/<plan_id>/<stage_id>/input/` and `output/`. Missing byte digests are rejected; the scheduler does not fabricate source identity. |
| Manifest overrides | Non-null entry fields replace generated values. Provide prepared `r2_input_uri`, actual `sha256`, `compressed_bytes` and `item_count`; `source_uri` replaces the generated input when no staged `r2_input_uri` is supplied. Existing lazy entries use their stored fields rather than a matching manifest entry. |
| Pack defaults | `item_count` or `items_per_pack` (positive; required), `compressed_bytes` (nonnegative; required), `est_input_tokens` (nonnegative; 512000), `est_output_tokens` (nonnegative; 128000). |
| `max_pending_packs` | Positive limit declared on stage, workload or `stream_spec`; counts pending and active packs together. |

## Return value

**200 OK** with:

| Field | Meaning |
|---|---|
| `materialized` | Integer count of packs promoted or registered in this call. |
| `stages` | Array containing `{plan_id, stage_id, materialized}` for the addressed stage. |

An eligible plan can register its first policy batch during plan admission, before you call this endpoint. Read the stream backlog after admission to establish the pending count. For example, with `lookahead_packs: 4` and `batch_size: 1`, admission can register one pack, a subsequent `{}` call adds one, and `{"force_fill":true}` then adds the remaining two. Each call's `materialized` counts only the work added by that call.

Repeated calls may add more packs as earlier work drains; they are not replay-key operations. Read the stream backlog to inspect remaining work. When automatic sealing is enabled, reaching the declared total can seal the stream in this transaction.

This call does not accept `verify_source` or perform source probes. For direct external sources, prepare and repost lazy packs through [pack registration](/run/docs/reference/streams-packs-create.md), which can verify their sources.

## Errors

| Status | Code | Meaning |
|---|---|---|
| `400` | `invalid_json`, `invalid_compute_plan` | Invalid body, unknown field, nonboolean flag or invalid generated pack. |
| `401` | `unauthorized`, `invalid_token`, `token_revoked`, `token_expired` | Supply a valid token. |
| `403` | `scope_required`, `account_suspended`, `compute_tenancy_unauthorized` | Missing scope, active account or tenant grant. |
| `404` | `compute_plan_not_found`, `compute_stage_not_found` | Plan or stage is absent or inaccessible to this account. |
| `409` | `compute_plan_conflict` | Generated pack identity, promotion or sealing conflicts with durable data. |
| `413` | `body_too_large` | Body exceeds 1 MiB. |
| `429` | `stream_backpressure` | Pack registration would exceed the pending-pack limit. Wait for work to drain. |
| `429` | `rate_limited` | Wait for `Retry-After` before retrying. |

## Examples

```sh
curl -s https://weights.fyi/run/v1/compute/plans/PLAN_ID/stages/STAGE_ID/materialize \
  -H "Authorization: Bearer $WEIGHTS_API_KEY" -H "Content-Type: application/json" \
  -d '{"force_fill":true}'
```

```json
{"materialized":8,"stages":[{"plan_id":"example-plan","stage_id":"pages","materialized":8}]}
```

## Patterns

Declare this `lazy_materializer` on the stage at admission, after uploading the actual input. The sample digest and size describe `{}` plus a newline; replace them and the count with your workload's records. `auto_seal: false` leaves sealing to the caller.

```json
{"lookahead_packs":2,"batch_size":1,"auto_seal":false,"manifest":[{"pack_id":"p0","r2_input_uri":"r2://tenants/demo/inputs/p0.jsonl","r2_output_uri":"r2://tenants/demo/results/p0.parquet","sha256":"ca3d163bab055381827226140568f3bef7eaac187cebd76878e0b63e9e442356","compressed_bytes":3,"item_count":1,"est_input_tokens":0,"est_output_tokens":0,"format":"jsonl"}]}
```

## History

- 2026-10-28: documented bounded lookahead materialization and forced fill.

## See also

- [POST /v1/compute/plans](/run/docs/reference/compute-plans-create.md)
- [GET /v1/streams/{stage_id}/packs](/run/docs/reference/streams-packs-list.md)
- [POST /v1/streams/{stage_id}/packs](/run/docs/reference/streams-packs-create.md)
