API Reference
REST API endpoints and integration patterns.
Overview
The LokkoLabs API uses Next.js API routes with a consistent response format. Authentication varies by endpoint type.
Base URL
https://lokkolabs.com/api
Response Format
// Success
{
"success": true,
"data": { ... }
}
// Error
{
"success": false,
"error": "Error message"
}Authentication
Two authentication modes are used:
Session Auth
For organizers, admins, and company members. Uses Supabase Auth cookies.
Cookie: sb-xxx-auth-tokenEvent Code
For attendee-facing endpoints. Event code in URL path.
/api/events/{code}/...Event Endpoints
Get Event by Code
/api/events/{code}Get event details by access code. Public endpoint for attendees.
{
"success": true,
"data": {
"id": "uuid",
"code": "FALCON-42",
"name": "Team Building Event",
"phase": "training",
"startedAt": "2024-01-15T10:00:00Z"
}
}Join Event
/api/events/{code}/joinRegister as an attendee for an event.
{
"name": "John Smith",
"email": "john@example.com",
"experienceLevel": "beginner"
}{
"success": true,
"data": {
"attendeeId": "uuid",
"codename": "Shadow Falcon",
"agentNumber": 42,
"coverJob": "Artisanal Cheese Whisperer",
"teamColor": "red",
"teamTable": 1
}
}Get Attendee State
/api/events/{code}/attendees/{id}Get current attendee state including phase progress.
{
"success": true,
"data": {
"id": "uuid",
"phaseStatus": "training",
"progress": 0.65,
"teamId": "uuid",
"lastActivityAt": "2024-01-15T10:30:00Z"
}
}Submit Help Request
/api/events/{code}/help-requestSubmit a help request from an attendee.
{
"attendeeId": "uuid",
"message": "Lock is stuck"
}Organizer Endpoints
Require organizer role or higher.
Advance Phase
/api/organizer/events/{id}/phaseAdvance the event to the next phase.
{
"targetPhase": "training"
}Record Team Completion
/api/organizer/events/{id}/teams/{teamId}/completeRecord a team's mission completion time.
{
"completionTime": 127.5
}Get Event Dashboard
/api/organizer/events/{id}/dashboardGet comprehensive event state for control center.
- • Event details and current phase
- • All teams with attendee lists
- • Pending help requests
- • Phase timing information
Admin Endpoints
Require admin role or higher.
Generate Audio
/api/admin/audio/generateGenerate TTS audio for scripts.
{
"scripts": ["briefing-intro", "training-start"],
"generateSegments": true
}Create Company
/api/admin/companiesCreate a new company.
{
"name": "Acme Corp",
"slug": "acme-corp",
"ownerEmail": "owner@acme.com"
}Content Endpoints
Get Phase Content
/api/events/{code}/content/{phase}Get content segments for a phase.
{
"success": true,
"data": {
"segments": [
{
"id": "uuid",
"type": "intro",
"title": "Welcome to Training",
"audio": {
"url": "https://...",
"duration": 45.2,
"pauseAfter": 3
}
}
]
}
}Real-Time Events
Real-time updates use Supabase Realtime channels:
| Event | Channel | Payload |
|---|---|---|
| phase_change | event:{code} | newPhase, timestamp |
| team_complete | event:{code} | teamId, completionTime, rank |
| help_request | organizer:{eventId} | attendeeId, message, team |
| audio_play | event:{code} | clipId, timestamp |
Subscribing
const channel = supabase
.channel(`event:${eventCode}`)
.on('broadcast', { event: 'phase_change' }, (payload) => {
setCurrentPhase(payload.newPhase);
})
.subscribe();
// Cleanup
return () => {
supabase.removeChannel(channel);
};Error Codes
| Status | Error | Meaning |
|---|---|---|
| 400 | INVALID_REQUEST | Missing or invalid parameters |
| 401 | UNAUTHORIZED | Not authenticated |
| 403 | FORBIDDEN | Insufficient permissions |
| 404 | NOT_FOUND | Resource doesn't exist |
| 409 | CONFLICT | State conflict (e.g., already joined) |
| 500 | SERVER_ERROR | Internal server error |
Rate Limits
API endpoints have rate limits to prevent abuse:
| Endpoint Type | Limit | Window |
|---|---|---|
| Public (event join) | 10 requests | per minute |
| Authenticated | 100 requests | per minute |
| Audio generation | 50 requests | per hour |
Next Steps
- Review the Architecture for system design
- Explore the Audio System
- Read the Organizer Guide for practical usage