Framework Handlers
- Next.js
- Remix
- TanStack Start
Options
CreateAssistantTokenHandlerOptions
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
appId | string | Yes | — | Your app ID from the dashboard |
apiKey | string | No | process.env.MWAI_API_KEY | Your API key |
apiUrl | string | No | https://api.modifywithai.com | API endpoint |
getEndUserId | (request: Request) => Promise<string | null> | No | Auto-generate | Function to get user ID |
Request Body
The handler expects a POST request with JSON body:Response
Success (200):Examples
Basic
With Authentication
Custom API URL
User ID Handling
The handler determines the user ID in this order:getEndUserIdfunction — If provided, calls it with the request- Request body — Uses
endUserIdfrom the POST body - Auto-generate — Creates an anonymous ID prefixed with
autogen_
Error Handling
The handler returns appropriate HTTP status codes:| Status | Cause |
|---|---|
| 200 | Success |
| 400 | Invalid request body |
| 401 | Invalid API key |
| 500 | Server configuration error or API failure |
Security
- API key stays server-side — Never exposed to the browser
- Tokens are short-lived — Expire in minutes
- Tokens are scoped — Only valid for the specified app and user