Introduction
The Maxw AI API provides access to AI-powered chat, metadata generation, and authentication services. The API is built on Next.js 16 App Router and uses streaming responses for real-time AI interactions.Base URL
All API requests are made to:Available Endpoints
Chat API
Stream AI responses with Claude Sonnet 4.5, supporting tools like web search, code execution, and Canvas LMS integration.
Metadata API
Retrieve information about available AI agents and their tools.
Authentication
Better-Auth endpoints for user authentication and session management.
Cron Jobs
Internal endpoint for updating Canvas LMS content index (requires bearer token authorization).
Request Format
Headers
All requests should include:Request Body
API requests expect JSON payloads. Example for/api/chat:
Response Format
Standard JSON Responses
Most endpoints return JSON with this structure:Streaming Responses
The/api/chat endpoint returns a streaming response using AI SDK’s toUIMessageStreamResponse() format. This enables real-time token streaming for AI responses.
Error Handling
Error Response Format
All errors follow a consistent structure:HTTP Status Codes
Request completed successfully
Missing required parameters or invalid formatCommon causes:
- Missing
messagesarray in chat request - Missing
chatIdparameter - Invalid message format
Authentication required or session expiredSolution: Authenticate via
/api/auth endpointsServer-side processing errorThe response includes error details when available
Rate Limiting
Rate limiting is not currently implemented at the API level. Consider implementing rate limiting for production deployments using middleware or services like Upstash Rate Limit.
Caching
The/api/metadata endpoint includes cache headers:
Geolocation Support
The chat API extracts geolocation data from request headers (provided by Vercel Edge Functions) to enable location-aware features:- Location-aware web search
- Timezone detection
- Regional context for AI responses
Agent Context
Each chat request builds anAgentContext that includes:
Authenticated user ID from session
User’s display name
User’s institution (currently hardcoded to “Harvard University”)
User’s Canvas LMS courses with assignments and content
Unique identifier for this conversation
Localized timestamp in user’s timezone
User’s timezone (extracted from geolocation or browser)
User’s country code (from Vercel geolocation)
User’s city (from Vercel geolocation)
User’s region/state (from Vercel geolocation)
Next Steps
Authentication
Learn how to authenticate requests and manage user sessions
Chat API
Explore the streaming chat endpoint and AI agent capabilities
Database Schema
Understand the data models and relationships