{"repo": "apache/apisix", "files": {"docs/en/latest/plugins/ai-request-rewrite.md": {"5f33466e26c8224ca5fc7fb092b6d4f6aa0690c3": {"t": 1785747233.3032188, "n": 28729, "h": "8aefaaaa90649b9d", "c": "---\ntitle: ai-request-rewrite\nkeywords:\n - Apache APISIX\n - AI Gateway\n - Plugin\n - ai-request-rewrite\ndescription: The ai-request-rewrite plugin forwards client requests to LLM services for processing before sending them upstream, enabling AI-driven redaction, enrichment, and reformatting.\n---\n\n\n\n
\n \n\n\nimport Tabs from '@theme/Tabs';\nimport TabItem from '@theme/TabItem';\n\n## Description\n\nThe `ai-request-rewrite` Plugin processes client requests by forwarding them to LLM services for transformation before relaying them to Upstream services. This enables LLM-powered modifications such as data redaction, content enrichment, or reformatting. The Plugin supports integration with OpenAI, DeepSeek, Gemini, Vertex AI, Anthropic, OpenRouter, and other OpenAI-compatible APIs.\n\n## Plugin Attributes\n\n| Name | Type | Required | Default | Valid values | Description |\n| --- | --- | --- | --- | --- | --- |\n| `max_req_body_size` | integer | False | 67108864 | >= 1 | Maximum request body size in bytes buffered into memory. Requests with a larger body are rejected. |\n| `prompt` | string | True | | | The prompt to send to the LLM service for rewriting the client request. |\n| `provider` | string | True | | [openai, deepseek, azure-openai, aimlapi, gemini, vertex-ai, anthropic, openrouter, openai-compatible] | LLM service provider. When set to `aimlapi`, the Plugin uses the OpenAI-compatible driver and proxies the request to `https://api.aimlapi.com/v1/chat/completions`. When set to `openai-compatible`, the Plugin proxies requests to the custom endpoint configured in `override`. When set to `azure-openai`, the Plugin also proxies requests to the custom endpoint configured in `override` and additionally omits the `model` parameter from the request body sent to Azure OpenAI. |\n| `auth` | object | True | | | Authentication configurations. |\n| `auth.header` | object | False | | | Authentication headers. Key must match pattern `^[a-zA-Z0-9._-]+$`. At least one of `header` and `query` should be configured. |\n| `auth.query` | object | False | | | Authentication query parameters. Key must match pattern `^[a-zA-Z0-9._-]+$`. At least one of `header` and `query` should be configured. |\n| `options` | object | False | | | Model configurations. In addition to `model`, you can configure additional parameters and they will be forwarded to the upstream LLM service in the request body. For instance, if you are working with OpenAI, you can configure additional parameters such as `temperature`, `top_p`, and `stream`. See your LLM provider's API documentation for more available options. |\n| `options.model` | string | False | | | Name of the LLM model, such as `gpt-4` or `gpt-3.5`. See your LLM provider's API documentation for more available models. |\n| `override` | object | False | | | Override setting. |\n| `override.endpoint` | string | False | | | LLM provider endpoint. Required when `provider` is `openai-compatible`. |\n| `timeout` | integer | False | 30000 | 1 - 60000 | Request timeout in milliseconds when requesting the LLM service. |\n| `keepalive` | boolean | False | true | | If true, keep the connection alive when requesting the LLM service. |\n| `keepalive_timeout` | integer | False | 60000 | ≥ 1000 | Keepalive timeout in milliseconds for requests to the LLM service. |\n| `keepalive_pool` | integer | False | 30 | ≥ 1 | Keepalive pool size for connections to the LLM service. |\n| `ssl_verify` | boolean | False | true | | If true, verify the LLM service's SSL certificate. |\n\n## How It Works\n\n\n\n## Examples\n\nThe examples below demonstrate how you can configure `ai-request-rewrite` for different scenarios.\n\nThe examples use OpenAI as the LLM service. To follow along, obtain an OpenAI [API key](https://openai.com/blog/openai-api) and save it to an environment variable:\n\n```shell\nexport OPENAI_API_KEY=