Giter Club home page Giter Club logo

azure-openai-apim-load-balancing's Introduction

page_type languages products name description
sample
azurecli
bicep
powershell
yaml
json
azure
azure-openai
azure-api-management
azure-resource-manager
Azure OpenAI Service Load Balancing with Azure API Management
This sample demonstrates how to load balance requests between multiple Azure OpenAI Services using Azure API Management.

Azure OpenAI Service Load Balancing with Azure API Management

This sample demonstrates how to use Azure API Management to load balance requests to multiple instances of the Azure OpenAI Service.

This approach takes advantages of the static, round-robin load balancing technique using policies in Azure API Management. This approach provides the following advantages:

  • Support for multiple Azure OpenAI Service deployments behind a single Azure API Management endpoint.
  • Remove complexity from application code for managing multiple Azure OpenAI Service instances and their authentication mechanisms using Azure API Management with policies and managed identity.
  • Retry logic for failed requests between Azure OpenAI Service instances.

For more information on topics covered in this sample, refer to the following documentation:

Flow

The following diagram illustrates the simplified flow of the sample.

A simplified flow of a request to Azure OpenAI instances via API Management using managed identity

  1. A user makes a request to a deployed Azure API Management API that is configured using the Azure OpenAI API specification.
    • The API Management API is configured with a policy that uses a static, round-robin load balancing technique to route requests to one of the Azure OpenAI Service instances.
  2. A bearer token is generated using the managed identity associated with the Azure API Management instance which has the Cognitive Services OpenAI User role assigned to the Azure OpenAI Service instances.
  3. The original request including headers and body are forwarded to the selected Azure OpenAI Service instance, along with the Authorization header containing the bearer token.

If the request fails, the policy will retry the request with the next Azure OpenAI Service instance, and repeat in a round-robin fashion until the request succeeds or a maximum of 3 attempts is reached.

Components

  • Azure OpenAI Service, a managed service for OpenAI GPT models that exposes a REST API.
  • Azure API Management, a managed service that provides a gateway to the backend Azure OpenAI Service instances.
  • Azure Managed Identity, a user-defined managed identity for Azure API Management to authenticate with Azure OpenAI.
  • Azure Bicep, used to create a repeatable infrastructure deployment for the Azure resources.

Getting Started

To deploy the infrastructure and test load balancing using Azure API Management, you need to:

Prerequisites

Run the sample notebook

The Sample.ipynb notebook contains all the necessary steps to deploy the infrastructure using Azure Bicep, and make requests to the deployed Azure API Management API to test load balancing between two Azure OpenAI Service instances.

Note: The sample uses the Azure CLI to deploy the infrastructure from the main.bicep file, and PowerShell commands to test the deployed APIs.

The notebook is split into multiple parts including:

  1. Login to Azure and set the default subscription.
  2. Deploy the Azure resources using Azure Bicep.
  3. Test load balancing using Azure API Management.
  4. Cleanup the Azure resources.

Each step is documented in the notebook with additional information and links to relevant documentation.

azure-openai-apim-load-balancing's People

Contributors

jamesmcroft avatar microsoft-github-operations[bot] avatar microsoftopensource avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

azure-openai-apim-load-balancing's Issues

Error while deploying Subscription for APIM API using Bicep

Please provide us with the following information:

This issue is for a: (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Run Sample.ipynb through Visual studio code

Any log messages given by the failure

"details":[{"code":"LinkedInvalidPropertyId","message":"Property id '/apis/openai' at path 'properties.scope' is invalid. Expect fully qualified resource Id that start with '/subscriptions/{subscriptionId}' or '/providers/{resourceProviderNamespace}/'."}]}]}]}}

Expected/desired behavior

It should add a subscription for API OpenAI.

OS and Version?

Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?)
Windows 11

Versions

Mention any other details that might be useful


Thanks! We'll be in touch soon.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.