Ask a question
Section titled “Ask a question”POST /api/askTurns a question into two to four tiles, runs them in parallel and returns a small dashboard. Costs 25 credits.
Common questions can cost 5 credits through POST /api/ask2/ask, which answers as a stream of UI patches. Which Ask to call compares the two.
There are two ways to receive the answer. The price, the limits and what is stored are the same for both.
| Mode | Ask for it with | You get |
|---|---|---|
| JSON | Accept: application/json, or ?stream=false |
One JSON document when the answer is finished, usually after 5 to 30 seconds |
| Event stream (default) | Nothing, or Accept: text/event-stream, or ?stream=true |
Server-sent events: each tile as soon as it is ready |
An Accept header that names both application/json and text/event-stream gets the stream. The stream parameter wins over the header.
{ "question": "Who are the highest-volume TAVR operators in Florida?" }question must be at least 5 characters. Anything past 500 characters is cut off. Nothing else in the body is read.
JSON mode
Section titled “JSON mode”curl "$OPH_API/api/ask" \ -H "Authorization: Bearer $OPH_KEY" \ -H "Content-Type: application/json" -H "Accept: application/json" \ -d '{"question": "Who are the highest-volume TAVR operators in Florida?"}'{ "id": "df706628-076f-4fa8-9797-c5f6028915ab", "question": "Who are the highest-volume TAVR operators in Florida?", "title": "Highest-volume TAVR operators in Florida", "summary": "Ranks Florida clinicians by Medicare fee-for-service TAVR services. Counts under 11 patients are withheld by CMS.", "followups": ["Which Florida hospitals do the most TAVR?"], "model": "claude-haiku-4-5", "tiles": [ { "index": 0, "type": "leaderboard", "title": "TAVR volume by operator, Florida", "x": "name", "y": "services", "format": "number", "sql": "SELECT s.npi, ... LIMIT 25", "columns": ["npi", "name", "city", "state", "services"], "rows": [{ "npi": "1234567893", "name": "Jane Example", "city": "Miami", "state": "FL", "services": 212 }], "sources": ["medicare_service", "medicare_provider"], "engine": "postgres", "ms": 41 } ], "failed": [], "sources": ["medicare_provider", "medicare_service"], "ms": 9120, "usage": { "credits": 25, "creditsUsed": 51, "creditsLimit": 100, "txid": "81260" }}| Field | Meaning |
|---|---|
id |
The stored dashboard. GET /api/dashboards/:id opens it again for free, and it is what an export refers to. null only if the answer was computed but could not be stored. |
title, summary |
How the question was read, and any limit on the answer, such as Medicare-only volumes. Show the summary. |
followups |
Up to three suggested next questions |
tiles |
The tiles that succeeded, in planned order. index is the tile’s position in the plan. See tile types. |
tiles[].sql |
The statement the model wrote for the tile. A receipt: it shows how the numbers were computed. Nothing accepts it back. |
failed |
Tiles whose statement was rejected or failed: index, title, error, sql. They are kept in the stored dashboard, so a free refresh retries them. |
sources |
Every dataset the answer read |
ms |
Total time, planning included |
usage |
The usage object for this call |
If the model cannot produce a plan, the response is 502, nothing is charged and nothing is stored:
{ "error": "The model could not plan an answer for that question. Nothing was charged.", "code": "ASK_FAILED", "charged": false }Event stream
Section titled “Event stream”Without a JSON Accept header the response is a text/event-stream. Events arrive in this order:
| Event | Count | Data |
|---|---|---|
usage |
1 | The usage object for this call. It arrives once the model has a plan, just before plan, so the first event can take several seconds. |
plan |
1 | title, summary, followups (up to 3 suggested next questions), model, ms, and tiles (each tile’s type, title, x, y, format, without its SQL) |
tile |
0 to 4 | One finished tile. Arrives in completion order, so use index to place it. |
tile_error |
0 to 4 | A tile whose statement failed: index, title, sql, error |
done |
1 | tiles (planned), failed, ms (total) and id, the stored dashboard (null only if it could not be stored) |
error |
0 or 1 | error. Sent in place of everything else when the answer cannot start; the stream then ends without done. See errors inside the stream. |
A tile event
Section titled “A tile event”event: tiledata: {"index":0,"tile":{"type":"bar","title":"TAVR volume by operator, Florida","sql":"SELECT ... LIMIT 15","x":"name","y":"services","format":"number","position":0},"columns":["name","services"],"rows":[{"name":"Jane Example","services":212}],"ms":41,"sources":["medicare_service","medicare_provider"],"engine":"postgres"}Each tile carries its own receipt: the SQL inside tile.sql, the sources it read and the engine that ran it. In the stream the tile’s fields sit under tile; in JSON mode they are flattened into the tile object.
curl -N "$OPH_API/api/ask" \ -H "Authorization: Bearer $OPH_KEY" -H "Content-Type: application/json" \ -d '{"question": "Who are the highest-volume TAVR operators in Florida?"}'-N turns off curl’s buffering so events print as they arrive. For a browser or Node client, see Stream Ask in JavaScript.
Errors inside the stream
Section titled “Errors inside the stream”Once the stream has started, the HTTP status is already 200. A failure arrives as one error event and the stream ends:
| Data | Meaning |
|---|---|
{ "error": "The model could not plan …", "code": "ASK_FAILED", "charged": false } |
No plan could be made. Nothing was charged or stored. |
{ "error": "Out of credits: …", "status": 402 } |
The balance was spent by another call between the first check and the charge. Nothing was charged and no tile ran. |
{ "error": "The answer could not be finished." } |
An unexpected failure after the charge |
Tile types
Section titled “Tile types”type |
Shape | How to draw it |
|---|---|---|
stat |
One row | Show the value in column y as a headline number. Other columns in the row are supporting figures. |
leaderboard |
A ranking of named clinicians, hospitals or groups | x is the name column, y the metric it is ranked by. Rows include an npi, ccn or group_pac_id you can pass to a lookup endpoint. |
map |
One row per state | x is state (a two-letter code), y the numeric column |
bar |
Ranked categories | x is the label column, y the numeric column |
line |
Ordered series | x and y as for bar |
table |
A detailed list | Show columns as headers. x and y are null. |
format is number, usd, percent or null, and says how to display y.
A table tile carries at most 50 rows and any other tile at most 100. The model is asked for fewer (about 15 for a bar, 25 for a leaderboard or table), but those are instructions to the model, not limits the API enforces.
When you are charged, and what is stored
Section titled “When you are charged, and what is stored”The same four steps run in both modes, in this order:
- Checks before any work. The request is rate limited (10 asks a minute per workspace, shared with the MCP
asktool) and the balance must cover 25 credits, or the answer is429or402. - The model plans. If it cannot produce a plan, the call ends: nothing is charged, nothing is stored.
- The workspace is charged, once. This happens when a plan exists and before any tile runs. If the balance was spent in the meantime the call ends with
402: no tile runs and nothing is stored. - Tiles run and one dashboard is stored. Exactly one, whether or not you are still connected. If your connection drops, the answer is still finished, charged and stored; find it with
GET /api/dashboardsinstead of asking again.
Things to know:
- A planned tile is not a guaranteed tile. The model writes the SQL, and each statement is checked before it runs. One that fails is reported (
failedin JSON mode,tile_errorin the stream) and the others still arrive. The call is still charged. - The planner is shown the tables your question needs, not all of them. A fast classifier picks the table groups (procedures, prescribing, hospitals, care sites, payers and so on) before the model plans; if a statement then reads a table that was left out, that table is added and the statement is rewritten once. Naming the thing you mean (“hospices”, “Medicare Advantage”, “trial investigators”) helps the right tables get picked.
- A tile that would double count is rewritten or withheld. Before a statement runs it is checked for a sum over a one-to-many join (a facility’s payment repeated once per owner) and for procedure volume picked by a loose text match. The model is asked to rewrite it. If the double count is still there, the tile is reported as failed with an
errorthat starts withWithheld:and no figure is shown. - A failed tile can be retried for free. It is stored with the dashboard, and refresh runs every tile’s stored statement again without calling the model.
- Tiles hold a page, not everything. A
tabletile carries at most 50 rows and any other tile at most 100. For every row a tile’s statement returns, export the tile. - Answers are kept as recent dashboards. A workspace keeps its newest 50 unsaved answers; a signed-in person can save one to keep it.
- Opening a stored answer is free.
GET /api/dashboards/:idreturns the stored rows. - There is no way to send your own SQL.
sqlfields are receipts. To change what a tile computes, ask a different question.
Answers framed for the asker
Section titled “Answers framed for the asker”When the request is made with a session token and the signed-in person has an onboarding profile, the profile is given to the model along with the question. The model is told to use it for emphasis and defaults only:
- Territory. If the question names no state, no region and does not say “national”, and the profile has a territory, the answer is filtered to those states and the summary says so. A place named in the question always wins.
- Subject. If the question says “my product”, “my market”, “my procedures” or “my drug”, or names no subject, the profile’s focus items are used. A subject named in the question always wins.
- Role. A territory rep or business developer gets named people and accounts first (a leaderboard). A sales leader or founder gets market size and where it is (a stat, a map). Marketing gets segments and counts. An analyst gets breakdowns and a detailed table.
- No numbers. The profile never supplies a figure. Every number still comes from SQL the model writes over the data tables, and that SQL passes the same checks.
Things to know:
- A request made with an API key never gets a profile. A key belongs to a workspace, not to a person, so the same question asked with a key and asked in the app can return different tiles. To get the territory with a key, name the states in the question.
- The profile does not have to be finished. It is used as soon as it holds a role, what the company sells, a focus item or a territory. A person with none of those is treated like a key.
- These are instructions to a model, not filters in code. Read
plan.summaryand each tile’ssqlto see what was applied. - The request is the same. There is no parameter that sends, overrides or turns off the profile, and the price is the same 25 credits.
- If the profile cannot be read, the question is answered without it.
Errors
Section titled “Errors”These arrive as an ordinary JSON error, in either mode, before any answer starts:
| Status | Message |
|---|---|
400 |
Body must be {"question": "..."}. |
402 |
Out of credits: … |
429 |
Too many requests. Try again in 23s. |
In JSON mode two more can follow: 502 with code: "ASK_FAILED" when no plan could be made, and 402 when the balance was spent between the first check and the charge. In the stream the same two arrive as an error event.