# Build with the Model API

Agos Model is the financial modeling capability of Manifold (`agos.manifold.model`). Use its hosted API to create models, run cases and read saved results from your application. Browse the public catalog or read its JSON index before signing in. [Catalog](https://model.iamagos.com/catalog/) · [Catalog JSON](https://model.iamagos.com/catalog/index.json)

## Inspect a public model

Use `by: "year"` for the default statement and Excel selection. Honor an explicit quarter or month from your user. A recipe can calculate monthly cash movements and still present annual totals and year-end balances.

Start with a GET request. The recipe index links the typed recipe contract and the worked case. The case manifest links each statement, its raw numbers and the Excel file. Public URLs support GET and HEAD. Your application can read their JSON across origins without credentials. [Recipe index](/catalog/recipes/index.json) · [Case manifests](/examples/index.json) · [Guide for agents](/docs/agents.md)

```sh
curl -fsS https://model.iamagos.com/catalog/recipes/saas_cash_runway/index.json
curl -fsS https://model.iamagos.com/examples/saas-cash-runway/index.json
```

Each case names its annual opening report in `openingStatement`. Use the supplied `inputs.sections[].url` and `dashboards[].sections[].url` to open a section in that case. The input section’s `family` joins to its label in the linked layout. [Inspect the Harbor Hotel cases](/examples/harbor-hotel/index.json)

For a worked recipe, `builder.data` lists the statement rows you can inspect. Expand the case’s `builder.rowUrlTemplate` with the statement and row IDs to link a figure. For a dependency, append each segment of its path to the Builder URL as a `node` parameter. [Trace construction draws in Project Cash Flow](/examples/single-family-development/?view=builder&report=cash_flow&line=cash_flow.construction_draws)

The featured equation and its dependencies are inline in `equations`. Extra pages contain the same `model.equation` results. Choose the last `parts[].first` whose JSON-serialized path sorts at or before the requested path in JavaScript string order. Resolve its `file` relative to `builder.data`.

Each component has a public calculation graph. Use `calculation.topics` to browse the financial calculations and their result IDs. Index `calculation.nodes` by `id` and follow the selected result’s `sources`. A source with a `url` identifies the exact output of a child component. The same node IDs open the corresponding rules in the human guide. [Trace Room Revenue](/catalog/components/hotel_room_revenue/#output-rooms_revenue)

```sh
curl -fsS https://model.iamagos.com/catalog/components/hotel_room_occupancy.json |
  jq '.calculation.nodes[] | select(.id == "step-requested_occupancy_lift") | {rule, sources}'
```

## Connect a project

Using a coding agent? Connect it to Agos over MCP, then install the Build model and Review model skills with the skills.sh CLI. [Connect via MCP](/docs/use/#use-another-mcp-client) · [Install the agent skills](/docs/use/#install-the-agent-skills)

Sign in to [My models](https://model.iamagos.com/models) to create your Agos project. To use the API from your backend, ask for a scoped project key. Include your Agos email and the access you need to read, edit or run models. Agos can issue a key for the same project you use in chat. [Request developer access](mailto:support@iamagos.com?subject=Model%20developer%20access)

Keep the key in your backend secret store. Set `MODEL_API_KEY` in the shell that runs the examples below. The HTTP examples use curl and jq.

```sh
export MODEL_URL=https://model.iamagos.com

model_call() {
  curl --fail-with-body --silent --show-error \
    -H "Authorization: Bearer $MODEL_API_KEY" \
    -H 'Content-Type: application/json' \
    --data-binary @- "$MODEL_URL/v1/$1"
}

context=$(echo '{}' | model_call model.context)
project=$(echo "$context" | jq -er '.project')
```

The response identifies the project and the operations it offers. Calls use `POST /v1/<operation>`. A successful response contains the operation result as JSON.

## Read a recipe

Search for the Hotel recipe and keep its exact reference. The `key` identifies the version selected by the service.

```sh
recipes=$(jq -n --arg project "$project" \
  '{project:$project, kind:"recipe", query:"hotel"}' | model_call catalog.list)
hotel=$(echo "$recipes" | jq -cer '.entries[] | select(.ref.id == "hotel") | .ref')

jq -n --arg project "$project" --argjson ref "$hotel" \
  '{project:$project, ref:$ref, section:"inputs", limit:5}' | model_call catalog.read
```

The result includes the total and a page of named input ports. Each port describes a value the model accepts, including its type and unit when specified. Change `section` to `outputs` to inspect calculated values. Add the number of returned ports to `offset` for the next page. Use `kind: "component"` in the search to find a reusable calculation.

## Choose a client

HTTP works with a scoped key today. Agos supplies the JavaScript and Python packages to design partners on request. Contact support for package access.

**JavaScript.** With `@agos/model` installed, run this as a Node.js module on your backend.

```js
import { Client } from '@agos/model/hosted'

const client = new Client(process.env.MODEL_URL, { apiKey: process.env.MODEL_API_KEY })
try {
  const { project } = await client.call('model.context', {})
  const page = await client.call('catalog.list', { project, kind: 'recipe' })
  console.log(page.entries.map(entry => entry.label))
} finally {
  client.close()
}
```

**Python.** The `iamagos-model-client` package includes the typed client and the `model-remote` CLI.

```python
import os
from model import catalog
from model.remote import service
from model.remote.client import Client

with Client(os.environ["MODEL_URL"], api_key=os.environ["MODEL_API_KEY"]) as client:
    context = client.call(service.CONTEXT, service.ContextRead())
    page = client.call(service.CATALOG, catalog.Selection(project=context.project, kind="recipe"))
    print([entry.label for entry in page.entries])
```

**CLI.** Inspect an operation's schema locally, then call it with the same environment as the HTTP example.

```sh
model-remote schema catalog.read
echo '{}' | model-remote call model.context --url "$MODEL_URL"
```

## Open or embed a saved case

For the hosted viewer, return the case URL from `run.list`. The URL opens the saved revision and run. The reader signs in with their Agos account. [Review a saved case](https://model.iamagos.com/docs/use/#return-to-a-saved-case)

To show the results inside your app, have your backend authorize the reader and call Model. Send the selected case data to the controlled React views in `@agos/model-ui`.

| View | React export | Data to request |
| --- | --- | --- |
| Statement | `HostedStatement` from `@agos/model-ui/statement/hosted` | Read the saved selection with `run.selection`, then page through `run.statement`. |
| Dashboard | `HostedDashboard` from `@agos/model-ui/dashboard/hosted` | Use the selected dashboard name with `run.dashboard`. |
| Inputs | `RetainedInputs` from `@agos/model-ui/input/retained` | Read saved values with `run.inputs.search`. Pass labels, formats and percentage scales from the same revision’s `model.interface` in the `presentations` map. |
| Model Builder | `EquationBuilder` from `@agos/model-ui/builder` | Read `model.equation` for the saved revision and selected statement row. |

For a case comparison, pass complete dashboard pages from the same model revision to
`compareDashboard(currentPages, basePages, 'Base')`. Pass its result as the `reading` prop on
`HostedDashboard`. Use `onMetric` to put the block and metric in your route, and pass the selected pair back as `metric`.
The host controls access to both saved cases. [Open a linked dashboard figure](/examples/harbor-hotel/?case=downside&view=dashboards&block=operating-outlook&metric=revenue)

For the complete input browser, request `model.input.layout` with the model, revision and `includeControls: true`. Pass the result to `GroupedInputs` from `@agos/model-ui/input/retained`. It keeps search matches in their authored groups. Its reader requests sorted names for the visible fields, period labels and choice lists. Return those fields from the same saved run.

For a saved comparison, `periodLink(input, caseLabel, period)` can return `{ href, label }` for a related statement figure. Resolve the row and column from that case’s retained statement. Return `undefined` when your app has no destination for a field or period. Harbor Hotel links each occupancy percentage to the corresponding year’s operating revenue. [Open the comparison](/examples/harbor-hotel/?case=y2-lift&view=inputs&input=operating.occupancy)

The details button beside a field shows its recipe description and each case’s value. Pass each case’s own input records and, when available, its set of explicitly submitted names. The hosted evaluator currently retains values and bindings. A consumer that supplies an authorized input record with evidence can also display its source references and decision rationale.

For an editable case, `onEdit(input, presentation, periods, position)` identifies the selected field and year. Pass `{ name: input.name, content }` to `GroupedInputs.editor`. Render `OverrideInput` from `@agos/model-ui/input/hosted` there with the same input, presentation and periods. Use `focusIndex={position ?? 0}` to focus the selected year.

Its change handler returns the encoded value for `run.scenario.preview`. Debounce valid edits and show figures only for the current draft. The free preview creates no run. On save, quote the same overrides with `run.scenario.quote` and submit the accepted maximum with a stable mutation ID. Return the saved case link to the person or agent who requested it.

Keep the saved case URL for collaboration. An agent can call `run.list` to discover saved cases and read the case by ID on its next turn. The current MCP connection uses request/response delivery.

For Excel, select the workbook from the successful run's manifest with `artifact.list`. The CLI downloads the workbook and verifies it. Set `WORKBOOK_ID` to the workbook entry's ID and choose a new output filename.

```sh
model-remote download "$WORKBOOK_ID" --url "$MODEL_URL" --output case.xlsx
```

To prepare a run, handle retries or prepare a workbook for an existing case, follow the [agent workflow](https://model.iamagos.com/docs/agents/).


## Present editable records and review notes

Request `includeRecords: true` and `includeControls: true` in `model.input.layout`. For an editable table, append one item to every field listed in `recordInputs` and send the complete overrides together to `run.scenario.preview`. Use the same overrides for the saved run. The React view provides `AppendRecord` for this operation.

Read `run.input.notes` with the run, field name and zero-based position of the value. Omit the position for a whole-field note. To add a note, call `run.input.annotate` with the same location, a stable mutation ID, and a `note` containing `reason` and an optional HTTPS `sourceUrl`. A source can link directly to a PDF page or spreadsheet cell. The service records the authenticated author and time. Notes are visible to readers of that project.
