Skip to main content

NexusAI-Client - Unified Multi-Provider AI Gateway

NexusAI-Client โšก

An ultra-lightweight, strictly-typed, asynchronous Python gateway for multi-provider AI APIs.
Unify Cerebras, Cohere, DeepSeek, Google Gemini (Free & Pro), Groq, Mistral, Nvidia NIM, OpenRouter, and OrcaRouter behind a single, elegant interface with zero heavy SDK dependencies.

PyPI version Python versions License MIT httpx Typing


๐Ÿ’ก Why NexusAI-Client?

Integrating multiple AI providers in modern Python applications usually requires installing 9 or 10 separate proprietary SDKs (google-genai, openai, groq, cohere, mistralai, etc.). This creates dozens of transitive dependencies, version conflicts, memory overhead, and fragmented codebases.

NexusAI-Client solves this at the core:

  • ๐Ÿชถ Zero Heavyweight Dependencies โ€” powered purely by httpx and python-dotenv.
  • โšก Native Asynchronous & SSE Streaming โ€” stream responses token-by-token in real time via stream_text() and stream_chat().
  • ๐Ÿ”„ Zero-Cost-First Smart Fallback โ€” automatic progression from 100% free tiers (Gemini, Groq, Cerebras, Cohere, Nvidia, OpenRouter, OrcaRouter, Mistral) to paid backups with AIGateway.auto_fallback().
  • ๐Ÿš€ World-Record Hardware Accelerators โ€” native support for Groq LPUs and Cerebras CS-3 wafer-scale engines (2,000+ tokens/sec).
  • ๐Ÿง  Enterprise Reasoning & Search Models โ€” native Cohere Command R+, DeepSeek R1, and Qwen 3.8 models.
  • ๐ŸŽฏ Guaranteed JSON Outputs โ€” native json_mode=True across all supported providers.
  • ๐Ÿ’ฐ Live Account & Budget Inspection โ€” inspect real-time balances (USD, NGC credits) and rate limits (RPM, TPM, RPD).
  • ๐Ÿ” 670+ Models Discovered Live โ€” automatic detection of free-tier models (:free, -free) and accurate per-million-token pricing.
  • ๐Ÿ‘๏ธ Multimodal Vision โ€” analyze images, charts, and documents with automatic vision-model resolution via analyze_image() and AIGateway.auto_fallback_vision().

๐ŸŒŸ Spotlight: Zero-Cost-First Smart Fallback Routing

Why pay for AI calls when you can leverage high-throughput free tiers first, with seamless automatic fallback to paid commercial models?

NexusAI-Client automatically prioritizes zero-cost models before touching your wallet:

  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚                                               100% FREE ZERO-COST TIERS                                                โ”‚
  โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
  โ”‚ 1. Gemini    โ”‚ 2. Groq LPU  โ”‚ 3. Cerebras CS-3 โ”‚ 4. Nvidia    โ”‚ 5. OpenRouterโ”‚ 6. OrcaRouterโ”‚ 7. Cohere    โ”‚ 8. Mistralโ”‚
  โ”‚ (1M Context) โ”‚ (Ultra-Fast) โ”‚ (2000+ tok/s)    โ”‚ (1k Credits) โ”‚ (Free Hub)   โ”‚ (Qwen/DeepS) โ”‚ (Command R+) โ”‚ (Dev Free)โ”‚
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚              โ”‚                โ”‚                โ”‚              โ”‚              โ”‚              โ”‚             โ”‚
         โ–ผ (If Rate-Limited / 429 Quota Exceeded / Network Outage / Timeout) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผ
  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚                                           ULTRA-LOW-COST PAID BACKUP TIERS                                             โ”‚
  โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
  โ”‚ 9. DeepSeek ($0.27 / 1M tokens)                            โ”‚ 10. Gemini Pro (Enterprise GCP)                           โ”‚
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

1-Line Zero-Cost Failover in Your Code

import asyncio
from nexusai_client import AIGateway

async def main():
    # Automatically discovers active keys in .env and routes: Free -> Free -> Paid
    async with AIGateway.auto_fallback() as client:
        response = await client.generate_text("Explain quantum computing in 2 sentences.")
        print(f"โœ… Served by [{response.provider}] with zero downtime:")
        print(response.text)

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

๐ŸŽฏ Supported Providers Matrix

Provider Identifier (provider) Tier Protocol Default Model Live Budget & Quota Detection
Cerebras "cerebras" (or "cerebras_free") Free (CS-3) OpenAI Chat API gpt-oss-120b Quotas: 30 RPM | 60k TPM | 1M tok/day
Cohere "cohere" (or "cohere_free") Free Trial Cohere V2 REST command-r-plus-08-2024 Quotas: 20 RPM | 1,000 calls/month
DeepSeek "deepseek" Paid OpenAI Chat API deepseek-chat Real-time USD Balance (GET /user/balance)
Gemini Free "gemini_free" Free (AI Studio) Gemini REST gemini-2.5-flash Quotas: 15 RPM | 1M TPM | 1,500 RPD
Gemini Pro "gemini_pro" Paid Gemini REST gemini-2.5-pro Google Cloud Pay-as-you-go Billing
Groq "groq" (or "groq_free") Free (LPU) OpenAI Chat API llama-3.3-70b-versatile Quotas: 30 RPM | 14,400 RPD | 30k TPM
Mistral AI "mistral" Free / Platform OpenAI Chat API mistral-small-latest Free Dev Models (codestral-latest, etc.)
Nvidia NIM "nvidia_free" Free (NGC) OpenAI Chat API meta/llama-3.1-8b-instruct 1,000 Free GPU Inference Credits (NGC)
OpenRouter "openrouter" Free & Paid OpenAI Chat API openrouter/free 19 Free models live + 390 Commercial models
OrcaRouter "orcarouter" (or "orcarouter_free") Free & Paid OpenAI Chat API qwen/qwen3.8-27b-free Zero-margin gateway + Free tier models (-free)

๐Ÿš€ Quickstart (1 Minute)

1. Installation

# With pip
pip install nexusai-client

# With uv (Recommended)
uv add nexusai-client

# With poetry
poetry add nexusai-client

2. Configure API Keys (.env)

No configuration code needed: as soon as you import nexusai_client, the package automatically loads the .env file found in your current working directory (via python-dotenv). Real environment variables always take precedence.

Create a .env file at the root of your project with only the keys you have โ€” every provider is optional:

# โ”€โ”€ Free Tiers (Priority 1) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
GEMINI_FREE_API_KEY=your_google_ai_studio_key
GROQ_API_KEY=gsk_your_groq_key
CEREBRAS_API_KEY=csk-your_cerebras_key
COHERE_API_KEY=your_cohere_key
NVIDIA_API_KEY=nvapi-your_nvidia_nim_key
OPENROUTER_API_KEY=sk-or-v1-your_openrouter_key
ORCAROUTER_API_KEY=sk-orca-your_orcarouter_key
MISTRAL_API_KEY=your_mistral_api_key

# โ”€โ”€ Paid Tiers (Backup Priority 2) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
DEEPSEEK_API_KEY=sk-your_deepseek_key
GEMINI_PRO_API_KEY=your_gemini_pro_key

Where to get each API key

Provider Environment Variable Get a key
Gemini Free GEMINI_FREE_API_KEY Google AI Studio
Gemini Pro GEMINI_PRO_API_KEY Google AI Studio / GCP
Groq GROQ_API_KEY console.groq.com/keys
Cerebras CEREBRAS_API_KEY cloud.cerebras.ai
Cohere COHERE_API_KEY dashboard.cohere.com
Nvidia NIM NVIDIA_API_KEY build.nvidia.com
OpenRouter OPENROUTER_API_KEY openrouter.ai/keys
OrcaRouter ORCAROUTER_API_KEY www.orcarouter.ai/console
Mistral MISTRAL_API_KEY console.mistral.ai
DeepSeek DEEPSEEK_API_KEY platform.deepseek.com

Notes:

  • GEMINI_API_KEY is accepted as a fallback alias for both GEMINI_FREE_API_KEY and GEMINI_PRO_API_KEY.
  • You can also pass a key directly in code: AIGateway("groq", api_key="gsk_...") โ€” useful for CI/CD or key rotation without touching .env.

Optional advanced environment variables

Variable Purpose Default
DEEPSEEK_DEFAULT_MODEL, GROQ_DEFAULT_MODEL, CEREBRAS_DEFAULT_MODEL, ... Override the default model of a provider Provider defaults (see matrix above)
DEEPSEEK_BASE_URL, GROQ_BASE_URL, MISTRAL_BASE_URL, ... Point a provider at a custom endpoint or proxy Official provider API URL
NEXUS_DEFAULT_TIMEOUT Global request timeout in seconds (all providers) 60
OPENROUTER_SITE_URL / OPENROUTER_APP_NAME App attribution headers sent to OpenRouter https://github.com/NexusAI-Client / NexusAI-Client

3. Basic Generation

import asyncio
from nexusai_client import AIGateway

async def main():
    async with AIGateway("cerebras") as client:
        response = await client.generate_text("Explain the theory of relativity in 2 sentences.")
        print(response.text)

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

๐Ÿณ Cookbooks & Common Patterns

1. Real-Time Token Streaming (SSE)

import asyncio
from nexusai_client import AIGateway

async def main():
    async with AIGateway("groq") as client:
        async for chunk in client.stream_text("Write a short poem about lightning fast LPUs."):
            print(chunk, end="", flush=True)

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

2. Custom Fallback Chain (Fine-Grained Strategy)

import asyncio
from nexusai_client import AIGateway

async def main():
    # Priority: Free Gemini -> Free Groq -> Free Cerebras -> Free Cohere -> Paid DeepSeek
    custom_chain = ["gemini_free", "groq", "cerebras", "cohere", "nvidia_free", "openrouter", "deepseek"]
    async with AIGateway.with_fallback(custom_chain) as client:
        res = await client.generate_text("Summarize the key advantages of Python 3.14.")
        print(f"[{res.provider}] {res.text}")

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

3. Multi-Turn Conversation (Chat)

import asyncio
from nexusai_client import AIGateway, ChatMessage

async def main():
    history = [
        ChatMessage(role="system", content="You are a senior algorithms instructor."),
        ChatMessage(role="user", content="How does QuickSort work?"),
    ]
    async with AIGateway("cohere") as client:
        response = await client.chat(history)
        print(response.text)

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

4. Guaranteed Structured JSON Output

import asyncio, json
from nexusai_client import AIGateway

async def main():
    async with AIGateway("groq") as client:
        res = await client.generate_text(
            prompt="Extract profile data: Alice, 28 years old, Software Engineer.",
            json_mode=True,
        )
        data = json.loads(res.text)
        print("Parsed JSON:", data)

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

5. Inspect Real-Time Account Balances & Quotas

import asyncio
from nexusai_client import AIGateway

async def main():
    async with AIGateway("deepseek") as client:
        account = await client.get_account_info()
        print(account.format_summary())
        # Output: "Solde restant: $4.99 | (Offert: $0.00)"

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

6. Multimodal Vision Analysis (Images, Charts, PDFs)

Pass a local file path (Path or str), raw bytes, or web URL:

import asyncio
from nexusai_client import AIGateway

async def main():
    # Automatically selects the best Vision model (Gemini 2.5 Flash, Llama 3.2 Vision, Aya Vision, Pixtral)
    async with AIGateway.auto_fallback_vision() as client:
        res = await client.analyze_image(
            prompt="Extract the invoice total and line items formatted as JSON.",
            image="invoice.png", # or "https://example.com/chart.jpg" or raw bytes
            json_mode=True,
        )
        print(f"[{res.provider} / {res.model}]:")
        print(res.text)

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

๐Ÿ›ก๏ธ Strongly-Typed Exceptions

All exceptions inherit from NexusAIError for clean error handling:

from nexusai_client import (
    AIGateway,
    NexusAIError,
    MissingAPIKeyError,    # Missing API key in environment
    AuthenticationError,   # Invalid key (HTTP 401/403)
    RateLimitError,        # Quota exceeded (HTTP 429)
    APITimeoutError,       # Network timeout
    APIConnectionError,    # Unreachable provider host
    ProviderNotFoundError, # Unknown provider requested
)

The package ships a py.typed marker (PEP 561): all types are available to your IDE and type checker out of the box.


๐Ÿ“š Resources


๐Ÿ“„ License

This project is licensed under the MIT License. Free for personal and commercial use.

Download files

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

Source Distribution

nexusai_client-0.2.0.tar.gz (31.2 kB view details)

Uploaded Source

Built Distribution

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

nexusai_client-0.2.0-py3-none-any.whl (45.6 kB view details)

Uploaded Python 3

File details

Details for the file nexusai_client-0.2.0.tar.gz.

File metadata

  • Download URL: nexusai_client-0.2.0.tar.gz
  • Upload date:
  • Size: 31.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.5 {"installer":{"name":"uv","version":"0.11.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for nexusai_client-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0d6cbde2808e808b1e7ff8c14d54b6c67762b4dca75a03e887927a92bb30b980
MD5 93e5795fcffd755e18e03c210a738ecc
BLAKE2b-256 69377677aba36060c3ee6a4c4b3655e997d470e73e3a512714f61016eb7e3f48

See more details on using hashes here.

File details

Details for the file nexusai_client-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: nexusai_client-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 45.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.5 {"installer":{"name":"uv","version":"0.11.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for nexusai_client-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d26b3c50e27fb53298a114bfaaf49d217edfd4b840ae6eb7135d13d8bdbba37a
MD5 bd4661b16362831701d1b7495c8fb4fe
BLAKE2b-256 6e78bb2363d63ce3b96892f341228f9eddeafe9451fb088360be3367ffe71a94

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