Skip to main content

Official multiroute.ai SDK client with client-side failover for OpenAI, Anthropic, Google and other LLMs.

Project description

multiroute

Official SDK client library for multiroute.ai. It provides high-availability wrappers for major LLM providers (OpenAI, Anthropic, Google).

If a MULTIROUTE_API_KEY is set, requests are transparently routed through api.multiroute.ai. The SDK adds client-side failover protection: if there is any issue talking to multiroute.ai (network errors, timeouts, 5xx responses, some 404s), the request is automatically retried against the original provider, so your call still succeeds whenever the underlying provider is healthy.

What is this library?

multiroute is a thin compatibility layer around the official SDKs:

  • OpenAI: Drop-in replacement for openai.OpenAI / openai.AsyncOpenAI.
  • Anthropic: Drop-in replacement for anthropic.Anthropic / anthropic.AsyncAnthropic.
  • Google: Wrapper around google.genai.Client.

When MULTIROUTE_API_KEY is not set, the wrapped clients behave exactly like the original SDKs. When it is set, requests first go through Multiroute; if the proxy returns a retryable error (5xx, timeouts, connection issues, some 404s), the request is automatically retried against the original provider.

Installation

Install from PyPI:

pip install multiroute

Or with uv:

uv add multiroute

Configuration

  • Provider API keys: Configure as you normally would for each provider (for example, OPENAI_API_KEY, ANTHROPIC_API_KEY, Google credentials, etc.).
  • Multiroute API key: Set MULTIROUTE_API_KEY in your environment to enable proxy routing and fallback.

Example:

export OPENAI_API_KEY=sk-...
export MULTIROUTE_API_KEY=sk-...

If MULTIROUTE_API_KEY is unset, the library is effectively a no-op wrapper around the default clients.

Usage

OpenAI

from multiroute import OpenAI

client = OpenAI()

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Hello from multiroute!"}],
)

print(response.choices[0].message.content)

Async:

from multiroute.openai import AsyncOpenAI

client = AsyncOpenAI()

async def main() -> None:
    response = await client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{"role": "user", "content": "Hello from multiroute (async)!"}],
    )
    print(response.choices[0].message.content)

Anthropic

from multiroute import Anthropic

client = Anthropic()

response = client.messages.create(
    model="claude-3-5-sonnet-latest",
    max_tokens=256,
    messages=[{"role": "user", "content": "Hello from multiroute + Anthropic!"}],
)

Google

from multiroute import GoogleClient

client = GoogleClient()
model = client.models.generate_content

response = model(
    model="gemini-1.5-pro",
    contents="Hello from multiroute + Google!",
)

When to use multiroute

Use multiroute if you:

  • Want higher availability across LLM providers without changing your application code.
  • Prefer to keep using the official SDKs and types, but add a smart routing / failover layer.
  • Need a simple opt-in mechanism: setting or unsetting MULTIROUTE_API_KEY should be enough.

Development

If you want to work on the library itself:

  • Install dependencies: uv sync
  • Run tests: uv run pytest

See AGENTS.md for more detailed contributor and agent guidelines.

License

This project is licensed under the terms of the MIT license. See LICENSE for details.

Project details


Download files

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

Source Distribution

multiroute-0.1.1.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

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

multiroute-0.1.1-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file multiroute-0.1.1.tar.gz.

File metadata

  • Download URL: multiroute-0.1.1.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for multiroute-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f788ac50abaa447709fb5bbffb885ddeca3b5874effaa6f80cf6af6806a5d97a
MD5 761562004298f8d1debf0a7d56643f60
BLAKE2b-256 75b6ec738d28d57b21689c11966575d28890e8925b8505ed35d1bfccd4aa0e59

See more details on using hashes here.

File details

Details for the file multiroute-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: multiroute-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for multiroute-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 31ce29b66ff26b4361d1b36e024c4393be414aafdb993eeff12a9f2088cde08b
MD5 ee4c8f8c0579be6248edb1f704775c53
BLAKE2b-256 0f1907a56bb6e7be8cab44ad7405af5c6248c8e15dab96254aaa43582b79873e

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 Pingdom Monitoring Sentry Error logging StatusPage Status page