A publishable key lets your page send questions straight to Gridsay. If you use session tokens or an identity webhook, your server still needs a route to identify the user. Every question carries your user's sign-in, so Gridsay checks who is asking and counts the question against limits you set. Your users sign in to your app as usual; they need no Gridsay account.
In the console, either choose the browser path in Setup, or open API keys, choose Create key and set Type to Publishable. List every site your table runs on under Allowed origins, such as https://app.example.com, and add http://localhost:3000 (or your development port) while you build. A key with no origins refuses every question.
Copy the key when it is shown: you will not see it again. A key created in Setup starts with limits for each user; one created on API keys has none. Secret and publishable keys covers the rest of the form.
Open Auth and limits, choose the key, and pick a Method under End-user authentication:
| Method | Use it when | Details |
|---|---|---|
| JWT / OIDC | Your sign-in provider already gives users a signed token, as Auth0, Clerk, Okta, Supabase or Firebase do | JWT and OIDC |
| Session tokens | Your app has its own sessions and no tokens. Your server asks Gridsay for a short-lived token with a secret key | Session tokens |
| Identity webhook | Your server can say who a user is from a value your page sends. Gridsay asks your server | Identity webhook |
Choose Save authentication. Until a method is saved, the key refuses every question with 403 forbidden. Saving does not contact your provider: the first real question is the test.
On the same page, under Limits, decide how many questions each user may ask a minute, an hour, a day and a month, and how many all users together may ask. Rules can give different users different limits, from a claim in their token. Per-user limits explains every field and what a user sees at a limit.
Your organization's credits still apply on top: a user limit cannot raise them.
Each question carries the publishable key and your user's sign-in:
POST /api/v1/datagrid/promptOrigin: https://app.example.comContent-Type: application/jsonx-api-key: pk_gs_FAKE_EXAMPLE_DO_NOT_USEAuthorization: Bearer <your user's token> {"query":"only remote people","context":"[…the grid's column definitions…]"}Install our helper or plugin:
npm install @gridsay/mui-x-data-gridnpm install @gridsay/tanstack-table @tanstack/react-table@^9.3.1For MUI X Data Grid you can skip the package: the console also gives you a short onPrompt function that sends the key and your user's sign-in.
The code below is what the console gives you for the JWT method, with the key filled in. getToken is yours: it returns the token your sign-in provider gave the user, and it runs before every question. When it returns nothing, nothing is sent and the answer is "Sign in to use the assistant."
'use client'; import { createPromptResolver } from '@gridsay/mui-x-data-grid';import { DataGridPremium, GridAiAssistantPanel, useGridApiRef,} from '@mui/x-data-grid-premium';import { useMemo } from 'react'; // Inside your client component, using your own rows and columns:const apiRef = useGridApiRef();const onPrompt = useMemo( () => createPromptResolver({ url: 'https://api.gridsay.com/api/v1/datagrid/prompt', publishableKey: 'pk_gs_FAKE_EXAMPLE_DO_NOT_USE', // Your end user's token, sent as Authorization: Bearer. getToken: () => getToken(), apiRef, }), [apiRef],); <DataGridPremium apiRef={apiRef} rows={rows} columns={columns} aiAssistant onPrompt={onPrompt} slots={{ aiAssistantPanel: GridAiAssistantPanel }} showToolbar/>'use client'; import { useTableAssistant } from '@gridsay/tanstack-table/react'; // table is your useTable result, with defaultColumn: assistantColumn. Full setup: /docs/tanstack-tableconst { ask, undo, pending, error } = useTableAssistant(table, { url: 'https://api.gridsay.com/api/v1/datagrid/prompt', publishableKey: 'pk_gs_FAKE_EXAMPLE_DO_NOT_USE', // Your end user's token, sent as Authorization: Bearer. getToken: () => getToken(),});The browser sends no cookies to Gridsay, so the sign-in must travel in a header your page sets. MUI X Data Grid Premium needs your own MUI X licence. For the whole page, see MUI X Data Grid from the browser or the TanStack Table quickstart.
Open your app while signed in and ask the table a question. Any answer means the key, the site and the sign-in all passed, even one that declines:
departments with more than 100 people
I can't filter on counts of people per department, since that would be a condition on an aggregate.
Your user reads this sentence. The table stays as it was.Then check that it refuses when it should:
Questions that reached the assistant appear under Requests on Usage. Questions stopped before it, by the site, the sign-in or a limit, appear under Refusals on the same page instead. Errors lists every code.