Skip to main content
Apache APISIX applies plugins for authentication, rate limiting, logging, and other controls to API routes. Its AI Proxy plugins (ai-proxy, ai-proxy-multi) route requests to model providers such as OpenAI, Anthropic, and Bedrock. This integration ships an APISIX plugin, ai-neuraltrust-guard, that sends the conversation to TrustGuard before the model is called and, optionally, the completion before the client receives it. It works with every provider supported by AI Proxy and needs no application changes. Direct calls to a provider do not pass through APISIX.
ai-neuraltrust-guard is proposed for inclusion in Apache APISIX (apache/apisix#14309). Until it is released, install it as an external plugin as described below. Once it ships with APISIX, you only enable it and skip step 2.

Integration capabilities

A transform verdict is applied (apply_transform, default true): the request is rewritten before the model is called, and the completion is rewritten before the client receives it. MCP tool calls are not evaluated.

Before you start

1

Set up the policy in TrustGuard

A collector with no policy returns allow and inspects nothing, with no warning. Set up the policy before anything else.
  1. In Detectors, create the detectors the policy needs. A typical set is Prompt Guard, Toxicity Detection, and a Custom Moderation detector for your own topics.
  2. In Policies, create a policy and add the rules on its Detectors tab: Use Block for Prompt Guard, Indirect Prompt Injection and secrets. Use Transform for Data Loss Prevention PII (email, card, IBAN) so the plugin can mask them. A Transform action is applied when apply_transform is true (the default).
  3. On the policy’s Collectors tab, attach the APISIX collector with Routing mode Default. You can do the same from the collector’s Policies tab.
  4. Set Basics → Enforcement mode to Observe for the first run. Findings appear in Activity without affecting traffic. Switch to Enforce after reviewing them.
2

Install the plugin on APISIX

APISIX loads plugins that live outside its own directory through apisix.extra_lua_path. No change to APISIX is needed. Download the three files into /opt/neuraltrust/apisix/plugins on every APISIX node:
The folder must keep this layout:
Then edit conf/config.yaml:
The plugins key replaces APISIX’s default plugin list. Copy the list from conf/config.yaml.example of your APISIX version (the plugins: block) and add ai-neuraltrust-guard to it. With a short list, keep prometheus next to ai-proxy: ai-proxy fails to load without it and every route answers 404.
With Docker, mount the folder and the config:
On Kubernetes, mount the same three files at /opt/neuraltrust/apisix/plugins (for example from a ConfigMap) and set extra_lua_path in the APISIX configuration. Restart APISIX, then confirm the plugin is loaded:
A JSON schema means it is loaded. A 404 means the plugin is not in the plugins list or the files are not under extra_lua_path.
3

Store the collector key

Do not paste the key into the route. Set it as an environment variable on every APISIX node and reference it:
The route then uses "api_key": "$env://NEURALTRUST_API_KEY". APISIX also supports $secret:// references (Vault, AWS, GCP) for the same field.
4

Enable the plugin on a route

Add the plugin next to ai-proxy on each route to protect. It runs after ai-proxy (priority 1027).
Put an auth plugin (key-auth, jwt-auth, openid-connect) on the same route so findings in Activity map to a consumer. With send_consumer_id (default true) the plugin sends the APISIX consumer name. Send a real conversation ID in a header and set session_id_header to its name so the Multi-turn Guard can follow a conversation.
5

Test it

A benign prompt passes:
A jailbreak is blocked. The denial is a normal completion (HTTP 200) so SDKs show it as the assistant’s message:
Each verdict is in the APISIX error log with its trace_id, which you can search in Activity. Set nginx_config.error_log_level: info to also log allow verdicts:
In Enforce mode a blocked request never reaches the model. In Observe mode the request passes and the finding appears in Activity.

Configuration

Behavior and limits

  • Streaming. With direction: input a stream reaches the client live. With output or both the plugin buffers the stream, evaluates the assembled completion once, then releases it in one piece or replaces it with the refusal. The client sees only SSE comments (:) until the end. This also works when another buffering guard plugin, such as ai-lakera-guard, is on the route.
  • Interrupted streams. If the stream ends without a complete assistant message (the upstream is cut by max_response_bytes or max_stream_duration_ms, or the SSE is truncated), the plugin follows fail_open: it blocks by default. A turn made only of tool calls has no text to evaluate and passes.
  • Redaction. A transform verdict is applied (apply_transform: true by default). The rewritten body has the same shape as the request, with values replaced by tokens such as [MASKED_CC]. Set apply_transform: false to only log, or add transform to block_on to deny. If the rewritten body cannot be applied, the plugin follows fail_open.
  • Cost. direction: both is two evaluations per model turn. The response is evaluated only if the request passed.
  • Models only. The plugin evaluates calls that go through ai-proxy or ai-proxy-multi. MCP tool calls are not evaluated.
  • Sessions. The Multi-turn Guard keeps history per session_id. After a blocked turn, later turns in the same session are also blocked. Without a session header, every call is a new session.