OpenAI SDK: Multi-deployment chat routingv3.8+

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

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-4"
)

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-3-5
   paths:
     - "~/openai/deployments/azure-gpt-3-5/chat/completions$"
   methods:
     - POST

and:

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

Prerequisites

  • Azure account

Environment variables

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

Set up the plugin

Something wrong?

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!