Skip to main content

Azure Switchboard

Batteries-included, coordination-free client loadbalancing for Azure AI Foundry — OpenAI and Anthropic models alike.

uv add azure-switchboard

PyPI - Version License: MIT CI

Overview

azure-switchboard is a Python 3 library that implements a client-only, coordination-free loadbalancer for OpenAI/Anthropic models hosted on Azure Foundry. It can be used as a drop-in replacement for the openai or anthropic SDKs and lets you spread inference traffic across model deployments in multiple Azure Foundry resources. Coordination-freedom is achieved via the power of two random choices algorithm. See below for performance benchmarks.

List the Azure resources you have and the models deployed on them:

from azure_switchboard import AnthropicDeployment, Foundry, OpenAIDeployment, Switchboard

sb = Switchboard(resources=[
    Foundry(
        name="east",
        api_key=...,
        models=[
            OpenAIDeployment("gpt-4o-mini", tpm=30000, rpm=300),
            AnthropicDeployment("claude-sonnet-5", tpm=30000, rpm=300),
        ],
    ),
    Foundry(
        name="west",
        api_key=...,
        models=[OpenAIDeployment("gpt-4o-mini", tpm=30000, rpm=300)],
    ),
])

async with sb:
    completion = await sb.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{"role": "user", "content": "Hello!"}],
    )
    message = await sb.messages.create(
        model="claude-sonnet-5",
        max_tokens=1024,
        messages=[{"role": "user", "content": "Hello!"}],
    )

The endpoint is inferrable from the Foundry resource name or can be overriden explicitly on a per-deployment basis. Usage, ratelimiting, and cooldown status is tracked per-deployment (tpm/rpm) and per-resource (network-level errors) and overloaded models or resources can be configured to fall back to first-party providers if the appropriate API keys are available in the environment.

Features

  • Multi-Provider: supports both the OpenAI Chat Completions API and the Anthropic Messages API. Non-OpenAI models that support the OpenAI API spec can be used via the OpenAIDeployment class.
  • Coordination-Free: The default Two Random Choices algorithm does not require coordination between client instances to achieve excellent load distribution characteristics. See benchmarks for additional details.
  • Utilization-Aware: TPM/RPM utilization is tracked per deployment for use during selection.
  • Batteries Included:
    • Session Affinity: Provide a session_id to route requests in the same session to the same resource, so a session spanning several models keeps one prompt cache warm.
    • Automatic Failover: Retries are controlled by a tenacity AsyncRetrying policy (failover_policy).
    • First-Party Fallback: Set openai_fallback=True / anthropic_fallback=True to back the pool with the vendors' own APIs once nothing healthy is left.
    • Pluggable Selection: Custom selection algorithms can be provided by passing a callable to the selector parameter on the Switchboard constructor.
    • OpenTelemetry Integration: Every call is a span, with a child per failover attempt naming the resource that served it. Traffic, tokens, latency, failovers, cooldowns, and live utilization come out as metrics — enough to see which region is carrying the pool and which one is quietly failing.
  • Lightweight: Small codebase with minimal dependencies: openai, anthropic, tenacity, wrapt, and opentelemetry-api.

Runnable Example

See tools/readme_example.py.

Benchmarks

1000 requests spread over 10 deployments of gpt-5.4-mini:

just bench
uv run tools/bench.py -v -r 1000 -d 10 -e 500
Distributing 1000 requests across 10 deployments
Max inflight requests: 1000

{
    'bench_0': {'gpt-5.4-mini': UtilStats(util=0.337, tpm=Quota(used=8388, limit=30000), rpm=Quota(used=100, limit=300))},
    'bench_1': {'gpt-5.4-mini': UtilStats(util=0.331, tpm=Quota(used=8251, limit=30000), rpm=Quota(used=99, limit=300))},
    ...
    'bench_9': {'gpt-5.4-mini': UtilStats(util=0.342, tpm=Quota(used=8435, limit=30000), rpm=Quota(used=100, limit=300))}
}

Utilization Distribution:
0.000 - 0.100 |   0
0.100 - 0.200 |   0
0.200 - 0.300 |   0
0.300 - 0.400 |  10 ..............................
0.400 - 0.500 |   0
0.500 - 0.600 |   0
0.600 - 0.700 |   0
0.700 - 0.800 |   0
0.800 - 0.900 |   0
0.900 - 1.000 |   0
Avg utilization: 0.338 (0.325 - 0.345)
Std deviation: 0.005

Distribution overhead: 242.59ms
Average response latency: 5066.64ms
Total latency: 10041.57ms
Requests per second: 4122.20
Overhead per request: 0.24ms

Distribution overhead scales ~linearly with the number of deployments.

Development

This project uses uv for package management, and just for task automation. See the justfile for available commands.

git clone https://github.com/arini-ai/azure-switchboard
cd azure-switchboard

just install

Running tests

just test        # unit tests; every upstream is mocked
just typecheck   # pyright over src/, as CI runs it

Release

This library uses CalVer for versioning. On push to master, if tests pass, a package is automatically built, released, and uploaded to PyPI.

Locally, the package can be built with uv:

uv build

Contributing

  1. Fork/clone repo
  2. Make changes
  3. Run tests with just test
  4. Lint with just lint
  5. Commit and make a PR

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

azure_switchboard-2026.8.2.tar.gz (224.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

azure_switchboard-2026.8.2-py3-none-any.whl (24.6 kB view details)

Uploaded Python 3

File details

Details for the file azure_switchboard-2026.8.2.tar.gz.

File metadata

  • Download URL: azure_switchboard-2026.8.2.tar.gz
  • Upload date:
  • Size: 224.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for azure_switchboard-2026.8.2.tar.gz
Algorithm Hash digest
SHA256 80fe7989da273a9698eec1931b3f43d9dc7d714c7afb0014bf8293bb8a3062b0
MD5 e37bc427fc9d02927a85a06f2fc22a6a
BLAKE2b-256 fa1d5ae2d920b8991acbc8146590a8a8a2133fda876cbe74d14f9e05b2af5e9c

See more details on using hashes here.

File details

Details for the file azure_switchboard-2026.8.2-py3-none-any.whl.

File metadata

  • Download URL: azure_switchboard-2026.8.2-py3-none-any.whl
  • Upload date:
  • Size: 24.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for azure_switchboard-2026.8.2-py3-none-any.whl
Algorithm Hash digest
SHA256 842190f5bc8fff807c0d3be2c0e664ce14272f1a6460471a394b5fdd26de0583
MD5 89f068b727f1da9d584eebb161398add
BLAKE2b-256 4e8eeda794df4df3e29336c7965d3fab08e2d73280c1e5f6d7883160e8684889

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page