Assembly: the request, the estimate and the job resource
POST /api/v1/dmgen/assemble/ builds a model from a tree of reused and new components; this page is the path a script or an agent takes, and sdcmodeler (see the MCP servers) is its client. Around it are two more endpoints: an estimate before any money moves, and one job to poll while the long work runs (both since 4.17.0). Authentication is a session or an API key (Authorization: Token sdcs_...; see API Keys). Prices are in credits, at 1,000 per dollar (see Wallet and Billing).
The request
{"title": "Vitals",
"description": "Bedside observations",
"data": {"label": "Vitals",
"components": [{"ct_id": "abc123abc123abc123abc123"},
{"label": "Pulse", "data_type": "XdCount", "description": "Beats per minute", "units": "beats/min"}],
"clusters": [{"label": "Context", "components": [{"label": "Note", "data_type": "XdString"}], "clusters": []}]},
"contextual": {"party": {"ct_id": "..."}},
"allow_retired": false,
"publish": true, "generate": true,
"estimate_id": "7f3a9c1e2b4d"}
| Field | |
|---|---|
title |
required, at most 255 characters; the model's title |
description |
optional; "" is the same as leaving it out |
data |
the model's root cluster: label (required, at most 110), optional ct_id to reuse a published cluster as the root, components and clusters (nested to any depth, each with the same shape) |
| a component | {"ct_id": ...} to reuse a published component, or {"label", "data_type"} to mint one, with optional description and units ("" means none). data_type is a type name such as XdString, XdCount, XdQuantity |
units_ct_id |
on a new XdCount, XdQuantity, XdFloat or XdDouble: a published Units component to attach as it is (the quantified list types hold their units as a label, units) |
seq |
on a new component or cluster, with infer: false: its place in its cluster, 1 to 4 digits (stored zero-padded, "3" as 0003). Components and clusters are ordered by seq, then by label; a reused one keeps its own |
a cluster's description |
optional, on a new cluster: its description |
reference_ranges |
on a new ordered component (XdOrdinal, XdTemporal, the quantified types and quantified lists): a list of published ReferenceRange ct_ids to attach |
contextual |
optional component references for the model's audit, attestation, party, subject, provider, participation, protocol, workflow and acs, each a component reference as above |
allow_retired |
true accepts a retired component; otherwise one is refused with 409 naming its successor when it has one |
publish, generate |
see below; both default to true |
infer |
default true; false makes each new component as it was sent, in draft, with no automated additions; see Bare drafts. Needs publish: false |
estimate_id |
the id of the estimate the person saw; see below |
deliver |
optional list of what the run hands back once the model is published: package, app:lightweight, app:enterprise, kit; empty or absent builds only. Needs publish and generate; see Build and deliver |
The answer is 200 with the model when every component exists (mode: reuse), or 202 with a job when something must be minted (mode: mixed). The errors:
| Status | When | Body |
|---|---|---|
400 |
the tree is malformed: a component without ct_id or label and data_type, a cluster without a label |
{"error": "Invalid request", "details": {...}}; the estimate refuses it the same way |
400 |
a units_ct_id or reference_ranges that is not published, not the right kind, or on a type that does not take it, or on a reused component; with infer: false, a data_type SDCStudio does not make or a Units label where a Units component is needed |
{"error": "Invalid component references", "errors": [{"path", "reason", "ct_id"?}]}, before anything is funded; the estimate lists the same under problems |
402 |
the run cannot be funded as a whole, deliverables included, even with the reloads auto-reload may make | error_type: insufficient_funds, with estimated_cost_credits, balance_credits, shortfall_credits, wallet_url and reason (see Funding the run) |
403 |
the key lacks a scope, or the charge would pass its limit | error_type: key_scope (with scope and the key's scopes) or key_spend_limit (with the numbers); see API Keys |
409 |
the estimate_id no longer matches the title, the tree and deliver, or a retired component without allow_retired |
error_type: stale_estimate, or {"error": ...} naming the retired component |
409 |
on the synchronous path (every leaf reused, or infer: false), a model with this title already exists in the project; refused before anything is funded (the pipeline path instead names the new model "Title (2)") |
error_type: title_taken; the estimate lists it under problems |
The estimate and assemble/ are writes, so a key needs Build to call either; a key that only reads is refused with 403 key_scope.
The estimate
POST /api/v1/dmgen/assemble/estimate/ takes exactly the body assemble/ takes and builds nothing and charges nothing. It resolves every leaf the way assemble/ will: a ct_id that names a published component is reused and free; a label with a data_type is minted at 100 credits; a new cluster below the root is minted at 100 credits too; and with publish (the default), each new component and cluster costs 100 more to publish (publish_credits). The model itself is 500 credits, and that includes its root data cluster, the model's own data cluster, and the model's publication. The estimate's total is exactly what assemble/ charges, on either path (one rule since 4.17.5).
{"title": "Vitals",
"data": {"label": "Vitals",
"components": [{"ct_id": "abc123abc123abc123abc123"}, {"label": "Pulse", "data_type": "XdCount"}],
"clusters": []}}
answers
{"estimate_id": "7f3a9c1e2b4d",
"mode": "mixed",
"reuse": [{"path": "data.components[0]", "ct_id": "abc123abc123abc123abc123", "label": "Blood Pressure", "type": "XdQuantity"}],
"mint": [{"path": "data.components[1]", "label": "Pulse", "data_type": "XdCount"}],
"problems": [],
"model_credits": 500, "mint_credits": 100, "publish_credits": 100, "total_credits": 700, "total_usd": "0.70",
"wallet": {"balance_credits": 9400, "can_pay": true},
"key": {"scopes": ["build", "read", "spend"], "can_spend": true, "spend_limit_credits": 5000, "spent_credits": 0, "remaining_credits": 5000, "within_limit": true}}
problemsnames whatassemble/would refuse: act_idthat is unknown or not published, or a retired component (with its successor when there is one;allow_retired: trueaccepts it). A malformed tree never reaches the estimate: it is refused with400, as above.keyis what the calling API key may do and whether this build fits its remaining limit;nullwhen the call was not made with a key.wallet.can_payis the balance against the total.- With
deliver, the estimate addsdeliver(the list, in a fixed order),deliver_credits(1,500 once when it holds an application or a kit, 0 for a package alone),build_credits, andtotal_creditsincluding both. will_publishnames everything the run will publish, which is permanent: each new component and cluster, the root cluster and the model, and theprojectthey land in (ct_id,name,public).fundingis how the run would be paid:balance_credits,shortfall_credits,covered, andauto_reload(enabled,confirmed,card_saved,amount_usd,monthly_max_usd,remaining_this_month_usd,reloads_needed,reload_total_usd). When the run is not covered,blocked_reasonis thereasonassemble/would give.auto_spendis whether the calling key may run without a person approving each estimate, andwithin_key_limitwhether the total fits the key's remaining limit (with a key only).modeis the pathassemble/will take:reusewhen every component (every leaf) exists, soassemble/builds synchronously, andmixedwhen a component must be minted, so the pipeline runs and a job is returned. A new cluster alone does not make an assembly mixed: a tree whose leaves all exist but which adds a new nested cluster is built on the reuse path and still charged 100 for that cluster, and 100 more to publish it.
estimate_id is the first twelve hex characters of the SHA-256 of the canonical JSON of {"title": ..., "tree": ...} (keys sorted, no whitespace), with "deliver": [...] added when the request has deliverables. sdcmodeler computes the same value locally. Hand it back to assemble/ as estimate_id: if the title or the tree changed since the estimate, assemble/ answers 409 with error_type: stale_estimate and builds nothing. An agent that shows the person an estimate and then builds with its id cannot build something else.
The publish and generate flags
assemble/ takes two booleans, publish and generate, both true by default since 4.17.2. generate needs publish.
- Every leaf existing (
mode: reuse): the response is the model, withpublished,generatedandmodel_urlbeside the catalog fields, and for a draftbench_url, the page that opens it on the Bench. Withpublish: falsethe clusters and the model are left in draft; withgenerate: falsethe model is published but no package is built. - Something to mint (
mode: mixed): the pipeline mints the new components and leaves everything in draft, then, when it completes, the assembly's job publishes the tree bottom-up (components, clusters, the model) and builds the package as the flags asked. The job'sresultthen carriespublished,generatedand the model's links, orfinalize_errorwith what could not be published. An upload's job publishes nothing: an upload is a draft for a person to review.
One call, one job to poll, and completed means what the caller asked for: the job reads running until finalize has published and generated (steps finalizing, publishing, generating), and only then completed (since 4.17.5). If publishing or generating fails, the job ends failed, with finalize_error in its result and as its error; the model's links are in the result either way.
A cluster node with a ct_id, at the root or below it, reuses that published cluster as it is: its children are not read, and it is free, as the estimate always said. (Until the Bench's first release the synchronous path built a new cluster from the node's children instead.)
Bare drafts (infer: false)
For a person or an agent who wants a draft with only their own words in it, for a modeler to finish (the Bench page sends this). With infer: false, each new component is made from what was sent and nothing else: its label, its type, its description (the requirement), its units, units_ct_id and reference_ranges. It is the same row a per-component create makes:
- no default string lengths, true/false values or link relation, no inferred formats, and no Units made from a label;
- no semantic links on the components, the clusters or the model, and no AI call;
- a new component is never swapped for an existing one with the same label.
The run is synchronous: 200 with the model, in draft, even when components are minted; no job. The price is the same as with infer: true (500 for the model, 100 for each new component and cluster, no publication charge). infer: false needs publish: false, since a bare draft is for a modeler to finish before it is published. The estimate echoes infer.
What an assembly costs
One rule for the estimate and both paths (since 4.17.5):
- 500 credits for the model, including its root
datacluster. - 100 credits for every other new cluster, at any depth.
- 100 credits for every new component, at any depth.
- Reused components and clusters are free.
Both paths fund the whole run before anything is built (see Funding the run). The reuse path charges from the hold before it builds and refunds if the build fails. The mixed path charges from the hold when the run has made the model, and never charges for more new components than the request named.
Funding the run
Since build and deliver (design_docs/build-and-deliver-PRD.md), assemble/ funds the whole run, deliverables included, before anything is published:
- The total is checked against the calling key's remaining limit, counting what its other runs still hold, and, in an organization's project, against the member's limit. Over either, the run is refused whole (
403). - If the balance is short and auto-reload may run, the saved card is reloaded synchronously at the wallet's purchase amount, as many times as the shortfall needs, within the wallet's monthly maximum. For a run made with an API key, auto-reload must have been turned on or confirmed by the person, signed in; each reload a key triggers emails the person. Organization wallets never auto-reload.
- The total is held: a
holdrow sets it aside, each charge of the run draws from it, and what the run did not spend is released when it ends, completed or failed. A hold a stopped worker left behind is released within six hours.
Otherwise the run is refused with 402 and nothing is published or charged. reason says why: auto_reload_off, no_card, auto_reload_unconfirmed, ceiling, declined, reload_failed, organization_wallet or insufficient_funds. Reloads that went through before a later refusal stay in the wallet.
Build and deliver
With deliver, the run hands back what it made once the model is published and its package generated:
| Item | Made | Download |
|---|---|---|
package |
the model's package, built by generate |
/api/v1/dmgen/dms/<ct_id>/download_package/ |
app:lightweight |
the Django application, Lightweight profile | /api/v1/dmgen/dms/<ct_id>/download_app/ |
app:enterprise |
the Django application, Enterprise profile | /api/v1/dmgen/dms/<ct_id>/download_enterprise_app/ |
kit |
the Supabase governed data kit, checked that the model can be made into one | /api/v1/dmgen/dms/<ct_id>/supabase_kit/ |
The applications and the kit share one charge of 1,500 credits per user per model, drawn from the run's hold; the download routes then answer without charging again. On the reuse path the response carries delivered (each item's item, status, download and any error) and deliver_charged_credits. On the mixed path the job does it after publishing and generating (step delivering), and its result carries the same two fields. An item that could not be made is reported failed and not charged; the model stays published, and the job ends failed with Not delivered: ....
Omit description (on the model or a component) and units, or send them as ""; both mean none (since 4.17.5; before, "" was refused as blank).
The job resource
GET /api/v1/jobs/<ct_id>/ is one record for every long operation. Only its owner (or staff) can read it.
| Field | Meaning |
|---|---|
kind |
assemble (a mixed assembly), upload (a file for the pipeline), generate_package, generate_app |
status |
queued, running, completed, failed |
step |
where it is: the pipeline's own status for an assembly or an upload (parsing, parsed, agent_processing, modeling), then finalizing, publishing, generating and done; or the generator's step |
cost_credits |
what the job has charged so far, read from the ledger |
result |
on completion: dm_ct_id, model_url, catalog_url, package_url; an assembly job adds published, generated and, when something could not be published, finalize_error; an application job adds profile, app_name, app_url |
error |
why it failed |
data_source_ct_id, dm_ct_id |
what the job is about |
ct_id, url, created, updated |
the job itself |
GET /api/v1/jobs/ lists the caller's jobs, newest first (at most 100); ?kind= and ?data_source=<ct_id> narrow it.
Where jobs come from
- A mixed
assemble/answers202withjob_ct_idandjob_urlbeside thetask_idanddata_source_ct_idit always returned. The job reads the pipeline's state, so its status moves as the data source's does and finishes with the model's links. - An upload gets a job too, from the API (
POST /api/v1/uploader/api/data-sources/) or from the Upload page (since 4.17.5); find it withGET /api/v1/jobs/?data_source=<ct_id>. A job is created before its task is sent. - Package and application generation run inside the request by default, which is what the application expects. Send
{"async": true}(or?async=1) toPOST /api/v1/dmgen/dms/<ct_id>/generate/or.../generate_app/and the call answers202with a job instead; the work runs in the background and the job finishes with the links. A model's package is generated once, by someone who may publish it, as before.
Polling
Poll the job, not the task: a sensible cadence is a few seconds, backing off. completed carries the links; failed carries the reason. The agent reports a failed job to the person; nothing is charged for a pipeline that minted nothing.