This guide walks you through setting up the AI Proxy plugin with Azure OpenAI Service.

For all providers, the Kong AI Proxy plugin attaches to route entities.

It can be installed into one route per operation, for example:

  • OpenAI chat route
  • Cohere chat route
  • Cohere completions route

Each of these AI-enabled routes must point to a null service. This service doesn’t need to map to any real upstream URL, it can point somewhere empty (for example, http://localhost:32000), because the AI Proxy plugin overwrites the upstream URL. This requirement will be removed in a later Kong revision.

Prerequisites

  • Azure OpenAI Service account and subscription
  • You need a service to contain the route for the LLM provider. Create a service first:
  1. curl -X POST http://localhost:8001/services \
  2. --data "name=ai-proxy" \
  3. --data "url=http://localhost:32000"

Remember that the upstream URL can point anywhere empty, as it won’t be used by the plugin.

Provider configuration

Create or locate OpenAI instance

Log in to your Azure account, and (if necessary) create an OpenAI instance with the following values:

  • Name: azure_instance
  • Access key as the header_value

Create or locate model deployment

Once it has instantiated, create (if necessary) a model deployment in this instance. Record its name as your azure_deployment_id:

Set up route and plugin

Now you can create an AI Proxy route and plugin configuration:

Kong Admin API

YAML

Create the route:

  1. curl -X POST http://localhost:8001/services/ai-proxy/routes \
  2. --data "name=azure-chat" \
  3. --data "paths[]=~/azure-chat$"

Enable and configure the AI Proxy plugin for Azure, replacing the <azure_ai_access_key> with your own API key:

  1. curl -X POST http://localhost:8001/routes/azure-chat/plugins \
  2. --data "name=ai-proxy" \
  3. --data "config.route_type=llm/v1/chat" \
  4. --data "config.auth.header_name=api-key" \
  5. --data "config.auth.header_value=<azure_ai_access_key>" \
  6. --data "config.model.provider=azure" \
  7. --data "config.model.name=gpt-35-turbo" \
  8. --data "config.model.options.azure_instance=ai-proxy-regression" \
  9. --data "config.model.options.azure_deployment_id=kong-gpt-3-5"
  1. name: azure-chat
  2. paths:
  3. - "~/azure-chat$"
  4. methods:
  5. - POST
  6. plugins:
  7. - name: ai-proxy
  8. config:
  9. route_type: "llm/v1/chat"
  10. auth:
  11. header_name: "api-key"
  12. header_value: "<azure_ai_access_key>" # add your own 'Azure OpenAI' access key
  13. model:
  14. provider: "azure"
  15. name: "gpt-35-turbo"
  16. options:
  17. azure_instance: "ai-proxy-regression"
  18. azure_deployment_id: "kong-gpt-3-5"

Test the configuration

Make an llm/v1/chat type request to test your new endpoint:

  1. curl -X POST http://localhost:8000/azure-chat \
  2. -H 'Content-Type: application/json' \
  3. --data-raw '{ "messages": [ { "role": "system", "content": "You are a mathematician" }, { "role": "user", "content": "What is 1+1?"} ] }'

Previous Set up AI Proxy with Anthropic

Next Set up AI Proxy with Cohere