Skip to main content
The SSE Find & Replace action enables you to modify Server-Sent Events stream content by finding and replacing text patterns using regular expressions. This is particularly useful for modifying streaming AI model responses in real-time, such as redacting sensitive information or transforming content as it streams to clients.

Configuration reference

The Traffic Policy configuration reference for this action.

Supported phases

on_event_stream_message

Type

sse-find-replace

Configuration fields

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 like data, event, id, and retry. This action currently supports modifying the data and retry fields.

Pattern matching

The from 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

The field, from, and to parameters all support CEL interpolation for dynamic values:
When using CEL in the from field, the resulting string must be a valid regular expression.

Non-terminating action

This is a Non-terminating action. It does not return a response, and will allow Traffic Policy processing to continue to the next Action in the chain. All Cloud Endpoint Traffic Policies must end with a terminating action. This requirement does not apply to Agent Endpoints.

Examples

Redacting sensitive data from streaming AI responses

When using streaming AI responses (like OpenAI’s chat completions with stream: 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.