The QuestMaster API is provided by the Agent Worker and accessed through the Frontend API routes. All requests require authentication via signed tokens.
- Production:
https://agent.sami-houssaini.workers.dev - Development:
http://localhost:8787
All requests require an Authorization header with a Bearer token:
Authorization: Bearer {sessionId}:{timestamp}:{signature}
Token Format:
sessionId: User session identifiertimestamp: Unix timestamp (milliseconds)signature: HMAC-SHA256 signature of{sessionId}:{timestamp}
Token Expiration: 5 minutes
Generation: Tokens are generated server-side by the frontend using NEXTAUTH_SECRET.
- Chat Requests: 30 per minute per session
- Task Operations: 60 per minute per session
Rate limit headers:
X-RateLimit-Limit: Maximum requests allowedX-RateLimit-Remaining: Remaining requestsRetry-After: Seconds until limit resets
Send a chat message to the AI Dungeon Master and receive a streaming response.
Request:
POST /agents/quest-master-agent/{sessionId}
Content-Type: text/plain
Authorization: Bearer {token}
x-timezone: America/New_York
{message text}Response: Server-Sent Events (SSE) stream
Stream Format:
data: {text chunk}
data: {"type":"metadata","tasks":[...]}
data: [DONE]
Example:
curl -X POST \
"https://agent.sami-houssaini.workers.dev/agents/quest-master-agent/user-123" \
-H "Authorization: Bearer user-123:1234567890:signature" \
-H "Content-Type: text/plain" \
-H "x-timezone: America/New_York" \
-d "Create a quest to finish my report"Response Stream:
data: Greetings, adventurer! I shall inscribe your quest into the chronicles...
data: {"type":"metadata","tasks":[{"id":"...","name":"...","XP":50}]}
data: [DONE]
Status Codes:
200: Success (streaming)400: Invalid input401: Authentication failed429: Rate limit exceeded500: Server error
Retrieve all active tasks and user statistics.
Request:
GET /agents/quest-master-agent/{sessionId}
Authorization: Bearer {token}Response:
{
"tasks": [
{
"id": "uuid",
"name": "Quest Name",
"description": "Epic fantasy description",
"startTime": "2026-01-15T14:00:00.000Z",
"endTime": "2026-01-15T18:00:00.000Z",
"XP": 50
}
],
"totalXP": 150,
"currentStreak": 5,
"longestStreak": 10,
"lastCompletionDate": "2026-01-15"
}Example:
curl -X GET \
"https://agent.sami-houssaini.workers.dev/agents/quest-master-agent/user-123" \
-H "Authorization: Bearer user-123:1234567890:signature"Status Codes:
200: Success401: Authentication failed429: Rate limit exceeded500: Server error
Retrieve completed quests and statistics.
Request:
GET /agents/quest-master-agent/{sessionId}?history=true
Authorization: Bearer {token}Response:
{
"completedQuests": [
{
"id": "uuid",
"name": "Completed Quest",
"description": "Description",
"completedAt": "2026-01-15T18:00:00.000Z",
"XP": 50
}
],
"statistics": {
"totalCompleted": 10,
"totalActive": 5,
"totalQuests": 15,
"completionRate": 66.67,
"totalXP": 500,
"avgXPPerQuest": 50,
"recentCompletions": 3
}
}Example:
curl -X GET \
"https://agent.sami-houssaini.workers.dev/agents/quest-master-agent/user-123?history=true" \
-H "Authorization: Bearer user-123:1234567890:signature"Status Codes:
200: Success401: Authentication failed429: Rate limit exceeded500: Server error
Perform direct task operations without AI interaction.
Request:
POST /agents/quest-master-agent/{sessionId}
Content-Type: application/json
Authorization: Bearer {token}
{
"tool": "createTask" | "updateTask" | "deleteTask",
"params": { ... }
}{
"tool": "createTask",
"params": {
"taskName": "Quest Name",
"taskDescription": "Epic description",
"taskStartTime": "2026-01-15T14:00:00.000Z",
"taskEndTime": "2026-01-15T18:00:00.000Z",
"XP": 50
}
}Response:
{
"success": true,
"task": {
"id": "uuid",
"name": "Quest Name",
...
}
}{
"tool": "updateTask",
"params": {
"taskId": "uuid",
"endTime": "2026-01-15T20:00:00.000Z"
}
}Response:
{
"success": true,
"task": { ... }
}{
"tool": "deleteTask",
"params": {
"taskId": "uuid",
"addXP": true // true = complete quest (earn XP), false = abandon (lose 50% XP)
}
}Response (when completing):
{
"success": true,
"narrative": "The brave adventurer ventured into the depths...",
"xpEarned": 55 // Base XP + streak bonus (if applicable)
}Response (when abandoning):
{
"success": true
}Note: When addXP: true, the quest is completed and:
- XP is added to total (base XP + 10% streak bonus if streak >= 7 days)
- A completion narrative is generated using AI
- The narrative builds on previous completion stories for coherence
- Quest is moved to completed quests history
When addXP: false, the quest is abandoned and:
- 50% of the quest's XP is deducted from total XP (minimum 0)
- No narrative is generated
- Quest is removed without being added to history
Status Codes:
200: Success400: Invalid parameters401: Authentication failed404: Task not found429: Rate limit exceeded500: Server error
interface Task {
id: string; // UUID
name: string; // Task name
description: string; // Fantasy description
startTime: Date; // ISO 8601 timestamp
endTime: Date; // ISO 8601 timestamp
XP: number; // Experience points (1-10000)
}interface CompletedQuest {
id: string;
name: string;
description: string;
startTime: Date; // ISO 8601 timestamp
endTime: Date; // ISO 8601 timestamp
completionDate: Date; // ISO 8601 timestamp
XP: number;
completionNarrative?: string; // AI-generated completion story
}interface Statistics {
totalCompleted: number;
totalActive: number;
totalQuests: number;
completionRate: number; // Percentage
totalXP: number;
avgXPPerQuest: number;
recentCompletions: number; // Last 7 days
}{
"error": "Error message description"
}400 Bad Request:
{
"error": "Task validation failed: Invalid start time format"
}401 Unauthorized:
{
"error": "Unauthorized. Invalid authentication token."
}429 Too Many Requests:
{
"error": "Rate limit exceeded. Too many requests. Please try again later."
}500 Internal Server Error:
{
"error": "Internal server error"
}The frontend provides proxy routes that add authentication and handle CORS:
Proxies chat messages to the agent.
Request: Same as agent chat endpoint Response: Same SSE stream
Proxies task retrieval.
Request: GET /api/tasks
Response: Same as agent GET endpoint
Creates a new task.
Request:
{
"taskName": "...",
"taskDescription": "...",
"taskStartTime": "...",
"taskEndTime": "...",
"XP": 50
}Updates a task.
Request:
{
"taskId": "uuid",
"endTime": "..." // optional
}Deletes a task.
Request:
{
"taskId": "uuid"
}Currently not implemented. All communication uses HTTP/SSE.
No versioning currently. All endpoints use the latest version.
- Natural language time parsing in
createTask - Retry logic for failed task creation
- Enhanced error messages
- Task timing validation