NeuralTrust has been recognized by Gartner → Read more
Back

TrustGuard Now Works with Apache APISIX

Roger Howroyd December 3, 2026
Share
TrustGuard Now Works with Apache APISIX

Last updated: December 3, 2026 · Reviewed by Alessandro Pignati

How do you add guardrails to Apache APISIX routes that proxy LLM traffic? Install the ai-neuraltrust-guard plugin next to ai-proxy or ai-proxy-multi on each route, create an APISIX collector and a policy in NeuralTrust TrustGuard, and store the collector key as an environment variable. The plugin sends the conversation to TrustGuard before the model is called and, if you choose, the completion before the client receives it. The integration was built by Alessandro Pignati, Lead AI Security Researcher at NeuralTrust, and is documented in the Apache APISIX integration guide.

TL;DR

  • Apache APISIX routes LLM requests to providers such as OpenAI, Anthropic and Amazon Bedrock through its AI Proxy plugins. The NeuralTrust plugin evaluates that traffic on the route, so applications do not change.
  • TrustGuard evaluates the prompt, and with direction: both the completion too. The controls are Monitor, Block and Redact.
  • Setup is five steps: policy, plugin install, collector key, route configuration and a test. APISIX 3.18 or later is required.
  • Start the policy in Observe mode, review Activity, then switch to Enforce. MCP tool calls are not evaluated by this plugin.

At a glance: how the integration works

Quick Answer

What does the NeuralTrust integration for Apache APISIX do?

It adds a plugin to APISIX routes that proxy model traffic. Before the model is called, the plugin sends the conversation to TrustGuard, which returns a verdict from the policy assigned to the collector. According to NeuralTrust's documentation, a blocked request never reaches the model in Enforce mode, and a redaction verdict rewrites the request or completion before it moves on.

ComponentRole in the integration
Apache APISIX ai-proxy or ai-proxy-multiRoutes the request to the model provider
ai-neuraltrust-guard pluginRuns on the same route and sends the provider body to TrustGuard, before the model is called and, with direction: both, on the completion
TrustGuardEvaluates the content against the assigned policy and returns a verdict: Monitor, Block or Redact
APISIX collector and tgk_ keyIdentifies the collector, and the policy is attached to it
TrustGuard ActivityShows each finding, which you can search by trace_id from the APISIX error log

How we wrote this

This guide summarizes NeuralTrust's integration documentation and Apache APISIX's official plugin documentation. We did not add new tests for this post. Use the official integration guide for exact field values and the plugin files.

Why LLM routes need their own content check

Apache APISIX applies plugins for authentication, rate limiting, logging and other controls to API routes. Its AI Proxy plugins transform requests for providers including OpenAI, DeepSeek, Azure, Anthropic, Gemini, Vertex AI and Amazon Bedrock (Apache APISIX, ai-proxy). The ai-proxy-multi plugin adds load balancing, retries, fallbacks and health checks on top (Apache APISIX, ai-proxy-multi).

That makes the route a natural control point, because every prompt and every completion crosses it:

  • Inbound to the model: a prompt can carry a jailbreak attempt, a secret or personal data such as an email, a card number or an IBAN.
  • Outbound to the client: a completion can carry content your policy forbids, such as toxic text or an off-topic answer.

Authentication and rate limits do not read that content. A content check on the route does, and it applies to every provider the route supports. For the wider picture, see what an AI gateway is and AI gateway security.

What the integration covers and what it does not

In scopeOut of scope
Requests on routes that use ai-proxy or ai-proxy-multiDirect calls from an application to a model provider, which do not pass through APISIX
Prompts, and completions when direction is output or bothMCP tool calls, which this plugin does not evaluate
Every provider supported by AI Proxy, with no application changesRoutes without an AI Proxy plugin, which the plugin cannot inspect and handles according to fail_mode

To keep traffic from bypassing the check, make APISIX the only path from your applications to the model providers. For MCP traffic, use a gateway built for it: see AI Gateway vs MCP Gateway.

Before you start

RequirementNotes
An APISIX collector and API keyIn the console, go to Agent Security, then Collectors, then Catalog, then Gateway, then Apache APISIX. Create the collector, then create the tgk_ key on its Auth tab. The key is shown once and identifies the collector
Apache APISIX 3.18 or laterNeuralTrust reports it as tested on 3.18, 3.19, 3.20 and 3.21. The route must use ai-proxy or ai-proxy-multi
Egress from APISIX to the TrustGuard base URLHTTPS on port 443. The console shows the base URL on the collector's Connection tab. The plugin's endpoint is that URL followed by /v1/evaluate
The plugin filesai-neuraltrust-guard.lua plus the ai-neuraltrust-guard folder with schema.lua and client.lua, from the integration guide

The plugin has been proposed for inclusion in Apache APISIX, and the proposal was still open on December 3, 2026. Until it is released, install it as an external plugin as described in step 2. Once it ships with APISIX, you only enable it and skip that step.

How to connect Apache APISIX to TrustGuard

1. Set up the policy in TrustGuard

Do this first. A collector with no policy returns allow and inspects nothing, with no warning.

  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 rules on its Detectors tab:
PhaseDetectorAction
InputPrompt GuardBlock
OutputToxicity DetectionBlock
OutputCustom ModerationBlock

Use Block for Prompt Guard, Indirect Prompt Injection and secrets. Use Transform for Data Loss Prevention PII such as email, card and IBAN, so the plugin can mask the values.

  1. 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.
  2. Under Basics, set Enforcement mode to Observe for the first run. Findings appear in Activity without affecting traffic. Switch to Enforce after you review them.

2. Install the plugin on APISIX

APISIX loads plugins that live outside its own directory through apisix.extra_lua_path, so no change to APISIX itself is needed (Apache APISIX, plugin development). Get the three plugin files from the integration guide and place them on every APISIX node with this layout:

Copied!

Then edit conf/config.yaml:

Copied!

The plugins key replaces APISIX's default plugin list. Copy the plugins: block from conf/config.yaml.example of your APISIX version and add ai-neuraltrust-guard to it. With a short list, keep prometheus next to ai-proxy, because ai-proxy fails to load without it and every route answers 404.

With Docker, mount the folder and the config:

Copied!

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 request /apisix/admin/plugins/ai-neuraltrust-guard from the Admin API with your admin key. A JSON schema in the response means the plugin 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:

Copied!

The route then refers to it as "api_key": "$env://NEURALTRUST_API_KEY". APISIX also supports $secret:// references for the same field, with Vault, AWS or GCP as the store (Apache APISIX, secrets).

4. Enable the plugin on a route

Add the plugin next to ai-proxy on each route you want to protect. It runs after ai-proxy, with priority 1027.

Copied!

Replace {TRUSTGUARD_BASE_URL} with the base URL from the collector's Connection tab. Put an authentication plugin such as key-auth, jwt-auth or openid-connect on the same route, so findings in Activity map to a consumer. With send_consumer_id, which is on by default, the plugin sends the APISIX consumer name. To let the Multi-turn Guard follow a conversation, send a real conversation ID in a header and set session_id_header to the header's name.

5. Test it

A benign prompt passes:

Copied!

A jailbreak is blocked. The denial is a normal completion with HTTP 200, so SDKs show it as the assistant's message:

Copied!
Copied!

Each verdict is written to the APISIX error log with its trace_id, which you can search in Activity. Set nginx_config.error_log_level to info to log allow verdicts as well. In Enforce mode a blocked request never reaches the model. In Observe mode the request passes and the finding appears in Activity.

Configuration reference

FieldDefaultNotes
api_keyrequiredCollector key, sent as Authorization: Bearer. Use $env:// or $secret://
endpointhttps://trustguard.neuraltrust.ai/v1/evaluateFull evaluate URL. Use the one from the collector's Connection tab
directioninputinput, output or both
actionblockblock denies. alert logs the verdict and lets the traffic through
block_on["block", "ask"]TrustGuard statuses that deny. Add transform to deny instead of forwarding unredacted content
fail_openfalseOn a TrustGuard error or timeout, false denies and true allows
fail_modeskipTraffic the plugin cannot inspect: skip, warn or error
timeout5000Milliseconds
apply_transformtrueRewrite the request or completion on a transform verdict
session_id_headernoneRequest header copied into session_id
deny_code200HTTP status of a denial
reveal_failure_categoriesfalseAppend the flagged categories to the refusal text

The guide also lists ssl_verify, payload_format, send_consumer_id and the refusal messages.

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.
  • Interrupted streams: if a stream ends without a complete assistant message, the plugin follows fail_open, which blocks by default. A turn made only of tool calls has no text to evaluate and passes.
  • Redaction: the rewritten body has the same shape as the request, with values replaced by tokens such as [MASKED_CC]. If it 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.
  • 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.

Troubleshooting

SymptomLikely cause
The Admin API returns 404 for ai-neuraltrust-guardThe plugin is not in the plugins list, or the files are not under extra_lua_path
Every route answers 404 after you edit pluginsThe short list dropped prometheus, and ai-proxy fails to load without it
Nothing appears in Activity and nothing is blockedThe collector has no policy attached, so it returns allow and inspects nothing
Findings do not map to a consumerThe route has no authentication plugin such as key-auth, jwt-auth or openid-connect
A blocked request still returns HTTP 200That is the default deny_code, so SDKs show the refusal as the assistant's message
Streamed answers arrive all at onceWith direction set to output or both, the plugin buffers the stream until it has evaluated the completion
A blocked request still reaches the modelThe policy is in Observe mode, or action is alert
Tool calls are not checkedThe plugin evaluates only calls that go through ai-proxy or ai-proxy-multi, and not MCP tool calls

Check the APISIX error log first. Each verdict carries a trace_id you can search in Activity.

Governance tips before you go live

  • Observe, then enforce: review Activity before you switch the policy to Enforce.
  • Protect every route: add the plugin to each route that proxies model traffic, and keep applications from calling providers directly.
  • Keep the key out of config files: use $env:// or $secret://, as in step 3.
  • Decide your failure mode: fail_open is false by default, so a TrustGuard error or timeout denies the request. Set it on purpose.
  • Retest after changes: rerun the benign and jailbreak tests whenever you change the policy or the route. AI Red Teaming (TrustTest) can probe the same applications more broadly.

Bottom Line: One Policy for Every LLM Route

APISIX already sits in front of your model traffic, so it is the right place to check what goes in and what comes out. This integration adds that check with one plugin per route and one policy in TrustGuard, and it needs no change in your applications. It covers model traffic through the AI Proxy plugins, so pair it with other controls for MCP tool calls.

Secure Apache APISIX With TrustGuard

Add prompt and completion evaluation to your APISIX routes. Start with the free plan or book a demo.

Try our AI Gateway today for free

Related Guides

FAQs about Apache APISIX LLM Security

1. How does NeuralTrust secure Apache APISIX LLM routes?

You enable the ai-neuraltrust-guard plugin next to ai-proxy or ai-proxy-multi. The plugin sends the conversation to TrustGuard before the model is called, and optionally the completion before the client receives it. TrustGuard returns a verdict from the policy attached to your collector, and the plugin enforces it.

2. Which APISIX versions and model providers does it support?

NeuralTrust's documentation requires Apache APISIX 3.18 or later and reports it as tested on 3.18, 3.19, 3.20 and 3.21. The route must use ai-proxy or ai-proxy-multi. The plugin works with every provider those plugins support and needs no application changes.

3. Does it evaluate MCP tool calls?

No. The plugin evaluates calls that go through ai-proxy or ai-proxy-multi, and MCP tool calls are not evaluated. A turn made only of tool calls has no text to evaluate and passes. For MCP traffic, use a gateway designed for it, such as TrustGate with an MCP application.

4. What happens when TrustGuard blocks a request?

In Enforce mode, a blocked request never reaches the model. The plugin returns a normal completion with HTTP 200 and the message "Request blocked by NeuralTrust TrustGuard", so SDKs show it as the assistant's reply. In Observe mode the request passes and the finding appears in Activity.

5. Does it work with streaming responses?

Yes. With direction: input, a stream reaches the client live. With output or both, the plugin buffers the stream and evaluates the assembled completion once. It then releases the text in one piece or replaces it with the refusal. Until then, the client sees only SSE comments.

6. How do I roll it out safely?

Create the policy first, because a collector with no policy returns allow and inspects nothing. Attach the policy to the collector and set Enforcement mode to Observe. Send test traffic, review the findings in Activity, then switch to Enforce. Keep fail_open at its default of false unless you need otherwise.

About the Author

Roger Howroyd is Head of Global SEO and AI at NeuralTrust, where he leads the company's search strategy across SEO, AEO, GEO, and LLM optimization. He specializes in AI-powered search, content strategy, and SEM. Connect on LinkedIn.

Integration built by Alessandro Pignati, Lead AI Security Researcher at NeuralTrust.

NeuralTrust is the leading platform for securing and scaling AI agents. Named a Pioneer in the Gartner Emerging Market Quadrant for AI Application Security 2026, recognized across four Gartner Hype Cycle reports in 2026, and featured in the Gartner Market Guide for Guardian Agents 2026, the Gartner Market Guide for AI Gateways 2025 and the KuppingerCole Leadership Compass for Generative AI Defense 2025. Headquartered in Barcelona with offices in London and New York. ISO 27001 certified.

Sources

Accessed December 3, 2026.

  1. NeuralTrust Docs, "Apache APISIX".
  2. Apache APISIX, "ai-proxy".
  3. Apache APISIX, "ai-proxy-multi".
  4. Apache APISIX, "Plugin Develop".
  5. Apache APISIX, "Secret".

Subscribe to our newsletter

Share

Join the leaders securing the agent ecosystem

Get a Demo