Related Documentation
Made by
Kong Inc.
Priority
779
Minimum Version
AI Gateway - 2.0

The Redirect AI Policy redirects requests to an AI Model, AI Agent, or AI MCP Server to a new URL. It stops the request before it reaches the upstream and returns a redirect response with a Location header. Use it when an endpoint has moved to another host and you want existing clients to follow it.

How does the Redirect Policy work?

Set config.location to the URL that callers should use. AI Gateway returns that URL in the Location header of every request that matches the policy’s scope. Streaming and non-streaming requests receive the same response.

By default, the response status code is 301. Set config.status_code to use a different code, such as 302 for a temporary redirect, or 307 or 308 to tell clients to repeat the request with the same method.

Keep the incoming path

Set config.keep_incoming_path to true to keep the path and query string of the incoming request. The Location header then combines config.location with that path and query string. This is useful when the new host serves the same paths as the old one.

The incoming path is the full path that the caller requested, including the route prefix of the AI Model or AI MCP Server.

The following table shows the result for a request to /my-model/chat/completions?a=1:

config.location

config.keep_incoming_path

Location header

https://new.example.com true https://new.example.com/my-model/chat/completions?a=1
https://new.example.com/base true https://new.example.com/base/my-model/chat/completions?a=1
https://new.example.com/base false https://new.example.com/base

Scopes

Attach the Redirect Policy to an AI Model, AI Agent, or AI MCP Server to redirect only that entity. You can also attach it to an AI Consumer or AI Consumer Group, or apply it globally. AI Consumer and AI Consumer Group scopes apply after the caller authenticates.

  • To move a single endpoint, attach the policy to that entity.
  • To move specific customers, attach it to their AI Consumer or AI Consumer Group. For details about how scopes work, see AI Policy scopes.

A global Redirect Policy redirects every request on the data plane, including requests to entities that you didn’t intend to move. Attach the policy to a single entity instead. To keep a global policy, use a condition to limit when it runs.

Looking for on-prem configuration? Convert the kongctl configuration to a decK yaml file and use deck file ai2kong. See Configure Kong AI Gateway on-prem for more information.

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!