Skip to main content
Feedback

Transform policy

The Transform Gateway policy modifies API requests based on predefined transformation rules by setting, deleting, or obfuscating specific request parameters.

Prerequisites

  • Active LLM Gateway instance. Refer to Installation.
  • Familiarity with Gateway policy structure and configuration templates.

Scenarios

  1. Data Obfuscation: Mask sensitive information with configurable obfuscation rules.
  2. Set Values: Change values in the header or body before sending the request to the provider.
note

Obfuscated values are replaced with consistent hashes, ensuring data privacy while maintaining traceability.

Gateway policy component

Transform API Call Processor

Transform policy configuration scenario

The following configuration example is a fully configured Transform API Call Gateway policy that transforms a request to OpenAI.

/etc/lunar-proxy/flows/flow.yaml
name: TransformAPI

filter:
url: "api.openai.com/*"

processors:
TransformAPICall:
processor: TransformAPICall
parameters:
- key: set
value:
$.request.path: '/v1/messages'
$.request.headers['x-api-key']: $OPENAI_API_KEY
- key: delete
value:
- $.request.headers.Authorization
- $.request.headers['openai-organization']
- $.request.headers['x-stainless-1']
- $.request.parsed_query.resource_id
- key: obfuscate
value:
- $.request.headers['user-agent']

flow:
request:
- from:
stream:
name: globalStream
at: start
to:
processor:
name: TransformAPI
- from:
processor:
name: TransformAPI
to:
stream:
name: globalStream
at: end

response:
- from:
stream:
name: globalStream
at: start
to:
processor:
name: TransformAPI
- from:
processor:
name: TransformAPI
to:
stream:
name: globalStream
at: end
On this Page