The Azure Functions AI Policy invokes Azure Functions from AI Gateway. Instead of forwarding a request to an upstream, the policy sends the request to your Azure function and returns the function’s response to the client. Use it to expose an existing Azure function through a AI Gateway endpoint, so clients call one address and the function stays behind the gateway.
Azure Functions Policy
How does the Azure Functions Policy work?
When a request reaches an entity that has the policy attached, the policy builds the function URL and calls it:
https://APP_NAME.HOST_DOMAIN/ROUTE_PREFIX/FUNCTION_NAMEThe following settings build the URL:
config.appname: The name of your Azure app.config.hostdomain: The domain where the function resides. Defaults toazurewebsites.net.config.routeprefix: The route prefix. Defaults toapi.config.functionname: The name of the function to invoke.
The policy forwards the HTTP method, query string, headers, and body of the client request to the function. It also sets the following headers when you configure the matching setting:
x-functions-key: Set fromconfig.apikey.x-functions-clientid: Set fromconfig.clientid.
The policy returns the status code, headers, and body from the function to the client. The entity that the policy is attached to never sends the request to its upstream.
The following example invokes a function named my-function in the my-app Azure app:
Use the policy in AI Gateway
The Azure Functions Policy attaches to an AI Model, AI Agent, or AI MCP Server, because AI Gateway has no Gateway Services or Routes. The entity provides the route that clients call, and the policy answers the request. For details about how scopes work, see AI Policy scopes.
- The upstream doesn’t receives traffic: The policy answers the request itself.
An AI Model still requires an AI Model Provider target, and clients must still send the
modelfield that the AI Model route matches on. AI Gateway doesn’t send the request to the provider. - AI Gateway changes the request body first: Before the policy runs, AI Gateway processes the request for the AI Model.
For example, the
modelfield in the body becomes the provider model name configured on the target, so the function receives that value instead of the AI Model name. - Scope: Attach the policy to an AI Model, AI Agent, AI MCP Server, or AI Consumer. The policy doesn’t support AI Consumer Group scope.
Don’t apply the Azure Functions Policy globally. A global policy answers every request on the data plane, so AI Models, AI Agents, or AI MCP Servers don’t receive traffic.
Configuration notes
- Set
config.routeprefixto at least one character. Keep the defaultapi, or set the prefix that your function app uses. - Store
config.apikeyandconfig.clientidas secret references. Konnect returns a literal value in API responses as plain text. - Make sure the data plane can reach the Azure function.
When the policy can’t connect, clients receive a
500response with the messageAn unexpected error occurred, and the cause appears in the data plane log.