Overview
The AI Workspace API provides a general-purpose AI assistant for students to discuss study topics, get help with assignments, and organize their learning. Unlike the AI Tutor which focuses on conversational tutoring, the Workspace is designed for managing multiple study sessions and maintaining context across conversations.All endpoints require authentication. Users must be logged in to access these APIs.
Chat
POST /api/ai-workspace/chat
Send a message to the AI workspace assistant and receive a response. Messages are automatically saved to the database along with the conversation history.The chat session ID to associate this message with
The user’s message or question
Optional conversation history. Each message should have:
role: “user” or “assistant”content: The message text
The AI assistant’s response
Session Management
GET /api/ai-workspace/sessions
Retrieve all AI workspace chat sessions for the authenticated user, ordered by most recent activity. Query Parameters None required. Returns up to 50 most recent sessions. Response Returns an array of session objects:Unique session identifier
Display name for the session
ISO 8601 timestamp when session was created
ISO 8601 timestamp of last update
ISO 8601 timestamp of last message
Total number of messages in the session
POST /api/ai-workspace/sessions
Create a new AI workspace chat session.Optional name for the session (defaults to “New Study Session”)
The new session’s unique identifier
The session name
ISO 8601 timestamp
ISO 8601 timestamp
ISO 8601 timestamp
Session Details
GET /api/ai-workspace/sessions/[id]
Retrieve a specific session and all its messages. Path ParametersThe session ID
The session object with all metadata
PATCH /api/ai-workspace/sessions/[id]
Update a session’s name. Path ParametersThe session ID
The new session name
DELETE /api/ai-workspace/sessions/[id]
Delete a session and all its messages. Path ParametersThe session ID to delete
Returns true if deletion was successful
System Prompt
The AI Workspace assistant uses the following system prompt to guide its behavior:Technical Details
The AI Workspace uses Groq’s LLaMA 3.3 70B Versatile model with the following parameters:
- Temperature: 0.7
- Max tokens: 2048
Message Persistence
All messages are automatically saved to the database:- User messages are saved before calling the AI
- Assistant responses are saved after generation
- The session’s
last_message_atandupdated_attimestamps are updated with each message
Conversation History
The chat endpoint accepts amessages array to maintain context. For best results:
- Include the most recent 10-20 messages
- Each message must have
roleandcontentfields - The system automatically appends the new message to the history
Error Responses
All endpoints return standard error responses:Common Error Codes
| Status Code | Description |
|---|---|
| 400 | Bad request - Missing required fields (sessionId, message, etc.) |
| 401 | Unauthorized - User not authenticated |
| 404 | Not found - Session doesn’t exist or doesn’t belong to user |
| 500 | Internal server error - AI service error or database failure |