Skip to main content

Error Handling

All errors from Dvara use a consistent JSON envelope, regardless of the source (validation, provider, internal).

Error Envelope

{
"error": {
"message": "Human-readable description of the error",
"type": "invalid_request_error | provider_error | gateway_error",
"code": "machine-readable error code",
"param": "field name, if validation error",
"trace_id": "32-character hex trace ID"
}
}
FieldTypeDescription
messagestringHuman-readable error description
typestringError category (see table below)
codestringMachine-readable error code
paramstringField name that caused the error (validation only)
trace_idstring32-character hex trace ID for debugging

HTTP Status Codes

StatustypecodeWhen
400invalid_request_errorvalidation_errorMissing required field (e.g., model, messages)
400invalid_request_errorno_providerNo provider configured for the requested model
400invalid_request_errorinvalid_requestMalformed JSON body or invalid response_format
400invalid_request_errorunsupported_response_formatProvider doesn't support response_format
400invalid_request_errorno_capable_providerNo provider on route supports the requested format
400invalid_request_errorno_regional_providerNo provider available in the required region
400invalid_request_errorcredential_not_foundRequired provider credential is not configured
400invalid_request_errorcompliance_not_availableCompliance reports require enterprise license
400invalid_request_errorinvalid_report_typeInvalid compliance report type
400invalid_request_errormcp_not_availableMCP features require enterprise license
400pii_violationpii_detectedPII detected in request and action is BLOCK
400invalid_request_errorcontext_window_exceededContext window exceeded with no pruning strategy
402budget_exceededbudget_cap_hardHard budget limit exceeded
403guardrail_violationguardrail_blockedGuardrail violation detected (injection, jailbreak, content)
403data_residency_errordata_residency_violationRequest violates data residency policy
413input_size_errorinput_too_largeRequest exceeds input size limits (messages, length, tokens)
422invalid_request_errorschema_validation_failedOutput schema validation failed after max retries
401authentication_errorinvalid_internal_secretInvalid or missing X-Internal-Secret header
404not_found_errortenant_not_foundTenant ID does not exist
404not_found_errorapi_key_not_foundAPI key ID does not exist or belongs to another tenant
404not_found_errorroute_not_foundRoute ID does not exist
404not_found_errorroute_version_not_foundRoute version does not exist
404not_found_errorreport_not_foundCompliance report ID does not exist
404not_found_errormcp_server_not_foundMCP server ID does not exist
409duplicate_errormcp_server_duplicateMCP server ID already exists for this tenant
429rate_limit_errorrate_limit_exceededRate limit exceeded. Includes Retry-After header.
502provider_errorprovider_errorUpstream provider returned an error (4xx/5xx)
503provider_unavailableprovider_circuit_openProvider circuit breaker is open
503provider_unavailablefailover_capability_mismatchFailover blocked — no capable fallback available
500gateway_errorgateway_errorUnexpected internal error

MCP Proxy Error Codes (port 8070)

The MCP proxy uses a separate error envelope with mcp_error type. All codes are lowercased with mcp_ prefix.

StatusTypeCodeDescription
401mcp_errormcp_auth_requiredMissing Bearer token on MCP proxy request
401mcp_errormcp_auth_invalidInvalid API key
401mcp_errormcp_auth_revokedAPI key has been revoked
404mcp_errormcp_server_not_foundMCP server ID not found for tenant
503mcp_errormcp_server_unavailableMCP server is suspended or disabled
403mcp_errormcp_policy_deniedMCP request denied by policy rule
502mcp_errormcp_upstream_errorUpstream MCP server returned an error or unreachable
400mcp_errormcp_not_availableMCP proxy requires enterprise license
500mcp_errormcp_internal_errorUnexpected internal error in MCP proxy

Error Examples

Validation Error — Missing Model

curl -X POST http://localhost:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"messages": [{"role": "user", "content": "Hi"}]}'
{
"error": {
"message": "model is required",
"type": "invalid_request_error",
"code": "validation_error",
"param": "model",
"trace_id": "a6783439db1f46a6bfed511a0011e955"
}
}

No Provider Configured

{
"error": {
"message": "No provider configured for model: gpt-4o. Set gateway.providers.<name>.api-key in application.yml or as an env var.",
"type": "invalid_request_error",
"code": "no_provider",
"trace_id": "d354d2faaa5f4e14939aa8c480fb9d90"
}
}

Unsupported Response Format

{
"error": {
"message": "Ollama provider does not support response_format. Supported formats: [text]",
"type": "invalid_request_error",
"code": "unsupported_response_format"
}
}

Tenant Not Found

{
"error": {
"message": "Tenant not found: t-999",
"type": "not_found_error",
"code": "tenant_not_found",
"trace_id": "e9016783ab4c5d60c3ff042e3h3h7266"
}
}

Credential Not Found

{
"error": {
"message": "Required credential not found: provider.openai.api-key",
"type": "invalid_request_error",
"code": "credential_not_found",
"trace_id": "f1234567890abcdef1234567890abcde"
}
}

Rate Limit Exceeded

HTTP/1.1 429 Too Many Requests
Retry-After: 1
X-Trace-ID: a6783439db1f46a6bfed511a0011e955
{
"error": {
"message": "Per-key request rate limit exceeded",
"type": "rate_limit_error",
"code": "rate_limit_exceeded",
"trace_id": "a6783439db1f46a6bfed511a0011e955"
}
}

Provider Error

{
"error": {
"message": "Provider openai returned HTTP 500: internal server error",
"type": "provider_error",
"code": "provider_error",
"trace_id": "b7894561cd2e4f38a1cc820d1f1f5044"
}
}

Circuit Breaker Open

{
"error": {
"message": "Provider openai is temporarily unavailable (circuit breaker open)",
"type": "provider_unavailable",
"code": "provider_circuit_open",
"trace_id": "c8905672de3f5049b2dd931e2g2g6155"
}
}

PII Detected (Block Mode)

{
"error": {
"message": "PII detected in request — 2 entity type(s) found. Tenant policy: BLOCK",
"type": "pii_violation",
"code": "pii_detected",
"trace_id": "g0127894ab5c6d71e4ff153f4i4i8377"
}
}

Guardrail Blocked

{
"error": {
"message": "Request blocked: guardrail violation detected (INJECTION, JAILBREAK)",
"type": "guardrail_violation",
"code": "guardrail_blocked",
"trace_id": "h1238905bc6d7e82f5gg264g5j5j9488"
}
}

Input Too Large

{
"error": {
"message": "Request exceeds maximum messages limit: 150 > 100",
"type": "input_size_error",
"code": "input_too_large",
"trace_id": "i2349016cd7e8f93g6hh375h6k6k0599"
}
}

Schema Validation Failed

{
"error": {
"message": "Output schema validation failed after 2 retries: [$.name: required property missing]",
"type": "invalid_request_error",
"code": "schema_validation_failed",
"trace_id": "j3450127de8f9004h7ii486i7l7l1600"
}
}

Context Window Exceeded

{
"error": {
"message": "Estimated token count 150000 exceeds context window 128000 (no pruning strategy configured)",
"type": "invalid_request_error",
"code": "context_window_exceeded",
"trace_id": "k4561238ef9g0115i8jj597j8m8m2711"
}
}

Failover Blocked

HTTP/1.1 503 Service Unavailable
X-Gateway-Failover-Blocked: capability_mismatch
{
"error": {
"code": "failover_capability_mismatch",
"message": "Failover blocked: no fallback provider supports response_format: json_schema. Primary provider [openai] failed: upstream down"
}
}

Troubleshooting

SymptomLikely CauseFix
400 no_providerAPI key not set for the providerSet the environment variable (e.g., OPENAI_API_KEY)
401 invalid_internal_secretMissing/wrong X-Internal-SecretSet the correct gateway.internal.secret value or header
400 no_regional_providerNo provider in required regionAdd a provider in the target region to the route
400 credential_not_foundCredential missing at runtimeSet the provider API key or check SecretProvider configuration
403 data_residency_violationData residency policy violationConfigure routing to use providers in allowed regions
400 unsupported_response_formatProvider doesn't support the formatUse a different provider or remove response_format
400 no_capable_providerNo provider on the route supports itAdd a capable provider to the route
404 tenant_not_foundTenant ID does not existVerify the tenant ID via GET /admin/v1/tenants
404 route_not_foundRoute ID does not existVerify the route ID via GET /admin/v1/routes
404 route_version_not_foundRoute version does not existCheck version history via GET /admin/v1/routes/\{id\}/versions
404 report_not_foundReport ID does not existVerify the report ID via GET /admin/v1/reports
400 pii_detectedPII found and action is BLOCKRemove PII from request, or change tenant PII action to REDACT or LOG
403 guardrail_blockedInjection/jailbreak/content detectedReview prompt content; change tenant guardrail action to FLAG or LOG
413 input_too_largeRequest exceeds input size limitsReduce message count, message length, or total input tokens; increase tenant limits via metadata
422 schema_validation_failedResponse doesn't match JSON schemaReview schema config via GET /admin/v1/schemas; adjust correction prompt or increase max retries
400 context_window_exceededContext window full, no pruningReduce conversation length; configure pruning strategy via tenant metadata (guardrail.context.pruning-strategy)
402 budget_cap_hardHard budget limit exceededWait for next budget period or increase budget via PUT /admin/v1/budgets/\{id\}
400 compliance_not_availableEnterprise license not activeSet GATEWAY_ENTERPRISE_LICENSE_KEY to a valid signed JWT (see license-generator)
400 invalid_report_typeInvalid report type specifiedUse one of: SOC2, HIPAA, GDPR
400 mcp_not_availableMCP features require enterpriseSet GATEWAY_ENTERPRISE_LICENSE_KEY to a valid signed JWT (see license-generator)
401 mcp_auth_requiredMissing Bearer token on MCP proxyInclude Authorization: Bearer gw_<key> header
401 mcp_auth_invalidInvalid API key on MCP proxyVerify the API key is correct
401 mcp_auth_revokedAPI key revoked on MCP proxyGenerate a new API key
404 mcp_server_not_foundMCP server ID does not existVerify server ID via GET /admin/v1/mcp/servers
409 mcp_server_duplicateServer ID already exists for tenantUse a different server_id or check existing servers
403 mcp_policy_deniedMCP request denied by policyCheck policy rules via GET /admin/v1/policies. Review mcp_server, mcp_tool, mcp_arg conditions.
502 mcp_upstream_errorUpstream MCP server errorCheck MCP server health via /admin/v1/mcp/servers/\{id\}/health
503 mcp_server_unavailableMCP server suspended/disabledRe-activate the server via PUT /admin/v1/mcp/servers/\{id\}
429 rate_limit_exceededToo many requestsWait for Retry-After seconds, or increase limits
502 provider_errorUpstream provider issueCheck provider status page; the gateway will retry automatically
503 provider_circuit_openRepeated provider failuresWait for the circuit breaker to transition to half-open (default: 30s)
503 failover_capability_mismatchPrimary failed, no capable fallbackAdd more providers to the route that support the capability