Skip to content

API Reference

Layerr exposes a comprehensive HTTP API with 135 routes across 8 categories. All routes flow through the central server (server.ts) and are protected by gateway middleware unless otherwise noted.

All API responses follow a consistent envelope:

{
"data": { ... },
"meta": {
"requestId": "uuid",
"timestamp": "2026-01-15T10:30:00Z",
"workspaceId": "workspace-slug"
}
}

Error responses include:

{
"error": {
"code": "PROVIDER_UNAVAILABLE",
"message": "All providers in fallback chain exhausted",
"details": { "attempts": 3, "providers": ["openai", "anthropic", "ollama"] }
}
}

All routes (except health checks) require a valid workspace API key passed via the Authorization: Bearer <key> header. Keys are validated by the gateway middleware (security/gateway/middleware.ts).

Per-workspace rate limits are enforced by the gateway:

TierRequests/minuteBurst
Free6010
Standard30050
Enterprise2000200

These routes implement the OpenAI API specification, allowing existing clients to use Layerr as a drop-in replacement.

RouteMethodDescription
/v1/chat/completionsPOSTMain chat completions endpoint. Accepts OpenAI-format requests, routes through Layerr intelligence
/v1/modelsGETList available models across all configured providers
/v1/models/{model}GETGet details for a specific model

Request body (OpenAI-compatible with Layerr extensions):

{
"model": "layerr-auto",
"messages": [{"role": "user", "content": "Write a React component"}],
"stream": true,
"layerr": {
"strategy": "quality",
"fallback": "relaxed",
"explain": true
}
}

Layerr extensions (all optional):

FieldTypeDescription
layerr.strategystringOverride strategy: cost, speed, quality, balanced
layerr.fallbackstringFallback mode: strict, relaxed, none
layerr.explainbooleanInclude routing explanation in response headers
layerr.workspacestringTarget workspace slug (for admin keys)

RouteMethodDescription
/api/chatPOSTLayerr-native chat endpoint with full orchestration
/api/conversationsGETList conversation history
/api/conversations/{id}GETGet a specific conversation
/api/conversations/{id}DELETEDelete a conversation
/api/conversations/{id}/messagesPOSTAdd a message to a conversation

The native chat endpoint provides more control than the OpenAI-compatible route:

Request body:

{
"messages": [{"role": "user", "content": "Refactor this to TypeScript"}],
"context": {
"files": ["src/App.js", "src/types.ts"]
},
"preferences": {
"strategy": "quality",
"maxCost": 0.50,
"maxLatency": 30000
}
}

RouteMethodDescription
/api/providersGETList all configured providers
/api/providersPOSTAdd a new provider connection
/api/providers/{id}GETGet provider details
/api/providers/{id}PATCHUpdate provider configuration
/api/providers/{id}DELETERemove a provider
/api/providers/{id}/healthGETGet provider health status
/api/providers/{id}/testPOSTTest provider connectivity
/api/providers/discoverGETAuto-discover local providers (Ollama, etc.)
/api/providers/capabilitiesGETGet capability matrix for all providers
{
"id": "openai-prod",
"name": "OpenAI Production",
"type": "openai",
"baseUrl": "https://api.openai.com/v1",
"models": ["gpt-4o", "gpt-4o-mini", "o1-preview"],
"status": "active",
"health": {
"status": "healthy",
"latencyP50": 1200,
"latencyP99": 4500,
"errorRate": 0.002
}
}

RouteMethodDescription
/api/workspacesGETList workspaces
/api/workspacesPOSTCreate a workspace
/api/workspaces/{slug}GETGet workspace details
/api/workspaces/{slug}PATCHUpdate workspace
/api/workspaces/{slug}DELETEDelete workspace
/api/workspaces/{slug}/healthGETWorkspace health dashboard
/api/workspaces/{slug}/limitsGETCurrent limit usage
/api/workspaces/{slug}/limitsPATCHUpdate limits
/api/workspaces/{slug}/runtimeGETRuntime profile
/api/workspaces/{slug}/runtimePATCHUpdate runtime profile
/api/workspaces/{slug}/restrictionsGETProvider restrictions
/api/workspaces/{slug}/restrictionsPATCHUpdate restrictions

RouteMethodDescription
/api/strategiesGETList strategies
/api/strategiesPOSTCreate custom strategy
/api/strategies/{id}GETGet strategy details
/api/strategies/{id}PATCHUpdate strategy
/api/strategies/{id}DELETEDelete strategy
/api/strategies/{id}/calibratePOSTTrigger calibration for this strategy
/api/workspaces/{slug}/strategyGETGet workspace default strategy
/api/workspaces/{slug}/strategyPUTSet workspace default strategy

RouteMethodDescription
/api/tracesGETList execution traces
/api/traces/{id}GETGet trace details
/api/traces/{id}/replayPOSTReplay a trace
/api/traces/{id}/compare/{id2}GETCompare two traces
/api/traces/{id}/explainGETGet routing explanation for trace
/api/traces/{id}/economicsGETGet economic analysis for trace
/api/traces/recentGETGet recent traces (with filtering)
/api/traces/analyticsGETTrace analytics and trends
{
"traceId": "trace-uuid",
"workspaceId": "my-project",
"intent": {
"classification": "coding",
"confidence": 0.94
},
"strategy": "quality",
"routingDecision": {
"primaryProvider": "anthropic-prod",
"primaryModel": "claude-sonnet-4",
"fallbackChain": ["openai-prod", "ollama-local"],
"scores": {
"quality": 0.92,
"speed": 0.78,
"cost": 0.65
}
},
"execution": {
"attempts": 1,
"finalProvider": "anthropic-prod",
"latencyMs": 3400,
"tokensIn": 1240,
"tokensOut": 892,
"costUsd": 0.023
},
"explanation": {
"summary": "Selected Claude Sonnet for high-quality code generation",
"providerRationale": "Top quality score (0.92) for coding workloads"
}
}

RouteMethodDescription
/api/evaluation/calibrationGETGet latest calibration report
/api/evaluation/calibrationPOSTRun new calibration
/api/evaluation/calibration/historyGETCalibration history
/api/evaluation/qualityGETQuality metrics overview
/api/evaluation/quality/providersGETPer-provider quality scores
/api/evaluation/benchmarksGETList benchmark runs
/api/evaluation/benchmarksPOSTRun new benchmark
/api/evaluation/benchmarks/{id}GETGet benchmark results
/api/evaluation/codingPOSTSubmit code for evaluation
/api/evaluation/coding/{id}GETGet code evaluation result
/api/evaluation/outcomesGETExecution outcome metrics

RouteMethodDescription
/api/economics/summaryGETEconomic summary for workspace
/api/economics/providersGETPer-provider cost breakdown
/api/economics/categoriesGETCost by model category
/api/economics/simulatePOSTRun cost simulation
/api/economics/simulate/{id}GETGet simulation result
/api/economics/savingsGETSavings attribution report
/api/economics/budgetGETCurrent budget status
/api/economics/budgetPATCHUpdate budget settings
/api/economics/insightsGETEconomic insights and recommendations
{
"workspaceId": "my-project",
"monthlyBudget": 100.00,
"weeklyAlertThreshold": 60.00,
"spentThisMonth": 34.50,
"remainingBudget": 65.50,
"projectedSpend": 98.20,
"status": "healthy"
}

RouteMethodDescription
/api/admin/secretsGETList secrets (admin only)
/api/admin/secretsPOSTAdd secret (admin only)
/api/admin/secrets/{id}/rotatePOSTRotate secret (admin only)
/api/admin/guardrailsGETGuardrail policies
/api/admin/guardrailsPATCHUpdate guardrail policies
/api/admin/auditGETAudit log
/api/admin/tenancyGETTenant diagnostics
/api/healthGETSystem health check (no auth)
/api/health/detailedGETDetailed health with component status
/api/telemetryPOSTSubmit telemetry data

CategoryCountPrefix
OpenAI-Compatible4/v1/
Chat & Conversations5/api/chat, /api/conversations
Provider Management9/api/providers
Workspace Management11/api/workspaces
Strategy8/api/strategies
Execution & Traces7/api/traces
Evaluation10/api/evaluation
Economics9/api/economics
Security & Admin9/api/admin, /api/health
Total135
CodeHTTP StatusDescription
UNAUTHORIZED401Invalid or missing API key
FORBIDDEN403Insufficient permissions
WORKSPACE_NOT_FOUND404Workspace does not exist
PROVIDER_UNAVAILABLE502All providers exhausted in fallback chain
RATE_LIMITED429Workspace or provider rate limit exceeded
BUDGET_EXCEEDED402Workspace has exceeded its budget
TIMEOUT504Request exceeded timeout profile
INVALID_STRATEGY400Requested strategy does not exist
GUARDRAIL_VIOLATION400Request violates content policy
CALIBRATION_PENDING503System is recalibrating, try again later

Because Layerr implements the OpenAI API specification, it is compatible with:

  • OpenAI SDK (Python/JS), point base_url to your Layerr instance
  • LangChain, use OpenAI-compatible adapter
  • Vercel AI SDK, use createOpenAI with custom endpoint
  • Continue.dev, configure as custom OpenAI-compatible provider
  • Cursor, set API base URL in settings

API documentation generated from GitNexus route map. 135 routes indexed across 1,090 source files.