This example demonstrates how to implement streaming manipulation using KrakenD Enterprise Edition with a middleware plugin and a response modifier plugin.
The example showcases how to manipulate stream responses. It does so by adding a processed_time key to the data: {} lines sent by the backend, which emulates a streaming session with OpenAI SSE response
-
Ensure you have a KrakenD EE license file named
LICENSEin theconfig/krakenddirectory -
Start all services:
docker compose up --build
This will start:
- KrakenD EE on port
8080 - Mock backend on port
8090
- KrakenD EE on port
-
Test the endpoints:
Middleware plugin:
curl -X POST http://localhost:8080/middleware \
-H "Content-Type: application/json" \
-d '{
"messages": [{"role": "user", "content": "Hello!"}]
}'Response modifier plugin:
curl -X POST http://localhost:8080/response \
-H "Content-Type: application/json" \
-d '{
"messages": [{"role": "user", "content": "Hello!"}]
}'Plugin not loading: Check KrakenD logs for plugin-related errors. Ensure the .so file is in /opt/krakend/plugins/ inside the container.
unsupported relocation type 7: If this error appears in krakend startup logs, this is most likely a mismatch between your architecture and the one the plugin is built for. If running on arm64, change the make amd64 command in Dockerfile to make arm64 instead.
This example requires a valid KrakenD Enterprise Edition license. Place your LICENSE file in the ./config/krakend directory.