Skip to main content

A simple llm router

Project description

GitHub stars License: MIT PyPI version Python 3.11+

llamux 🦙

A simple router to rotate across your configured LLM endpoints, balancing load and avoiding rate limits. The router selects your preferred provider-model pair based on an implicit preference list, ensuring token and request limits (day/hour/minute) aren't crossed. State persists across sessions, with quotas stored in local cache.

Install

Requires Python 3.11+

pip install llamux

Usage

You need first to set the list of endpoints you want to allow routing on;

$ > endpoints.csv

| provider | model                   | rpm | tpm   | rph   | tph     | rpd   | tpd     |
| -------- | ----------------------- | --- | ----- | ----- | ------- | ----- | ------- |
| cerebras | llama3.3-70b            | 30  | 60000 | 900   | 1000000 | 14400 | 1000000 |
| groq     | llama-3.3-70b-versatile | 30  | 6000  | 14400 |         | 14400 |         |

where rpm, tpm are requests and tokens limits per minutes, and the same follows for hours and days. Important note 🔊 Your implicit preference list is given by the ordering of the endpoints in this table. In the above, we'll always prefer Cerebras over Groq, as long as the quota limits are not exceeded.

Use it as a standalone router;

from llamux import Router

os.environ["CEREBRAS_API_KEY"] = "sk-..."
os.environ["GROQ_API_KEY"] = "sk-..."

router = Router.from_csv("endpoints.csv")
messages = [{"role": "user", "content": "Hello, how are you?"}]

provider, model, id, props = router.query(messages)
# provider: cerebras, model: llama3.3-70b

Or use it directly as a completion endpoint;

from llamux import Router

router = Router.from_csv("endpoints.csv")
messages = [{"role": "user", "content": "hey" * 59999}]

response = router.completion(messages) # calls cerebras
response = router.completion(messages) # calls groq (cerebras quota is out!)

The above builds upon litellm llm proxy

More features

Contributions are welcome :)

  • Add support for speed and cost routing preferences
  • Add other routing strategies (now preferencial ordering only)
  • Avoid getting preference listing from table ordering

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

llamux-0.1.4.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

llamux-0.1.4-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file llamux-0.1.4.tar.gz.

File metadata

  • Download URL: llamux-0.1.4.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.13.0 Darwin/22.6.0

File hashes

Hashes for llamux-0.1.4.tar.gz
Algorithm Hash digest
SHA256 ac44de7f1e9dd5ee070f34f11da24bbdf40a420ca64df1b8306c89764d38ac40
MD5 adbff02e2558592f7c6180ccf0f7e989
BLAKE2b-256 fd65d815f53cd7dc359715f2399d1956597f34a366d1954fa7e7a5f8bf4d66b8

See more details on using hashes here.

File details

Details for the file llamux-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: llamux-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.13.0 Darwin/22.6.0

File hashes

Hashes for llamux-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8d3ff35c3f8e444b89bcd68a861f06c60bce1114aaa8063a8bd7cee263922ab8
MD5 6b15302373b5d1bbf8d7b78d2f46c7a1
BLAKE2b-256 4fbe1c5f092b280301385f495341ab8ee5244f75481d7913a3dbb557876ead8f

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