AI Proxy Advanced

AI License Required

OpenAI SDK: Multi-deployment chat routingv3.8+

Use separate Routes to map Azure OpenAI SDK requests to specific deployments of GPT-4o and GPT-4-1-mini.

Using OpenAI SDK with the AI Proxy Advanced plugin, you can configure multiple Routes in Kong Gateway to represent different Azure OpenAI deployments. Each Route maps a unique path segment (such as azure-gpt-3-5 or azure-gpt-4) to the corresponding deployment ID and model name. This setup allows you to use a single Azure-compatible OpenAI SDK client to switch between deployments by changing only the base URL.

For example:

client = OpenAI(
  base_url="http://127.0.0.1:8000/openai/deployments/azure-gpt-3-5"
)

Or:

client = OpenAI(
  base_url="http://127.0.0.1:8000/openai/deployments/azure-gpt-4o"
)

Kong Gateway reads the deployment path, maps it to the appropriate Azure deployment ID and model, and handles authentication automatically.

For this configuration to work properly, you need a Route with the following configuration:

routes:
 - name: azure-chat-gpt-4-1-mini
   paths:
     - "~/openai/deployments/azure-gpt-4-1-mini/chat/completions$"
   methods:
     - POST

and:

routes:
 - name: azure-chat-gpt-4o
   paths:
     - "~/openai/deployments/azure-gpt-4o/chat/completions$"
   methods:
     - POST

For a complete tutorial of this configuration, see the Azure OpenAI SDK example.

Prerequisites

  • Azure account

Environment variables

  • AZURE_API_KEY: The API key to authenticate requests to Azure.

  • AZURE_INSTANCE: The name of your Azure OpenAI instance.

  • AZURE_DEPLOYMENT: The deployment ID of the Azure OpenAI model you want to use.

Set up the plugin

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!