v1

EngineNear Gateway API Reference

Real-time prompt optimization and firewall engine API specification. Provides high-throughput, low-latency endpoints for prompt inspection, context compilation, and policy enforcement.

Local Development Gateway
http://localhost:3000
EngineNear Cloud Production Gateway
https://api.enginenear.com

Authentication

All /v1 endpoints require Bearer authentication. Include your API key or tenant JWT token in the Authorization HTTP header:

HTTP Header
Authorization: Bearer <your-tenant-jwt-or-api-key>

API Endpoints

6 routes registered
POST/v1/guardBearer Auth

Evaluate prompt against real-time security policies

The hot-path firewall endpoint. Analyzes user prompts for secrets (Aho-Corasick + Shannon entropy), multi-region PII, and layered prompt injection in sub-5ms.

Response Status Codes

StatusDescriptionHeaders / Notes
200Guard policy verdict with findings and masked/tokenized prompt-
400Input validation failure-
401Missing or invalid authentication token-
429Rate limit quota exceeded-
503Event-loop lag load shedding triggered with Retry-After headerRetry-After: 1 (Load shedding active)
POST/v1/analyzeBearer Auth

Score prompt health and compute actionable optimization suggestions

Evaluates clarity, specificity, and safety scores (0-100) and returns gap-filling suggestions for prompt refinement.

Response Status Codes

StatusDescriptionHeaders / Notes
200Prompt health diagnostics and optimization recommendations-
400Invalid input-
401Unauthorized-
POST/v1/compileBearer Auth

Compile dynamic organizational context with role-based ACL pre-filtering

Extracts intent, resolves CRM/ERP entities, enforces tenant ACLs, and formats verified context into structured XML with strict token budget limits.

Response Status Codes

StatusDescriptionHeaders / Notes
200Compiled structured prompt with verifiable citations-
400Validation error-
401Unauthorized-
POST/v1/chat/completionsBearer Auth

OpenAI-compatible chat completion proxy with inline prompt firewall

Drop-in replacement for OpenAI endpoints. Point any OpenAI-compatible client (Python, TypeScript, LangChain) at the gateway by setting baseURL to http://gateway-host:3000/v1.

Response Status Codes

StatusDescriptionHeaders / Notes
200OpenAI-compatible chat completion with EngineNear security metadata-
403Request blocked by active firewall policy (secret or injection detected)-
429Rate limit exceeded-
503Gateway overloaded (load shedding)-
POST/v1/feedbackBearer Auth

Submit telemetry feedback on false positives or rule actions

Logs user decisions (accepted, dismissed, overridden) against a prompt hash for firewall policy tuning.

Response Status Codes

StatusDescriptionHeaders / Notes
202Feedback received successfully-
GET/v1/policyBearer Auth

Fetch active compiled policy tree for tenant and group

Returns the versioned compiled policy rules and priority ordering currently applied to the request context.

Response Status Codes

StatusDescriptionHeaders / Notes
200Active compiled policy tree-

Data Models & Schemas

The following Zod schemas are published in @enginenear/shared and compiled into the official OpenAPI 3.0 specification:

GuardRequestobject
Properties: prompt, destinationHost, clientTimestamp, maskSecrets (+4 more)
GuardResponseobject
Properties: action, allowed, promptHash, findings (+6 more)
AnalyzeRequestobject
Properties: prompt, sequenceId, destinationHost
AnalyzeResponseobject
Properties: promptHash, health, suggestions, findings (+2 more)
CompileRequestobject
Properties: prompt, intent, entityName, tokenBudget (+1 more)
CompileResponseobject
Properties: compiledPrompt, rawUserPrompt, variables, disambiguation (+4 more)
FeedbackRequestobject
Properties: promptHash, actionTaken, userAction, reason
FeedbackResponseobject
Properties: status, id
CompiledPolicyTreeobject
Properties: tenantId, group, version, defaultAction (+3 more)
AuditEventobject
Properties: tenantId, userId, promptHash, categories (+7 more)
BadRequestErrorobject
Properties: error, details
UnauthorizedErrorobject
Properties: error, message
RateLimitErrorobject
Properties: error, message
LoadSheddingErrorobject
Properties: error, message, lagMs
ChatCompletionResponseobject
Properties: id, object, created, model (+3 more)
ChatMessageobject
Properties: role, content
ChatCompletionRequestobject
Properties: model, messages, temperature, max_tokens (+1 more)