With a publishable key, the grid's page calls Gridsay directly. Each question carries your user's sign-in, so Gridsay verifies every user and counts each against the limits you set. There is no route on your server to forward questions.
Every plan includes publishable keys, the trial too.
http://localhost:3000. A publishable key has no exception for localhost./api/v1/datagrid/prompt.The key refuses every question until it has origins and a sign-in method. A publishable key can sit in your page; a secret key never can.
MUI's stock resolver cannot call Gridsay from the browser: it has no way to send a key. Use one of these as the grid's onPrompt instead.
The dashboard shows this when you choose a publishable key.
npm install @gridsay/mui-x-data-gridimport { createPromptResolver } from '@gridsay/mui-x-data-grid';import { DataGridPremium, type DataGridPremiumProps, GridAiAssistantPanel, useGridApiRef,} from '@mui/x-data-grid-premium';import { useMemo } from 'react'; export function OrdersGrid({ rows, columns }: Pick<DataGridPremiumProps, 'rows' | 'columns'>) { const apiRef = useGridApiRef(); const onPrompt = useMemo( () => createPromptResolver({ url: `${process.env.NEXT_PUBLIC_GRIDSAY_URL}/api/v1/datagrid/prompt`, publishableKey: process.env.NEXT_PUBLIC_GRIDSAY_PUBLISHABLE_KEY!, getToken: getUserToken, // your sign-in's token, or a session token from your route apiRef, }), [apiRef], ); return ( <DataGridPremium apiRef={apiRef} rows={rows} columns={columns} aiAssistant onPrompt={onPrompt} slots={{ aiAssistantPanel: GridAiAssistantPanel }} showToolbar /> );}url is your Gridsay URL followed by the prompt path; publishableKey is your key. With apiRef, the helper also tells Gridsay which features your grid has switched off and checks every answer before the grid applies it: see Using the helper.
For a page that would rather not add a package. The dashboard offers it under "Rather not add a package?". It sends the key and the sign-in as the helper does, without the helper's checks.
'use client'; import { DataGridPremium, GridAiAssistantPanel } from '@mui/x-data-grid-premium'; // Sends each question straight to Gridsay with your key and your user's sign-in.// The grid shows each thrown message in its assistant panel.async function onPrompt(query: string, context: string, conversationId?: string) { let token; try { token = await getToken(); } catch { token = null; } // No signed-in user: ask nothing. if (!token) throw new Error('Sign in to use the assistant.'); const response = await fetch('https://api.gridsay.com/api/v1/datagrid/prompt', { method: 'POST', headers: { 'content-type': 'application/json', 'x-api-key': 'pk_gs_example_not_a_real_key', authorization: `Bearer ${token}`, }, body: JSON.stringify({ query, context, conversationId }), }).catch(() => null); // No answer, or not JSON (an error page from a proxy): one plain sentence. const result = await response?.json().catch(() => null); if (!result?.ok) throw new Error(result?.message ?? 'The assistant couldn’t respond. Try again.'); return result.data;} // Keep your rows and columns; put this in your client component's return value.<DataGridPremium rows={rows} columns={columns} aiAssistant onPrompt={onPrompt} slots={{ aiAssistantPanel: GridAiAssistantPanel }} showToolbar/>Replace getToken() with your sign-in's token. With no token it sends nothing and the panel shows "Sign in to use the assistant." Every failure becomes a sentence the panel shows.
Gridsay needs a credential from your app's sign-in with every question, not your Gridsay console sign-in.
getToken returns the token your sign-in provider issued. The helper sends it as Authorization: Bearer …. Refresh it through your provider when it expires.expiresAt rather than minting one per question.authorization, leave out getToken and send the header with headers:createPromptResolver({ url: 'https://api.gridsay.com/api/v1/datagrid/prompt', publishableKey: 'pk_gs_example_not_a_real_key', apiRef, headers: async () => ({ 'x-user-token': await getCredential() }),});With getToken, a missing token stops the question in the browser. A headers function has no such check: an empty header reaches the gateway and is refused there. If headers throws, the helper reports unexpected_error and keeps what was thrown in the error's cause.
How to set up each method: JWT or OIDC, session tokens, identity webhook.
Each question passes these checks before any model reads it. A question refused here is free. If Gridsay recognises the key, the refusal can appear on the Usage page under Refusals. That list shows the last seven days.
| Check | When it fails | Status and code | Your user sees |
|---|---|---|---|
| The key | Missing, mistyped, disabled or revoked | 401 invalid_api_key | The assistant is not available right now. |
| The origin | The page's origin is not on the key's list, or the list is empty | 403 origin_not_allowed | The assistant is not available on this site. |
| A sign-in method | The key has none | 403 forbidden | The assistant is not available right now. |
| The credential | Missing, expired, or not verified by the method you chose | 401 unauthenticated_user | Sign in to use the assistant. |
| Failed sign-ins | Too many failed checks from one address | 429 rate_limited | Too many attempts. Try again in N seconds. |
| Your limits | The user or the key reached a limit you set | 429 rate_limited | Your rule's message, or a default with when to try again |
| Your plan | No plan, the trial's allowance, or your spending cap | 402 quota_exceeded or billing_limit_exceeded | The assistant is not available right now, or has reached its limit |
Limits are set per key and per user under Auth and limits. A rule can show its own message at the limit, for example a link to your upgrade page.
apiRef: also the features your grid has switched off, each column's limits, option lists and the current filters, sorting, grouping, totals and pivot.No whole rows are sent. Example values from your rows go only if you turn on allowAiAssistantDataSampling or write them into your columns.
Each answered question appears under Requests on the Usage page, with the user it was counted against.