Skip to content
MUI’s hosted AI Assistant backend shuts down at the end of 2026.Switch in two lines →
  • Products
    • AG Grid AI Toolkit Early accessThe model and the server behind the toolkit.
    • MUI X Data Grid StableThe backend for the Premium AI Assistant.
    • TanStack Table Public alphaA plugin that applies each answer to your table.
    • AG Studio Early accessA hosted backend for its assistant, not built yet.
  • How it works
  • Accuracy
  • Pricing
  • Security
  • Docs
    • Quickstart: server route
    • Quickstart: TanStack Table
    • Browser keys
    • Moving from MUI’s hosted service
    • Guide: when MUI’s service retires
Sign inStart a 7-day trial
Menu
  • Products
    • AG Grid AI Toolkit Early access
    • MUI X Data Grid Stable
    • TanStack Table Public alpha
    • AG Studio Early access
  • How it works
  • Accuracy
  • Pricing
  • Security
  • Docs
    • Quickstart: server route
    • Quickstart: TanStack Table
    • Browser keys
    • Moving from MUI’s hosted service
    • Guide: when MUI’s service retires
  • Sign in

Product

  • How it works
  • Accuracy
  • Pricing
  • Data and security

Grids

  • AG Grid AI ToolkitEarly access
  • MUI X Data Grid PremiumStable
  • TanStack TablePublic alpha
  • AG StudioEarly access

Docs

  • Quickstart: server route
  • Browser keys
  • Guide: when MUI’s service retires

Company

  • Contact
  • Terms
  • Privacy

Not affiliated with or endorsed by MUI or AG Grid. MUI and AG Grid are trademarks of their respective owners.

© 2026 Gridsay

Docs pages
Start
  • Documentation
  • How it works
  • Examples
MUI X Data Grid
  • Quickstart: server route
  • From the browser
  • Using the helper
  • Filtering
  • Sorting
  • Grouping
  • Aggregation
  • Pivoting
  • Charts
  • Row selection
  • Follow-up questions
  • Refusals and errors
  • Moving from MUI’s service
  • Reference
TanStack Table
  • Quickstart
  • Describing columns
  • Filtering
  • Sorting
  • Grouping
  • Row selection
  • Server-side data
  • Controlled state
  • Undo and reset
  • Refusals and errors
  • API reference
Keys and sign-in
  • Secret and publishable keys
  • Browser keys
  • JWT and OIDC
  • Session tokens
  • Identity webhook
  • Per-user limits
  • The console
  • Data and privacy
HTTP API
  • HTTP API
  • Authentication
  • Data Grid endpoint
  • Follow-up questions
  • Private mode
Reference
  • Errors
  • Limits
  • Tiers and credits
  • @gridsay/core
On this page

On this page

  1. Turn it on
  2. The call
  3. The lifetime
  4. What the browser sends
  5. When it fails
  6. Next
Skip to the article
Start
  • Documentation
  • How it works
  • Examples
MUI X Data Grid
  • Quickstart: server route
  • From the browser
  • Using the helper
  • Filtering
  • Sorting
  • Grouping
  • Aggregation
  • Pivoting
  • Charts
  • Row selection
  • Follow-up questions
  • Refusals and errors
  • Moving from MUI’s service
  • Reference
TanStack Table
  • Quickstart
  • Describing columns
  • Filtering
  • Sorting
  • Grouping
  • Row selection
  • Server-side data
  • Controlled state
  • Undo and reset
  • Refusals and errors
  • API reference
Keys and sign-in
  • Secret and publishable keys
  • Browser keys
  • JWT and OIDC
  • Session tokens
  • Identity webhook
  • Per-user limits
  • The console
  • Data and privacy
HTTP API
  • HTTP API
  • Authentication
  • Data Grid endpoint
  • Follow-up questions
  • Private mode
Reference
  • Errors
  • Limits
  • Tiers and credits
  • @gridsay/core

Session tokens

On this page

  1. Turn it on
  2. The call
  3. The lifetime
  4. What the browser sends
  5. When it fails
  6. Next

If your app has its own sessions and no tokens to share, your server asks Gridsay for a short-lived token for the signed-in user, with a secret key. Your page sends that token with each question. This is the Session tokens method on a publishable key.

Turn it on#

  1. Open Auth and limits, choose the publishable key, set Method to Session tokens and choose Save authentication.
  2. Create a secret key in the same organization on API keys, and keep it in your server's environment. Leave its Allowed origins empty: your server's call carries no browser origin, so a secret key with origins refuses it.
  3. Add a route on your server that asks for a token, as below, and call it from your page.

A token works on every publishable key of your organization that uses session tokens.

The call#

Your server sends:

HTTP
POST /api/v1/sessionsContent-Type: application/jsonx-api-key: <your secret key, on your server only> {  "userId": "user_123",  "attributes": { "plan": "pro", "ai_quota": 300 },  "ttlSeconds": 3600}
  • userId, required: 1 to 255 characters. A stable id from your own session: it is the user every limit counts.
  • attributes, optional: an object, at most 8 KB as JSON. Limit rules match these, such as plan or ai_quota.
  • ttlSeconds, optional: how long the token lasts, 60 to 86,400 seconds; 3,600 by default.

The whole body may be at most 16 KB. The answer, with status 200 and Cache-Control: no-store:

JSON
{  "ok": true,  "data": {    "token": "<a signed token, valid only for your organization>",    "expiresAt": "2026-12-02T21:00:00.000Z"  }}

This route checks your sign-in first and answers 401 if the user is signed out. It takes the id and attributes from your session. Set GRIDSAY_SECRET_KEY and GRIDSAY_URL on your server. If either is missing or empty, the route answers 500 before calling Gridsay.

app/api/ai-session/route.ts
import { NextResponse } from 'next/server'; export async function POST() {  const user = await getSignedInUser(); // your own sign-in  if (!user) return NextResponse.json({ error: 'Not signed in' }, { status: 401 });   const key = process.env.GRIDSAY_SECRET_KEY; // a secret key  const gateway = process.env.GRIDSAY_URL;  if (!key || !gateway) {    console.error('[Gridsay] Set GRIDSAY_SECRET_KEY and GRIDSAY_URL on your server, then restart it.');    return NextResponse.json({ error: 'Not configured' }, { status: 500 });  }  const response = await fetch(`${gateway}/api/v1/sessions`, {    method: 'POST',    headers: {      'Content-Type': 'application/json',      'x-api-key': key,    },    body: JSON.stringify({      userId: user.id,      attributes: { plan: user.plan }, // optional; your limit rules can match on these      ttlSeconds: 3600, // 60 to 86,400; default 3,600    }),      // Never follow a redirect: it would send your key to another address.      redirect: 'error',  });  // On success: { ok: true, data: { token, expiresAt } }  return NextResponse.json(await response.json(), { status: response.status });}

In the console’s version of the route, the Gridsay URL is already filled in.

The lifetime#

A token is valid until its expiresAt, with 60 seconds' allowance for clock differences. It cannot be revoked: signing a user out of your app does not end a token already issued. Choose a lifetime that suits how quickly you need a change of plan or access to take effect, since the attributes in the token stay as they were when it was issued.

You may keep a token in the page and reuse it until shortly before expiresAt. The console's page code below asks your route for a new token before every question, which is simpler but makes one more call per question.

What the browser sends#

Each question carries the publishable key in x-api-key and the token as Authorization: Bearer followed by the token. This is the console's page code for MUI X Data Grid with this method:

TSX
'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: () => fetch('/api/ai-session', { method: 'POST' })        .then((response) => (response.ok ? response.json() : null))        .then((body) => body?.data?.token),      apiRef,    }),  [apiRef],); <DataGridPremium  apiRef={apiRef}  rows={rows}  columns={columns}  aiAssistant  onPrompt={onPrompt}  slots={{ aiAssistantPanel: GridAiAssistantPanel }}  showToolbar/>

When it fails#

Status and codeWhen
403 forbiddenWhenThe token call was sent with a publishable key. It needs a secret key
403 origin_not_allowedWhenThe token call was sent with a secret key that has allowed origins, and no matching Origin or Referer
400 invalid_requestWhenThe token call's body is not valid JSON, breaks a rule above, or is over 16 KB
401 unauthenticated_userWhenA question came with no token, an expired one, or one issued for another organization. Your user sees "Sign in to use the assistant."

A refused question is not charged, and is listed under Refusals on Usage.

Next#

  • Identity webhook
  • Per-user limits
  • Secret and publishable keys