POST https://api.gridsay.com/api/v1/datagrid/prompt answers questions from MUI X Data Grid and TanStack Table. You send the question and your columns; the answer is the complete state for the table to apply: filters, sorting, grouping, totals, pivot, chart and selection. It never contains rows or computed values.
people in Germany or France earning over 100k
filter country is any of Germany, Francefilter salary is greater than 100000The same question over HTTP:
curl https://api.gridsay.com/api/v1/datagrid/prompt \ --header 'Content-Type: application/json' \ --header 'x-api-key: sk_gs_FAKE_EXAMPLE_DO_NOT_USE' \ --data-binary @- <<'JSON'{ "query": "people in Germany or France earning over 100k", "context": "[{\"field\":\"country\",\"type\":\"string\",\"allowedOperators\":[\"equals\",\"isAnyOf\"]},{\"field\":\"salary\",\"type\":\"number\",\"allowedOperators\":[\"=\",\">\",\"<\"]}]"}JSON// On your server: the secret key never reaches the browser.const key = process.env.GRIDSAY_SECRET_KEY;if (!key || !(key.startsWith('sk_gs_') || key.startsWith('sk_ayt_'))) throw new Error('Set GRIDSAY_SECRET_KEY to a secret key.'); const columns = [ { field: 'country', type: 'string', allowedOperators: ['equals', 'isAnyOf'] }, { field: 'salary', type: 'number', allowedOperators: ['=', '>', '<'] },];const response = await fetch('https://api.gridsay.com/api/v1/datagrid/prompt', { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-api-key': key }, body: JSON.stringify({ query: 'people in Germany or France earning over 100k', context: JSON.stringify(columns), }), // A redirect would send your key to another address. redirect: 'error',});const answer = await response.json();if (!answer.ok) throw new Error(answer.message);console.log(answer.data.filters);HTTP 201. The filters are the recorded answer; conversationId and the meta values are examples, since they depend on your key and your organization's usage:
{ "ok": true, "data": { "select": -1, "filters": [ { "column": "country", "operator": "isAnyOf", "value": ["Germany", "France"] }, { "column": "salary", "operator": ">", "value": 100000 } ], "aggregation": {}, "sorting": [], "grouping": [], "pivoting": {}, "chart": null, "conversationId": "00000000-0000-4000-8000-000000000001" }, "meta": { "tier": "fast", "usedQueries": 12, "remainingQueries": 7988, "resetAt": "2027-01-01T00:00:00.000Z" }}Authenticate as in Authentication. The examples use a secret key, so they run on your server. If that key has allowed origins, add one of them as an Origin header, or the call is refused with 403.
Gridsay uses grid.table and referenceId for usage records. The model receives:
context: every property of every column, examples included, and any other property you add;grid.disabled: the features your table has switched off;grid.columns: restrictions, and each select column's options, values and labels;grid.state: the current filters with their values, the sorting, grouping, totals and pivot;No rows are sent otherwise. The table packages decide what goes in: the TanStack Table plugin and the MUI X helper send the columns, option lists and current view (the MUI X helper only when you give it apiRef), with example values only when you turn them on; MUI's own resolver sends the question and the column definitions.
A JSON object. Fields the endpoint does not know are dropped, so a field such as tier or rows changes nothing.
| Field | Type | Meaning and limits |
|---|---|---|
query | string, required | 1 to 8,000 characters. The user's question. |
context | string, required | At most 1,000,000 characters. Your columns, below, as one JSON string: JSON.stringify(columns). |
conversationId | string or null, optional | At most 255 characters. The last answer's id, to ask a follow-up. See Follow-up questions. |
options | object or null, optional | The settings below. |
additionalContext | string, optional | At most 20,000 characters. The older place for notes; options.additionalContext wins when both are sent. |
grid | object, optional | What the table can do and shows now. See grid. |
| Field | Type | Meaning and limits |
|---|---|---|
privateMode | boolean, optional | Left out means false. Keeps no question, answer or conversation. See Private mode. |
additionalContext | string, optional | At most 20,000 characters. Notes for the assistant: units, the words your users use. |
metadata | object, optional | Holds referenceId. |
metadata.referenceId | string, optional | At most 127 characters. Your id for the user, for usage reports. On a publishable key, the signed-in user's id takes its place. |
Describe each column once.
const columns = [ { field: 'name', type: 'string', description: null, examples: [], allowedOperators: ['contains'] }, { field: 'salary', type: 'number', description: 'Annual base salary in USD' },];const body = { query: 'highest salary first', context: JSON.stringify(columns) };| Field | Type | Meaning |
|---|---|---|
field | string, required | The column's id. Answers name columns by it. |
description | string or null, optional | What the column means, with its unit. |
examples | array, optional | Sample values you choose to share. They go to the model. |
type | string, optional | The column type, such as string, number, date, dateTime, boolean or singleSelect. |
allowedOperators | array of strings, optional | The filter operators the column accepts. Left out, any; empty, none. |
derivedFrom | string, optional | Marks a pivot-only column made from another, such as the year of a date. |
Other properties of a column are kept and go to the model with it. Use distinct, real column ids.
grid tells the assistant what your table allows and what it shows. The MUI X helper (with apiRef) and the TanStack Table plugin send it for you.
{ "query": "Only the paid ones", "context": "[{\"field\":\"status\",\"type\":\"singleSelect\",\"allowedOperators\":[\"is\",\"not\",\"isAnyOf\"]}]", "conversationId": null, "options": { "privateMode": false, "additionalContext": "Invoices are in EUR.", "metadata": { "referenceId": "example-user-123" } }, "grid": { "table": "tanstack-table", "disabled": ["aggregation", "pivoting", "charts"], "columns": { "status": { "sortable": false, "options": [{ "value": "paid", "label": "Paid" }, { "value": "pending", "label": "Pending" }] } }, "state": { "filters": [], "sorting": [] } }}| Field | Type | Meaning and limits |
|---|---|---|
table | string, optional | mui-x or tanstack-table. Labels your usage only; left out means mui-x. |
disabled | array of strings, optional | Features switched off: filtering, sorting, grouping, aggregation, pivoting, selection, charts. See What the answer is checked against. |
columns | object, optional | Restrictions per column, keyed by column id (at most 255 characters). List only columns with a restriction or options. |
state | object, optional | The current view, below. When sent, it wins over the conversation, and a part left out counts as empty. |
| Field | Type | Meaning and limits |
|---|---|---|
filterable | boolean, optional | false: the column cannot be filtered. |
sortable | boolean, optional | false: the column cannot be sorted. |
groupable | boolean, optional | false: the column cannot be grouped. |
pivotable | boolean, optional | false: the column cannot be used in a pivot. |
aggregable | boolean, optional | false: the column gets no total. |
aggregationFunctions | array of strings, optional | The only functions the column accepts. At most 32, each at most 64 characters. |
options | array, optional | A select column's choices, at most 500. Helps match what users type to the stored value; a value outside the list is not always refused. |
options[].value | string or number, required | The stored value. Text at most 255 characters. |
options[].label | string, required | What the user sees. At most 255 characters. |
The current view, in the answer's shape, without select and chart. It is checked for shape, not against your columns: send what the table really shows.
| Field | Type | Meaning |
|---|---|---|
filters | array, optional | Current filters. |
filters[].column | string, required | A column id. |
filters[].operator | string, required | The filter operator. |
filters[].value | string, number, boolean or array, required | The value. A list is all text or all numbers. |
filterOperator | string, optional | and or or. Left out, the filters combine with and. |
sorting | array, optional | Current sort keys, most important first. |
sorting[].column | string, required | A column id. |
sorting[].direction | string, required | asc or desc. |
grouping | array, optional | Current group columns, outermost first. |
grouping[].column | string, required | A column id. |
aggregation | object, optional | Current totals: column id to avg, sum, min, max or size. |
pivoting | object, optional | The current pivot, or {}. |
pivoting.rows | array of strings, required | Columns down the side. |
pivoting.columns | array, required | Columns across the top. |
pivoting.columns[].column | string, required | A column id. |
pivoting.columns[].direction | string, required | asc or desc. |
pivoting.values | array, required | The measures: column id to avg, sum, min, max or size. |
The three pivoting fields are required in a pivot; {} means no pivot.
HTTP 201. The answer is the whole state, never a patch: every part is there except filterOperator. The table below says how each part is applied.
| Field | Type | Meaning |
|---|---|---|
ok | boolean, required | Always true on an answer. |
data | object, required | The state to apply, and the conversation id. |
data.select | integer, required | -1 means no rows are requested. The TanStack Table plugin leaves the existing selection alone. With a positive N, the plugin selects the first N loaded data rows in sorted order, including rows on later pages or in collapsed groups. The MUI X Data Grid helper with apiRef selects the first N sorted leaf rows that pass the filters. Selection does not hide rows. |
data.filters | array, required | The filters. Empty clears filtering. |
filters[].column | string, required | A column id from context. |
filters[].operator | string, required | One of the column's allowedOperators, when you sent them. |
filters[].value | string, number, boolean or array, required | The value to compare with. A list is all text or all numbers. |
data.filterOperator | string, optional | Only or, and only to combine two or more filters with or; absent means and. Values are and or or. |
data.sorting | array, required | Sort keys, most important first. Empty clears sorting. |
sorting[].column | string, required | A sortable column. |
sorting[].direction | string, required | asc or desc. |
data.grouping | array, required | Group columns, outermost first. Empty clears grouping. |
grouping[].column | string, required | A groupable column. |
data.aggregation | object, required | Totals: column id to avg, sum, min, max or size (a row count). Empty clears totals. |
data.pivoting | object, required | {} for no pivot, or a pivot with the three fields below. Never null. |
pivoting.rows | array of strings, required | Columns down the side. |
pivoting.columns | array, required | Columns across the top. |
pivoting.columns[].column | string, required | A column id. |
pivoting.columns[].direction | string, required | asc or desc. |
pivoting.values | array, required | The measures, one per entry: column id to avg, sum, min, max or size. |
data.chart | object or null, required | null, or what the table's chart shows. It does not choose a chart type. |
chart.dimensions | array of strings, required | Category or time columns. |
chart.values | array of strings, required | Measured columns. |
data.conversationId | string, required | Send it with the next question to ask a follow-up. |
meta | object, required | The tier and the period's usage. |
meta.tier | string, required | The tier that answered and was charged: fast, standard or max, never auto. |
meta.usedQueries | integer, required | Charged questions in your organization this period, all keys together. |
meta.remainingQueries | integer or null, required | Questions the remaining credits cover at this answer's tier. null during a trial or with no ceiling. |
meta.resetAt | string, required | When the period ends, as an ISO time in UTC. |
TanStack Table applies filters, sorting, grouping and selection. Its plugin switches off totals, pivots and charts in grid.disabled.
Before it is returned, the answer is checked against your columns and grid:
allowedOperators, or a switched-off feature such as charts or sorting: the model gets one chance to correct it. If the answer is still wrong, your user gets a refusal (422, charged) with the reason, such as "Sorting is switched off for this table."selection switched off, select comes back as -1 without an error. The TanStack Table plugin keeps the existing selection.When the assistant cannot do what was asked with your table, it answers HTTP 422 with a sentence for your user. Nothing changes in the table.
people who earn more than their manager
I can't compare a person's salary with their manager's, because the grid has no manager column and cannot compare two columns.
Your user reads this sentence. The table stays as it was.{ "ok": false, "statusCode": 422, "code": "query_not_understood", "message": "I can't compare a person's salary with their manager's, because the grid has no manager column and cannot compare two columns.", "detail": "The question could not be applied to this table. Check the columns and enabled features sent by your resolver. Request 00000000-0000-4000-8000-000000000002; find it at /app/usage."}Show message. A refusal is charged, like an answer; it has no data or meta, so keep the conversation id you had. See What is charged.
| Status | Code | Charged | Send again unchanged? |
|---|---|---|---|
| 201 | Yes | It is a new question, charged again. | |
| 400 | invalid_request | No | No: fix the field detail names. |
| 401 | invalid_api_key, unauthenticated_user | No | No: fix the key or the user's token. |
| 402 | quota_exceeded, billing_limit_exceeded | No | Not until the plan or credits change. |
| 403 | origin_not_allowed, forbidden | No | No: fix the origin or the key's sign-in. |
| 404 | not_found | No | No: fix the path. |
| 413 | context_too_large | No | No: send less. |
| 422 | query_not_understood | Yes | It is charged again; let the user ask differently. |
| 429 | rate_limited | No | Yes, after retryAfter seconds. |
| 502 | upstream_unavailable | No | Yes, once, after a short wait. |
| 503 | upstream_unavailable | No | Yes, later. |
| 500 | internal_error | Maybe | Check Usage first: a 500 can come after the question was charged. |
What each code means: Errors.
| What | Limit | Over it |
|---|---|---|
| The whole body | 2 MB (2,097,152 bytes) | 413 context_too_large |
context | 1,000,000 characters | 413 context_too_large |
| What the first model call for the question is sent: our instructions, your columns, notes, current view, the question and the history that fits | 73,728 bytes | 413 context_too_large, with the size in detail |
query | 8,000 characters | 400 invalid_request |
All limits: Limits.