Skip to main content

HTTP response body modifier

The LLM Response body modifier plugin intercepts HTTP response bodies from your backend, sends them to an LLM with a configured system prompt, and replaces the response with the LLM's output before returning it to the client.

How it works

  1. The backend returns a response with a body
  2. The plugin sends the response body to the configured LLM provider with a system prompt
  3. The LLM processes the content and returns a transformed version
  4. The original response body is replaced with the LLM's output
  5. The modified response is returned to the client

This is useful for post-processing responses: translating, summarizing, reformatting, enriching, or sanitizing backend output.

Plugin configuration

{
"enabled": true,
"plugin": "cp:otoroshi_plugins.com.cloud.apim.otoroshi.extensions.aigateway.plugins.AiResponseBodyModifier",
"config": {
"ref": "provider-entity-id",
"prompt": "Summarize the following API response in 2-3 sentences:",
"prompt_ref": null,
"context_ref": null,
"extractor": null,
"is_response": false
}
}

Parameters

ParameterTypeDefaultDescription
refstring""LLM Provider entity ID
promptstring""System prompt sent to the LLM along with the response body
prompt_refstringnullReference to a stored prompt entity
context_refstringnullReference to a stored context entity for pre/post messages
extractorstringnullRegex pattern to extract a specific part of the LLM response
is_responsebooleanfalseWhen true, the LLM response is parsed as a full HTTP response (see below)

Full HTTP response mode

When is_response is set to true, the LLM is expected to return a complete HTTP response as a JSON object:

{
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"body": "{\"message\": \"transformed response\"}"
}

The plugin will use these values to construct the actual HTTP response (status code, headers, and body).

Example: translate response

{
"ref": "provider_openai",
"prompt": "Translate the following API response body to French. Return only the translated content, preserving the JSON structure."
}

Example: sanitize response

{
"ref": "provider_openai",
"prompt": "Remove any personally identifiable information (PII) from the following API response. Replace PII with '[REDACTED]'. Return only the sanitized content."
}