Skip to main content

A unified interface for various LLM providers

Project description

indoxRouter

indoxRouter Logo

A unified interface for various LLM providers

PyPI version License GitHub stars

Overview

indoxRouter is a powerful Python library that provides a unified interface to interact with various Large Language Model (LLM) providers. With a single API key, you can access models from OpenAI, Anthropic, Mistral, Google, and more, without having to manage multiple provider-specific API keys and implementations.

Key Features

  • Single API for Multiple Providers: Access models from OpenAI, Anthropic, Mistral, Google, and more with a single API key
  • Standardized Response Format: Consistent response format across all providers
  • Streaming Support: Stream responses for real-time applications
  • Cost Tracking: Track token usage and costs across providers
  • Rate Limiting: Built-in rate limiting to prevent exceeding provider quotas
  • Error Handling: Comprehensive error handling with detailed error messages
  • Authentication: Secure authentication with JWT tokens
  • Type Hints: Full type hints for better IDE support

Installation

pip install indoxRouter

For development:

pip install indoxRouter[dev]

Quick Start

from indoxRouter import Client
from indoxRouter.models import ChatMessage

# Initialize the client with your API key
client = Client(api_key="your-api-key")

# Chat completion with OpenAI
response = client.chat(
    messages=[
        {"role": "user", "content": "What are three fun activities to do in New York?"}
    ],
    model="openai/gpt-4o-mini",
    temperature=0.7,
    max_tokens=500,
)

print(response.data)

Available Providers

indoxRouter supports the following providers:

  • OpenAI
  • Anthropic (Claude)
  • Mistral
  • Google
  • Cohere

Core Features

Chat Completion

response = client.chat(
    messages=[
        {"role": "user", "content": "What are three fun activities to do in New York?"}
    ],
    model="openai/gpt-4o-mini",
    temperature=0.7,
    max_tokens=500,
)

Text Completion

response = client.completion(
    prompt="Write a short story about a robot learning to paint.",
    model="anthropic/claude-3-haiku",
    temperature=0.7,
    max_tokens=500,
)

Embeddings

response = client.embeddings(
    text="This is a sample text to embed.",
    model="openai/text-embedding-3-small",
)

Image Generation

response = client.image(
    prompt="A futuristic city with flying cars and neon lights",
    model="openai/dall-e-3",
    size="1024x1024",
)

Streaming

generator = client.chat(
    messages=[
        {"role": "user", "content": "Write a short story about a robot learning to paint."}
    ],
    model="openai/gpt-4o-mini",
    temperature=0.7,
    max_tokens=500,
    stream=True,
    return_generator=True,
)

for chunk in generator:
    if isinstance(chunk, dict) and chunk.get("is_usage_info"):
        # This is the final usage info
        usage_info = chunk
    else:
        # This is a content chunk
        print(chunk, end="", flush=True)

Provider and Model Information

# List all available providers
providers = client.providers()

# List all available models
models = client.models()

# List models for a specific provider
openai_models = client.models(provider="openai")

# Get information about a specific model
model_info = client.model_info(provider="openai", model="gpt-4o-mini")

Configuration

indoxRouter can be configured using environment variables or a configuration file:

# Set API key via environment variable
import os
os.environ["INDOX_ROUTER_API_KEY"] = "your-api-key"

# Or provide it directly to the client
client = Client(api_key="your-api-key")

Error Handling

indoxRouter provides comprehensive error handling:

from indoxRouter import Client
from indoxRouter.exceptions import AuthenticationError, RateLimitError, ProviderError

try:
    client = Client(api_key="invalid-api-key")
except AuthenticationError as e:
    print(f"Authentication error: {e}")

try:
    response = client.chat(
        messages=[{"role": "user", "content": "Hello"}],
        model="nonexistent-model",
    )
except ProviderError as e:
    print(f"Provider error: {e}")

Documentation

For detailed documentation, visit https://docs.indoxrouter.com.

Examples

Check out the examples directory for more examples.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file 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

indoxrouter-0.1.2.tar.gz (36.7 kB view details)

Uploaded Source

Built Distribution

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

indoxrouter-0.1.2-py3-none-any.whl (46.7 kB view details)

Uploaded Python 3

File details

Details for the file indoxrouter-0.1.2.tar.gz.

File metadata

  • Download URL: indoxrouter-0.1.2.tar.gz
  • Upload date:
  • Size: 36.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for indoxrouter-0.1.2.tar.gz
Algorithm Hash digest
SHA256 5048ca96c88f31800d0a724a5d08c254e0991d6e381c1c4108e3b5551da6e4fd
MD5 879cc893dc24276b93ba60434d3d13fb
BLAKE2b-256 872a5e1fe6579e4d269815f817657aaff29f690a4a583bdcdbdf84b8ae70d9cc

See more details on using hashes here.

File details

Details for the file indoxrouter-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: indoxrouter-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 46.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for indoxrouter-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8604e4d3b700a0c03e8b15d5aa9752acb50fdc98e3a1849cbd9007000aee86b0
MD5 7dd2eb3270b6f930808fb3a7c8968bf2
BLAKE2b-256 c44da92f1d8aa147a1d7054e28fe0630ab5648d700372187a2ba9962a7ec8a0b

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