Skip to main content

Multi-provider LLM router with async streaming and round-robin fallback.

Project description

NoLimitAI

NolimitAI Logo

PyPI version Python versions Downloads License

NoLimitAI is a Python library designated to route LLM requests across multiple providers (Groq, OpenRouter, Together AI, Gemini, Mistral) with built-in round-robin load balancing and automatic failover. It simplifies managing multiple AI services through a single, unified asynchronous API.

Features

  • Multi-Provider Support: Seamlessly switch between Groq, OpenRouter, Together AI, Google Gemini, and Mistral AI.
  • Round-Robin & Fallback: Automatically rotates through configured providers to distribute load and handles failures by retrying with the next available service.
  • Async Streaming: Native async/await support with streaming responses.
  • Unified Interface: Use one standard API for all providers.

Installation

Install the package from PyPI:

pip install nolimit-ai

You can view the project on PyPI here: https://pypi.org/project/nolimitai/

Usage

Here is a complete example of how to configure and use NoLimitAI.

1. Basic Setup

You need to provide API keys for the services you want to use. The library does not automatically load environment variables; you must pass them explicitly.

import asyncio
import os
from nolimitai import NolimitAI

# Optional: Load environment variables from a .env file
# from dotenv import load_dotenv
# load_dotenv()

async def main():
    # Initialize the client
    nlai = NolimitAI()

    # Configure the client with your API keys and optional parameters
    # You only need to provide keys for the services you intend to use.
    nlai.set_config(
        temperature=0.7,
        max_tokens=1024,
        top_p=0.9,
        keys={
            "groq": os.getenv("GROQ_API_KEY"),
            "openrouter": os.getenv("OPENROUTER_API_KEY"),
            "gemini_ai": os.getenv("GEMINI_API_KEY"),
            "mistral_ai": os.getenv("MISTRAL_API_KEY"),
            "together_ai": os.getenv("TOGETHER_API_KEY"),
        }
    )

    prompt = "Explain the concept of round-robin scheduling in one sentence."

    print(f"--- Asking: {prompt} ---\n")

    # Check which service is next in line (optional)
    next_service = nlai.get_next_service()
    print(f"[Next Service]: {next_service}")

    try:
        # Stream the response
        print("[Response]: ", end="", flush=True)
        async for token in nlai.chat(prompt=prompt):
            print(token, end="", flush=True)
        print("\n")
        
        # Check which service actually handled the request
        used_service = nlai.get_last_used_service()
        print(f"[Used Service]: {used_service}")

    except Exception as e:
        print(f"\nAn error occurred: {e}")

if __name__ == "__main__":
    asyncio.run(main())

2. Configuration Options

The set_config method accepts the following parameters:

  • temperature (float): Sampling temperature (0.0 to 1.0).
  • max_tokens (int): Maximum number of tokens to generate.
  • top_p (float): Nucleus sampling parameter.
  • keys (dict): A dictionary mapping provider names to API keys.

Supported Keys:

  • "groq"
  • "openrouter"
  • "together_ai"
  • "gemini_ai"
  • "mistral_ai"

Important Notes

  • Failover: If a service fails to connect or authorize, the router will automatically try the next configured service in the list.

Troubleshooting

  • RuntimeError: NoLimitIA no ha sido configurado: This error occurs if you try to call chat() before calling set_config(). Ensure you configure the instance with at least one valid API key.
  • Authentication Errors: Ensure your API keys are correct. If a key is invalid, the router will treat it as a failure and attempt to switch to another provider if available.

License

This project is licensed under the Apache-2.0 License.

Documentación en español

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

nolimit_ai-0.1.1.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

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

nolimit_ai-0.1.1-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nolimit_ai-0.1.1.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for nolimit_ai-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5788baab66627192ab14c57e3530669d54d3a4d72d30cd2748f703f723d79606
MD5 c0563f8f447ce6298a1558268f6e6556
BLAKE2b-256 3fb137b0b074b226bd68990495c34515277b880ee2ac45781f871aedd2aae882

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nolimit_ai-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 21.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for nolimit_ai-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ba71b62f119ab9d58a003b63e03f527e70cb79d85edd0ea0c49f918db06eb843
MD5 9d628a855b4d79fc831a0de29d685b43
BLAKE2b-256 93ae457a87ea2d6737d27dac3cdf8d58fcd4aa71a2146713c204994ebe21f257

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