Creating a wrapper
Lakera Red tests AI systems by sending probes and analyzing the responses. To do that, Red needs an HTTP endpoint it can call.
If your system already matches Red’s supported contracts, connect it directly with an Agent target. If it does not, place a wrapper in front of it.
What a wrapper does
A wrapper is a lightweight HTTP service between Red and your AI system. It translates Red’s request format into your system’s format, waits for the full response, and returns Red-compatible JSON.
This is especially useful when your system is not directly OpenAI-compatible, streams output, or needs custom auth handling.
Handle authentication in the way that best fits your system. Your wrapper can either forward Lakera Red credentials upstream or use its own configured credentials when calling the target system.
Wrapper contract
Your wrapper must expose the
Stateful agent contract. Red uses a
sessionId to maintain multi-turn conversations.
Request (Red → wrapper):
Response (wrapper → Red):
On the first request, Red omits sessionId. Your wrapper should create a new session
and return its ID. Red then sends that sessionId on follow-up requests.
Typical wrapper flow
- Authenticate the inbound request from Red.
- Resolve an existing session or create a new one.
- Translate Red’s request into the payload your upstream system expects.
- Call the upstream API.
- Collect the full response (buffer if upstream streams).
- Return Red-compatible JSON with the
sessionId.
Generate a starter wrapper with AI
For a quick starting point, paste this prompt into your AI coding tool along with a real upstream request example, response example, and auth details.
Practical guidance
Secure the wrapper endpoint with authentication, such as a Bearer Token or API Key. Once deployed, use the Test Connection option in Red to verify the setup.
How to configure Red for a wrapper
Configure the wrapper as an Agent target:
Next steps
- Agent target configuration for full details on the request/response contracts.
- Getting Started with Lakera Red to create the target and run your first scan.