Search K
Appearance
Appearance
AI GUARDRAILS
This article is meant for AI Guardrails users.
ROLES AND PERMISSIONS
To complete the task described in this section, make sure you have the required permissions.
Use the /backend/v1/scans/raw/{format} endpoint to scan raw request and response bodies with F5 AI Guardrails. Call a provider directly, then scan its content without routing traffic through a provider-compatible endpoint.
By default, AI Security scans the full SSE response before returning it. Scan results appear in response headers. Add stream=true to scan supported SSE responses as they arrive. In this mode, AI Security adds scan results to the SSE response body instead of returning them in headers.
SUPPORTED FORMATS
Use openai-responses-request for OpenAI Responses API request bodies. Use openai-chat-sse or openai-responses-sse for streamed responses.
Before you begin, make sure you have:
<AI_SECURITY_HOSTNAME> in the examples with the hostname for your AI Security deployment.When you send a request to the /backend/v1/scans/raw/{format} endpoint, it:
stream=true.The endpoint doesn't call any upstream AI provider. You keep full control over when and how you interact with the provider.
The {format} path parameter specifies how AI Security interprets the body you send:
openai-responses-request -- Interprets the body as a JSON request for the OpenAI Responses API. Use this format to scan outgoing request bodies before you send them to OpenAI.openai-chat-sse -- Interprets the body as an SSE stream from the OpenAI Chat Completions API.openai-responses-sse -- Interprets the body as an SSE stream from the OpenAI Responses API.Set stream=true only with openai-chat-sse or openai-responses-sse. AI Security returns 400 Bad Request if you use it with another format.
When you omit stream=true, or set it to false, AI Security scans the full body before it returns the scan results in these headers:
x-ai-security-outcome -- The scan outcome (for example, cleared). This header indicates whether the content passed all configured guardrails.x-ai-security-scan-id -- A UUID that identifies the scan. Use this value to look up scan details in audit logs or the AI Security dashboard.x-ai-security-error -- Included only when an error occurs during scanning. Contains a message that describes what went wrong.Use the openai-responses-request format to scan a raw JSON request body before you send it to the OpenAI Responses API.
To scan a request body:
Send the raw JSON request body to the scan endpoint:
curl -X POST \
-H "Authorization: Bearer <YOUR_API_TOKEN>" \
-H "Content-Type: application/json" \
"https://<AI_SECURITY_HOSTNAME>/backend/v1/scans/raw/openai-responses-request" \
-d '{
"model": "gpt-5-nano",
"input": "My credit card number is 4111-1111-1111-1111 and my SSN is 123-45-6789. Help me fill out this form.",
"stream": true
}'Check the response headers for the scan result.
A successful scan returns headers like the following:
HTTP/2 200
x-ai-security-outcome: cleared
x-ai-security-scan-id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxAnalyze the outcome.
x-ai-security-outcome is cleared, the content passed all guardrails. You can safely send it to the provider.The response body is the same request JSON that you sent.
By default, the openai-responses-sse format scans the full response after you receive it from the OpenAI Responses API. AI Security returns scan results in response headers.
To scan an SSE stream response:
Pipe the OpenAI Responses API output directly into the AI Security scan endpoint:
curl https://api.openai.com/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <YOUR_OPENAI_API_KEY>" \
-d '{
"model": "gpt-5-nano",
"input": "My credit card number is 4111-1111-1111-1111 and my SSN is 123-45-6789. Help me fill out this form.",
"stream": true
}' | curl -X POST \
-H "Authorization: Bearer <YOUR_API_TOKEN>" \
"https://<AI_SECURITY_HOSTNAME>/backend/v1/scans/raw/openai-responses-sse" \
--data-binary @-This command sends a streaming request to the OpenAI Responses API. It pipes the SSE response into AI Security for scanning.
Check the response headers for the scan result.
A successful scan returns headers like the following:
HTTP/2 200
x-ai-security-outcome: cleared
x-ai-security-scan-id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxAnalyze the outcome.
x-ai-security-outcome is cleared, the streamed response passed all guardrails. You can safely use it in your application.RESPONSE BODY
The response body contains the same SSE chunks that you sent. The stream contains events like response.created, response.in_progress, and response.completed, following the event structure of the OpenAI Responses API.
Set stream=true to scan an SSE response as AI Security receives it. The response includes the original SSE content and a scan result comment for each scan:
: x-ai-security {"outcome": "<OUTCOME>", "scanId": "<SCAN_ID>", "error": "<ERROR>"}In this mode, AI Security doesn't return the x-ai-security-outcome, x-ai-security-scan-id, or x-ai-security-error response headers. It scans accumulated text when enough new text arrives, when a timeout expires, or when the stream ends. AI Security doesn't wait for another chunk from the provider. Each scan includes new text and preceding text, so it can detect content that spans chunks.
If AI Security blocks a chunk, it doesn't send that chunk's text. It sends the error event CAI guardrails blocked the response and ends the stream.
To scan a response as it arrives, add ?stream=true to the scan endpoint URL:
curl https://api.openai.com/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: ******" \
-d '{
"model": "gpt-5-nano",
"input": "My credit card number is 4111-1111-1111-1111 and my SSN is 123-45-6789. Help me fill out this form.",
"stream": true
}' | curl -X POST \
-H "Authorization: ******" \
"https://<AI_SECURITY_HOSTNAME>/backend/v1/scans/raw/openai-responses-sse?stream=true" \
--data-binary @-For more information, see: