IBM Support

Configuring Azure API Management to Inject GPT-5 Mini Model Name Using Terraform

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

 

  1. Create the API Operation
    Define the API operation that forwards requests to the Azure OpenAI Responses API endpoint.
  2. 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."
    }
  3. Configure an APIM Operation Policy
    Use an API operation policy to modify the inbound request and inject the required model deployment name.
  4. 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
    }
  5. 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:
  6. {
      "model": "gpt-5-mini-deployment",
      "input": "Hello"
    }

  7. Confirm that Azure OpenAI successfully processes the request using the specified deployment.

 

Document Location

Worldwide

[{"Type":"MASTER","Line of Business":{"code":"LOB77","label":"Automation Platform"},"Business Unit":{"code":"BU048","label":"IBM Software"},"Product":{"code":"SSTYDYO","label":"IBM Terraform"},"ARM Category":[{"code":"a8mgJ0000000EB7QAM","label":"Terraform-\u003ECLI Official Providers-\u003EAzureRM"}],"ARM Case Number":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":""}]

Document Information

Modified date:
02 June 2026

UID

ibm17274764