Skip to content

Valter API Adapter

The adapter layer that enables Juca to communicate with Valter’s REST API for jurisprudence search, verification, and graph analysis.

Valter is Juca’s primary backend agent — a FastAPI service hosting 23,400+ STJ decisions with search, verification, knowledge graph, and LLM capabilities.

Currently, Juca communicates with Valter indirectly through its own internal API routes that replicate some of Valter’s logic locally. The adapter layer (planned for v0.3) will provide a unified interface for calling any backend agent (Valter, Leci, future agents) directly from the orchestrator.

EndpointMethodPurposeUsed By
/v1/retrievePOSTJurisprudence search (BM25 + semantic + KG)Briefing F1, F2; Search
/v1/verifyPOSTCitation verification (sumulas, processos, ministros)Validation pipeline
/v1/graph/optimal-argumentPOSTAdversarial analysis (risks and opportunities)Briefing F3
/v1/graph/divergenciasGET/POSTMinister divergences on specific themesBriefing F3; future comparison views
/v1/graph/temporal-evolutionGETTemporal trends in jurisprudenceFuture analytics
/v1/similar_casesPOSTFind cases similar to a given caseBriefing F2
/v1/factual/*VariousFactual analysis endpointsBriefing F1
/healthGETHealth check (should return 200)Monitoring, /api/health

Valter uses API key authentication via the X-API-Key header:

SettingValue
Auth methodX-API-Key header
Env variableVALTER_API_KEY
Base URL variableVALTER_API_URL
Production URLhttps://valter-api-production.up.railway.app

Verify connectivity:

Terminal window
curl -H "X-API-Key: $VALTER_API_KEY" \
https://valter-api-production.up.railway.app/health

When the adapter is implemented, Valter responses will map to Juca blocks:

Valter EndpointJuca Block TypeTransformation
/v1/retrieve → resultsprecedentEach result becomes a precedent block with processo, ementa, ministro, turma
/v1/retrieve → summarysummaryAggregated search summary
/v1/verify → verificationBlock metadataVerification status added to existing blocks
/v1/graph/optimal-argument → risksrisk_balanceRisk/opportunity pairs with weights
/v1/similar_cases → matchesprecedent_pickerSelectable precedent cards

The adapter will implement a standard error handling strategy:

Valter ErrorJuca Behavior
401 UnauthorizedLog error, show “Backend configuration error” to user
404 Not FoundReturn empty results with appropriate message
429 Rate LimitedRetry with exponential backoff (Valter uses Redis-based rate limiting)
500+ Server ErrorShow fallback error block, log to OTel
Network timeoutCancel via AbortController (#238), show timeout message

The target adapter interface for v0.3:

// Planned — src/lib/adapters/valter.ts
interface ValterAdapter {
retrieve(params: RetrieveParams): Promise<RetrieveResponse>
verify(params: VerifyParams): Promise<VerifyResponse>
graphOptimalArgument(params: GraphParams): Promise<GraphResponse>
graphDivergencias(params: DivergenciaParams): Promise<DivergenciaResponse>
similarCases(params: SimilarParams): Promise<SimilarResponse>
health(): Promise<HealthResponse>
}

The adapter will handle authentication, error mapping, response transformation, retry logic, and timeout management in a single place — keeping route handlers and server actions clean.