Guide: OpenAI Proxy API
Drop-in OpenAI-compatible proxy with inline prompt inspection, tokenization, and policy enforcement via POST /v1/chat/completions.
Endpoint Overview
The POST /v1/chat/completions endpoint is a wire-compatible proxy for the OpenAI Chat Completions API.
By pointing your OpenAI SDK (or any framework like LangChain, LlamaIndex, or AutoGen) to the EngineNear gateway, all prompts are automatically inspected and sanitized before leaving your infrastructure.
When a policy violation is detected (such as an unmasked high-entropy API key or an active injection attack under Enforce mode), the proxy rejects the request immediately with an HTTP 403 status code and detailed policy finding metadata.
SDK Configuration & Base URL
To integrate EngineNear with standard official OpenAI libraries, configure baseURL to point to the gateway:
In Node.js / TypeScript:
new OpenAI({ baseURL: "http://localhost:3000/v1", apiKey: process.env.ENGINENEAR_API_KEY })
In Python:
OpenAI(base_url="http://localhost:3000/v1", api_key=os.environ.get("ENGINENEAR_API_KEY"))
Code Examples (curl, TypeScript, Python)
The examples below demonstrate sending a chat completion through the EngineNear proxy:
curl -s -X POST http://localhost:3000/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer test-token" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "user", "content": "Explain zero-trust architecture in one paragraph."}
]
}'Policy Enforcement & Response Metadata
EngineNear extends the standard OpenAI response with an enginenear object containing security evaluation telemetry:
- enginenear.verdict: allow, warn, mask, or block.
- enginenear.promptHash: Immutable SHA-256 hash identifying the prompt.
- enginenear.latencyMs: Gateway firewall inspection duration in milliseconds.
- enginenear.findingsCount: Total count of sensitive spans or threat patterns identified.