How To
Summary
When exposing Azure OpenAI GPT-5 Mini through Azure API Management (APIM), the model deployment name must be included in the request payload as the model parameter. The Terraform resource azurerm_api_management_api_operation does not provide an attribute to specify the model name directly. Instead, request payload modifications must be performed through Azure API Management policies using the azurerm_api_management_api_operation_policy resource.
Objective
Demonstrate how to configure Azure API Management with Terraform to route requests to the Azure OpenAI Responses API and inject the required GPT-5 Mini deployment name into the request payload using APIM policies.
Environment
Terraform
HashiCorp AzureRM Provider
Steps
- Create the API Operation
Define the API operation that forwards requests to the Azure OpenAI Responses API endpoint. resource "azurerm_api_management_api_operation" "chat_completion_app_bpp" { operation_id = "ChatCompletions_Create" api_name = azurerm_api_management_api.apim-api-app-bpp.name resource_group_name = module.ai_foundations_platform.resource_group_name api_management_name = module.ai_foundations_platform.apim_name display_name = "Creates a completion for the chat message" method = "POST" url_template = "/openai/responses?api-version=2025-04-01-preview" description = "Creates a completion for the chat message." }- Configure an APIM Operation Policy
Use an API operation policy to modify the inbound request and inject the required model deployment name. resource "azurerm_api_management_api_operation_policy" "chat_completion_policy" { api_name = azurerm_api_management_api.apim-api-app-bpp.name api_management_name = module.ai_foundations_platform.apim_name resource_group_name = module.ai_foundations_platform.resource_group_name operation_id = azurerm_api_management_api_operation.chat_completion_app_bpp.operation_id xml_content = <<XML <policies> <inbound> <base /> <!-- Example policy logic to inject model deployment name --> <set-body template="liquid"> { "model": "gpt-5-mini-deployment", "input": {{body.input}} } </set-body> </inbound> <backend> <base /> </backend> <outbound> <base /> </outbound> <on-error> <base /> </on-error> </policies> XML }- Validate the Request
After applying the Terraform configuration:
Send a POST request through the APIM endpoint.
Verify that the request body forwarded to Azure OpenAI contains: { "model": "gpt-5-mini-deployment", "input": "Hello" }
Confirm that Azure OpenAI successfully processes the request using the specified deployment.
Document Location
Worldwide
Was this topic helpful?
Document Information
Modified date:
02 June 2026
UID
ibm17274764