Skip to content

API Reference

Overview of Juca’s API surface — internal routes, Valter adapter layer, and server actions.

Juca’s API surface has three layers:

  1. Internal API Routes — ~55 endpoints in src/app/api/ serving the frontend. Many are transitional and will be replaced by direct Valter API calls.
  2. Valter Adapter (planned for v0.3) — abstraction layer for calling Valter and future backend agents via a unified interface.
  3. Server Actionssrc/actions/ for client-to-server mutations (briefing phase transitions, session management).
GroupPathEndpointsStatusPurpose
Unified/api/unified/*4ActiveHub session management and analysis
Export/api/export/*1ActivePDF export
Auth/api/auth/*1ActiveNextAuth handler
Health/api/health1ActiveSystem health check
Metrics/api/metrics1ActiveApplication metrics
Feedback/api/feedback/*2ActiveUser feedback
Chat/api/chat/*6TransitionalChat pipeline (SSE)
Analyzer/api/analyzer/*8TransitionalCase analysis pipeline
Search/api/search/*2TransitionalHybrid jurisprudence search
KG/api/kg/*14TransitionalKnowledge graph queries
Reasoning/api/reasoning/*4TransitionalIRAC extraction
Comparator/api/comparator/*2TransitionalMulti-model comparison
Reference/api/reference/*2TransitionalReference data
Citations/api/citations/*1TransitionalCitation statistics

All API routes (except /api/health) require authentication:

Production: NextAuth JWT session via auth() from @/lib/auth.

Development: Set ENABLE_DEV_AUTH=true in .env.local to bypass authentication with a dev user.

// Standard pattern in every API route
import { auth } from '@/lib/auth';
export async function GET() {
const session = await auth();
if (!session?.user) return new Response('Unauthorized', { status: 401 });
// ...
}

All JSON API responses follow a standard envelope pattern defined in src/types/api.ts:

Success:

{
"success": true,
"data": { },
"metadata": { "timestamp": "2026-02-28T...", "duration_ms": 123 }
}

Error:

{
"success": false,
"error": {
"code": "VALIDATION_ERROR",
"message": "Parameter X is required",
"details": { }
}
}

Standard error codes: VALIDATION_ERROR, NOT_FOUND, UNAUTHORIZED, INTERNAL_ERROR, SERVICE_UNAVAILABLE, RATE_LIMITED, TIMEOUT.

SSE streaming routes use a different convention:

  • event: stage — free-form progress payload (does not use the envelope)
  • event: result — uses the ApiSuccess envelope
  • event: error — uses the ApiError envelope

The API client at src/lib/api/client.ts automatically unwraps the envelope: success returns data, failure throws ApiClientError with code and details.