Skip to main content
Runs a calculation against a published domain. A calculation happens inside a conversation: omit conversation_id to start a new conversation, or pass one to continue an existing one.

Request

Send an Idempotency-Key header to make a request safe to retry and to poll. Since natural language requests return immediately with 202 Accepted, an Idempotency Key is required to retrieve the final result. See Limits.

Natural language input

Structured input

Structured input is a set of key: value lines — one variable per line — plus a calculate: line naming the variable to solve for. For the full grammar — values, units, tables, scenario selectors, and how omitted lines are inferred — see Input formats.

JSON input

A JSON request sets input_format to json and passes a JSON string as prompt. Like structured text, it involves no language model and runs synchronously — the result returns in the same response. For the full object — inputs, calculate, scenario, and value conventions — see Input formats.
A prompt that parses as JSON but does not match the schema returns input.invalid_input_schema; a prompt that is not valid JSON returns the transport error error_invalid_json.

Automatic detection

Set input_format to automatic — or leave it out, or pass null or "" — to let TrueMath determine from the prompt whether it is natural language, structured text, or JSON, and process it accordingly. This is the default when the field is absent.
Because the detected format governs processing, the same request behavior applies once it is resolved — a prompt detected as natural_language is processed asynchronously, while one detected as structured or json runs synchronously. Specify input_format explicitly when you already know the format and want to skip detection.

Response

The response echoes the conversation, message, and request metadata, and reports its outcome with status. A completed or error outcome returns 200 OK; an asynchronous request that is still running returns 202 Accepted with status: "in_progress". The echo of your input depends on the format. A structured request returns its result as structured_text. A natural_language request returns the natural_language reading plus the parsed input as parsed_json. A json request returns the parsed input as parsed_json. structured_text is always a key on a completed response — null for natural_language and json — while natural_language and parsed_json are present only for the formats noted above and omitted otherwise.

Completed

A completed calculation returns status: "completed" and a results object: the action taken, the scenario indexes, the activities applied, and every variable with its value, provenance, and display format. results.calculated is the id of the variable that was solved for (null when action is fetch).
Each variable’s key is its creator-defined variable name. source is user_input, calculated, or default_value, and historical indicates whether the value was carried forward from a prior scenario. value is a combined "value unit" string at full precision — the unit travels inside the value (see Units and precision). For a table, value is an array of such strings (nested for a 2-D table); see Tables. The scenario object reports the original scenario the calculation started from (0 starts a new scenario) and the current scenario the results belong to. action is one of new, extend, discard, or fetch — see Scenarios. When action is fetch, retrieve that scenario with GET /v1/conversations/:id/context.

Display formats

Each variable carries a display object. data_type selects its shape — number, table, bar_chart, or pie_chart — and the remaining fields depend on it. Two fields recur across shapes: number — a scalar or unit value.
table — a grid with per-column formats and optional row names.
bar_chart — a table presented as a bar chart.
pie_chart — a table presented as a pie chart.

Chart scaling

When a bar_chart or pie_chart is built from a table column whose cells carry different units of the same dimension — for example 3 ft, 4 in, 5 yd — the chart variable carries an optional scale companion: the same magnitudes restated in one common unit, so a client can draw bars and slices to honest geometry. value is unchanged — it remains the authoritative data and still drives labels and tooltips. These fields sit on the variable, alongside value and display, and are present only when relevant. A chart variable is in exactly one of three states:
  1. Scaledscale and scale_unit are present. Plot from scale, label the axis with scale_unit, and show the original value cell in tooltips.
  2. Incompatiblescale_incompatible and scale_types are present. There is no common axis; render a short message instead of a chart.
  3. Neither — no scale fields. The column is a single unit or unitless; plot the numeric part of each value cell directly, with the first cell’s unit as the axis unit.
The common unit is the first cell’s unit. scale values are full precision — format them with the variable’s display decimal settings, the same as value.
The bars sit at 3, 0.333, and 15 on a ft axis, while the second bar’s tooltip reads 4 in — the original authored value, not 0.333 ft. When the cells span different dimensions, no chart is drawn:

In progress

Natural-language requests will be processed asynchronously; structured-text and JSON requests run synchronously and never return in_progress. When a natural-language request is still running, the API responds with 202 Accepted, status: "in_progress" and no results:
To get the result for natural language requests, re-post the same body with the same Idempotency-Key until status is completed or error. Leave a 1–2 second gap between retries. This could take multiple retries but rarely more than 20 total. You can also poll the conversation with GET /v1/conversations/:id.

Error

A calculation that cannot complete returns status: "error" with an errors array. Each entry has a code and message, plus conditionally included args, offset, and missing fields (present only when the error uses them).
See Errors for what args, offset, and missing contain, and the full list of calculation error codes.

Transport errors

Problems with the request itself — rather than with the calculation — return a 4xx or 5xx status and a single error object: