Connect your grid through a server route.

Your grid sends each question to a route on your server. The route adds your secret key and forwards it to Gridsay, then returns our answer to the grid unchanged. The secret key never reaches the browser, and the grid keeps using MUI’s stock resolver.

This takes about ten minutes if your grid already has the AI Assistant switched on. Moving from MUI’s hosted service? You already have the route: see the migration page for the two-line change.

Moving from MUI’s service 

Before you start.

  • A grid built with DataGridPremium from @mui/x-data-grid-premium. We test against version 9.18.0.
  • A server that can add a route. The example below is a Next.js route handler; any server that can forward a POST works.
  • A Gridsay account, on the 7-day trial or a paid plan. During the trial, Pro’s limits apply, such as up to 5 keys.

1. Create a secret key.

In the dashboard, open Keys and choose Create key. Choose the type Secret and a tier: fast is the default and suits most grids. Copy the key when it is shown: it is shown only once. The dashboard also shows your gateway address.

Put both in your server’s environment:

.env.local
GRIDSAY_URL=<your gateway address, from the dashboard>GRIDSAY_API_KEY=<your secret key>

Never put the secret key in browser code. Anyone who has it can spend your organization’s credits.

2. Check the key.

Before touching your app, send one question from a terminal. This uses one credit.

Shell
curl -s -X POST "$GRIDSAY_URL/api/v1/datagrid/prompt" \  -H "content-type: application/json" \  -H "x-api-key: $GRIDSAY_API_KEY" \  -d '{"query":"highest salary first","context":"[{\"field\":\"salary\",\"type\":\"number\",\"description\":null,\"examples\":[],\"allowedOperators\":[\">\",\"<\"]}]"}'

You should get status 201 and an answer like this:

JSON
{  "ok": true,  "data": {    "conversationId": "…",    "select": -1,    "filters": [],    "filterOperator": "and",    "aggregation": {},    "sorting": [{ "column": "salary", "direction": "desc" }],    "grouping": [],    "pivoting": {},    "chart": null  },  "meta": { "tier": "fast", "usedQueries": 1, "remainingQueries": 3999, "resetAt": "…" }}

meta.tier is the tier that answered and was charged: the key’s own, or on a key set to auto, the one a small model chose for this question.

An answer with "ok": false has a message for your users, a code, and often a detail for you. The table at the end of this page lists them.

3. Add the route.

The route forwards the whole body, including conversationId and options, and returns our response and HTTP status unchanged.

app/api/ai-assistant/route.ts
import { type NextRequest, NextResponse } from 'next/server'; export async function POST(request: NextRequest) {  const response = await fetch(`${process.env.GRIDSAY_URL}/api/v1/datagrid/prompt`, {    method: 'POST',    headers: {      'Content-Type': 'application/json',      'x-api-key': process.env.GRIDSAY_API_KEY!,    },    body: JSON.stringify(await request.json()),  });  return NextResponse.json(await response.json(), { status: response.status });}

On another server, do the same three things: forward the JSON body as it came, add the x-api-key header, and return our JSON body and status as they came. Put your own sign-in check in front of the route, as you would for any endpoint that spends money.

4. Point the grid at the route.

Use MUI’s stock resolver with the route’s path:

TSX
import { DataGridPremium, unstable_gridDefaultPromptResolver } from '@mui/x-data-grid-premium'; function onPrompt(prompt: string, context: string, conversationId?: string) {  return unstable_gridDefaultPromptResolver('/api/ai-assistant', prompt, context, conversationId);} <DataGridPremium rows={rows} columns={columns} aiAssistant onPrompt={onPrompt} />

Open the AI Assistant panel and ask something your table can answer, then a follow-up. Both appear in the request log on the dashboard’s Usage page.

Optional: tell us who the user is, or turn on private mode.

Your route can add options before it forwards the body. A referenceId (up to 127 characters) groups usage by your user in the dashboard; we store it only as a keyed hash. privateMode stops us storing the question and the answer, and turns off follow-ups.

app/api/ai-assistant/route.ts
// inside the route, before fetchconst body = await request.json();body.options = {  ...body.options,  privateMode: true,  metadata: { referenceId: currentUserId }, // your own user id};// then send JSON.stringify(body)

With a secret key, we trust your route about who the user is. To have each user verified and limited separately, use a publishable key instead.

Quickstart: browser keys 

Choosing a tier.

The tier is fixed per key. Create one key per tier if different screens need different tiers, or set a key to auto and a small model picks the tier for each question.

TierCredits per questionMedian model time in our benchmarkUse it for
fast10.92 sMost grids
accurate101.13 sScreens where a wrong answer is costly
max251.42 sTeams that want the largest model we run
auto1 or 10; 25 if the key allows max—Keys where you would rather not choose a tier

On auto, a question costs what the tier that answered costs. The small model starts together with the fast answer, so a question it leaves on fast is not delayed; one it sends up waits for it first, about a quarter of a second at the median in our measurement. On our requests it sent about one question in a hundred up, cost 1.12 credits a question on average, and did not measurably improve accuracy. New keys start on fast.

See the benchmark 

What can go wrong.

The grid shows message to your user. code and detail are for you.

StatuscodeUsual cause
400invalid_requestThe body is not what the grid sends. Check that the route forwards it unchanged
401invalid_api_keyThe key is missing, mistyped or revoked
402quota_exceededNo active plan, the trial reached its usage limit, or payment failed. Start the paid plan from the Billing page
402billing_limit_exceededYour organization reached its spending cap. Raise it on the Billing page
403origin_not_allowedThe key is locked to origins and this request came from another
413context_too_largeOver 2 MB, or column definitions over 1,000,000 characters. Turn off data sampling or shorten descriptions
422query_not_understoodThe model could not do what was asked. message says why, in a sentence for the user. This is charged
429rate_limitedToo many requests; retryAfter says how many seconds to wait
502, 503upstream_unavailableThe model providers did not answer. Not charged. Try again

Calling Gridsay from the browser instead, with each of your users verified and limited? Read the browser-keys quickstart. Want to know what each request sends and what we keep? Read the data and security page.