ai-request-rewrite
Rewrites the request body with an LLM before proxying.
ai-request-rewritePriority 1073What it does
ai-request-rewrite sends the client's request body to a model together with the instruction under Prompt, and the model's answer replaces that body before the request goes on to the route's backend. The model is the one Provider names, reached with the credential under Auth.
The backend receives what the model wrote, not what the client sent, under the content type the client gave the original body.
When to use it
- Partners that send orders in their own language to the orders API, while the backend reads English only.
- Request bodies that carry e-mail addresses the backend must never store, removed by a model before the request reaches it.
- Free text from a mobile app that the backend should receive as one short paragraph.
- A model your company runs itself behind an address that speaks the OpenAI protocol, named under Endpoint with the provider
openai-compatible.
Not for changing the path, the Host header or the headers the backend receives — see proxy-rewrite (Rewrites the request URI, method, host and headers before proxying), sending the client's prompt to a model and the answer back to the client — see ai-proxy (Proxies requests to an LLM provider with a unified API) or adding documents from a search index to a prompt — see ai-rag (Adds retrieved documents to the prompt from a vector search).
Set it up
Translate each request body into English before it reaches the backend
The Authorization value is sent to the provider as written, so write it as Bearer, a space and the key.
Under Basics set Provider to openai, fill Auth as in the JSON below, set Prompt to Translate the request body into English and keep its JSON shape., fill Options as in the JSON below and fill Override as in the JSON below.
{
"provider": "openai",
"auth": {
"header": {
"Authorization": "<secret>"
}
},
"prompt": "Translate the request body into English and keep its JSON shape.",
"options": {
"model": "gpt-4o-mini"
},
"override": {
"endpoint": "https://api.openai.com/v1/chat/completions"
}
}
Things to know
- Prompt — The rewritten body keeps the client's original content type. A model that answers in plain text on a request sent as
application/jsongives the backend a body labelled JSON, which the backend can refuse. - Provider — Bedrock and Vertex AI need AWS or GCP signing, which this plugin cannot do, because Auth takes only a header or a query key.
- Auth — Auth takes a header or a query parameter only, and a key pair for signing, the
awsshape, is refused when you save. - Endpoint — Without an endpoint, openai-compatible is refused at save, while azure-openai, bedrock and vertex-ai are saved but answer every request with 500.
- Endpoint — An empty endpoint is refused when you save.
- Timeout — The whole call to the model may last at most
60000milliseconds, and60001is refused when you save. - Prompt — The backend receives the model's answer in place of the client's body: in the example a Turkish note arrives as
Deliver before noon. - Endpoint — The request to the model goes to this address when it is set, the provider's own otherwise.
- AdviceWrite the prompt so that it names the shape the backend reads, for example "keep its JSON shape" for a backend that parses JSON.
Settings
The fields as the console shows them, section by section.
Basics
providerstringRequiredThe AI service that rewrites the request.
authobjectRequiredThe provider credential, usually a header such as Authorization with the value Bearer and your key.
auth.headerobjectStored on the engine and shown only to roles that manage this object. An object whose keys are letters, digits, dots, underscores and hyphens, each with a string as its value.
auth.queryobjectStored on the engine and shown only to roles that manage this object. An object whose keys are letters, digits, dots, underscores and hyphens, each with a string as its value.
promptstringRequiredThe instruction sent to the model with the client's request body, whose answer then replaces that body. The body keeps its original Content-Type, so a plain-text answer sent on as application/json can be refused by the upstream.
optionsobjectSettings passed to the model, such as the model name or the temperature. Other keys are stored as written.
{"model":"gpt-4o","temperature":0.2}options.modelstringoverrideobjectRequired when Provider is openai-compatible, or when Provider is azure-openai, or when Provider is bedrock, or when Provider is vertex-aioverride.endpointstringRequired when Provider is openai-compatible, or when Provider is azure-openai, or when Provider is bedrock, or when Provider is vertex-aiThe address requests go to instead of the provider's own, including the full path for bedrock and vertex-ai.
Behavior
timeoutintegerdefault 30000How long the whole call to the model may take, connect, send and read together.
ssl_verifybooleandefault trueAdvanced
max_req_body_sizeintegerdefault 67108864The largest request body in bytes that is read, where a larger one is refused with 400.
keepalivebooleandefault truekeepalive_poolintegerdefault 30