Configuration reference
The Traffic Policy configuration reference for this action.Supported phases
on_event_stream_message
Type
sse-find-replace
Configuration fields
Array of replacement rules to apply to SSE messages. Rules are applied in order.Minimum
1 replacement required.The SSE field to apply the replacement to. Valid values are
data and retry.
Defaults to data if not specified.
CEL interpolation is supported.Regular expression pattern to match. Supports RE2 syntax.
CEL interpolation is supported for dynamic patterns.
Replacement string. Use
$1, $2, etc. to reference capture groups from the pattern.
CEL interpolation is supported for dynamic replacements.
If omitted or empty, matched text is deleted.Behavior
When this action executes, it processes each SSE message as it streams through ngrok, applying replacement rules to the specified fields.SSE message structure
Server-Sent Events consist of messages with fields likedata, event, id, and retry.
This action currently supports modifying the data and retry fields.
Pattern matching
Thefrom field accepts RE2 regular expressions.
All matches within the specified field are replaced, not just the first occurrence.
Streaming behavior
Unlike the request/response body find & replace actions, this action processes messages in real-time as they stream through. Each SSE message is processed independently.Capture groups
You can use capture groups in your pattern and reference them in the replacement:CEL expressions
Thefield, from, and to parameters all support CEL interpolation for dynamic values:
from field, the resulting string must be a valid regular expression.
Examples
Redacting sensitive data from streaming AI responses
When using streaming AI responses (like OpenAI’s chat completions withstream: true),
you can redact sensitive information in real-time.
Example Traffic Policy document
Modifying streaming AI output format
Transform streaming content as it’s delivered to clients:Filtering profanity from streaming responses
Remove or replace inappropriate content from AI responses in real-time:Modifying retry behavior
Change the retry interval in SSE streams:Action result variables
The following variables are made available for use in subsequent expressions and CEL interpolations after the action has run. Variable values will only apply to the last action execution, results are not concatenated.Related actions
- Request Body Find & Replace - Modify request bodies
- Response Body Find & Replace - Modify response bodies