v1

Errors, Limits & Load Shedding

Complete reference for HTTP error codes, token-bucket rate limits, and 503 load-shedding behavior with Retry-After headers.

HTTP Status Codes

EngineNear uses standard HTTP response codes to indicate request success, client validation errors, or security blocks:

  • 200 OK: Request succeeded and payload passed inspection.
  • 400 Bad Request: Zod schema validation failure. The response includes a details array indicating the invalid properties.
  • 401 Unauthorized: Missing or invalid Authorization: Bearer <token> header.
  • 403 Forbidden: Content policy violation. The prompt contained a secret or hostile prompt injection blocked under an Enforce policy.
  • 429 Too Many Requests: Rate limit quota exceeded. Rate limit headers indicate quota reset timestamps.
  • 503 Service Unavailable: Gateway load shedding active due to event loop lag exceeding 100ms. Response includes a Retry-After header.

Token-Bucket Rate Limits

The gateway enforces token-bucket rate limiting at both IP and tenant levels backed by Redis (with an in-memory fallback):

Standard tiers default to 100 requests per minute per tenant, while Pro and Teams tiers scale to thousands of requests per minute.

Responses include the following rate limit headers:

  • X-RateLimit-Limit: Total allowed requests in current window.
  • X-RateLimit-Remaining: Available remaining quota.
  • X-RateLimit-Reset: Epoch timestamp in seconds when the window resets.

503 Load Shedding & Retry-After

To maintain sub-5ms p95 latency and prevent cascading queue buildup, the EngineNear gateway continuously monitors Node.js event-loop lag (measured via perf_hooks).

If event-loop lag exceeds 100ms, the load shedder immediately terminates incoming requests with HTTP 503 Service Unavailable and a Retry-After: 1 header.

Clients should implement exponential backoff with full jitter when encountering 503 responses.

Handling Error Responses (curl, TypeScript, Python)

The examples below demonstrate sending an empty prompt payload to observe the structured HTTP 400 validation error:

Validation Error Response (HTTP 400)
Terminal (curl)
curl -s -X POST http://localhost:3000/v1/guard \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer test-token" \
  -d '{
    "prompt": ""
  }'