Transformations
About CEL expressions
CEL (Common Expression Language) transformations allows you to use dynamic expressions to extract and transform values from requests and responses.
For an overview of supported CEL expressions, see the agentgateway docs.
About this guide
This guide walks you through how to set up CEL-based transformations for the OpenAI LLM provider. Note that you can use the same AgentgatewayPolicy resource to apply transformations to MCP server, inference, or agent routes.
Before you begin
Set up transformations
-
Create an AgentgatewayPolicy with your transformation rules. In this example, you use a CEL expression to extract the path from the request. The request path is then added to the
response-gatewayheader.kubectl apply -f- <<EOF apiVersion: agentgateway.dev/v1alpha1 kind: AgentgatewayPolicy metadata: name: transformation namespace: agentgateway-system spec: targetRefs: - group: gateway.networking.k8s.io kind: Gateway name: agentgateway-proxy traffic: transformation: response: set: - name: response-gateway value: "'response path ' + request.path" EOF -
Send a request to the OpenAI API. Verify that the request succeeds and that you see the
response-gatewayheader with a value ofresponse path /openai.curl -v "${INGRESS_GW_ADDRESS}:8080/openai" -H content-type:application/json -H "X-User-ID: user123" -d '{ "model": "gpt-3.5-turbo", "messages": [ { "role": "system", "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair." }, { "role": "user", "content": "In the style of Shakespeare, write a series of sonnets that explain the concept of recursion in programming." } ] }'curl -v "localhost:8080/openai" -H content-type:application/json -H "X-User-ID: user123" -d '{ "model": "gpt-3.5-turbo", "messages": [ { "role": "system", "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair." }, { "role": "user", "content": "In the style of Shakespeare, write a series of sonnets that explain the concept of recursion in programming." } ] }'Example output:
* upload completely sent off: 358 bytes < HTTP/1.1 200 OK < content-type: application/json < access-control-expose-headers: X-Request-ID < openai-organization: solo-io-1 < openai-processing-ms: 1082 < openai-version: 2020-10-01 ... < response-gateway: response path /openai < content-length: 1198
Cleanup
You can remove the resources that you created in this guide.kubectl delete AgentgatewayPolicy transformation -n agentgateway-system