Skip to main content

A unified client for various AI providers

Project description

IndoxRouter

A unified client for various AI providers, including OpenAI, anthropic, Google, and Mistral.

Features

  • Unified API: Access multiple AI providers through a single API
  • Simple Interface: Easy-to-use methods for chat, completion, embeddings, image generation, and text-to-speech
  • Error Handling: Standardized error handling across providers
  • Authentication: Secure cookie-based authentication
  • BYOK Support: Bring Your Own Key support for using your own provider API keys

Installation

pip install indoxrouter

Usage

Initialization

from indoxrouter import Client

# Initialize with API key
client = Client(api_key="your_api_key")

# Using environment variables
# Set INDOX_ROUTER_API_KEY environment variable
import os
os.environ["INDOX_ROUTER_API_KEY"] = "your_api_key"
client = Client()

Authentication

IndoxRouter uses cookie-based authentication with JWT tokens. The client handles this automatically by:

  1. Taking your API key and exchanging it for JWT tokens using the server's authentication endpoints
  2. Storing the JWT tokens in cookies
  3. Using the cookies for subsequent requests
  4. Automatically refreshing tokens when they expire
# Authentication is handled automatically when creating the client
client = Client(api_key="your_api_key")

Chat Completions

response = client.chat(
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Tell me a joke."}
    ],
    model="openai/gpt-4o-mini",  # Provider/model format
    temperature=0.7
)

print(response["data"])

Text Completions

response = client.completion(
    prompt="Once upon a time,",
    model="openai/gpt-4o-mini",
    max_tokens=100
)

print(response["data"])

Embeddings

response = client.embeddings(
    text=["Hello world", "AI is amazing"],
    model="openai/text-embedding-3-small"
)

print(f"Dimensions: {len(response['data'][0]['embedding'])}")
print(f"First embedding: {response['data'][0]['embedding'][:5]}...")

Image Generation

# OpenAI Image Generation
response = client.images(
    prompt="A serene landscape with mountains and a lake",
    model="openai/dall-e-3",
    size="1024x1024",
    quality="standard",  # Options: standard, hd
    style="vivid"  # Options: vivid, natural
)

print(f"Image URL: {response['data'][0]['url']}")


# Access base64 encoded image data
if "b64_json" in response["data"][0]:
    b64_data = response["data"][0]["b64_json"]
    # Use the base64 data (e.g., to display in HTML or save to file)

BYOK (Bring Your Own Key) Support

IndoxRouter supports BYOK, allowing you to use your own API keys for AI providers:

# Use your own OpenAI API key
response = client.chat(
    messages=[{"role": "user", "content": "Hello!"}],
    model="openai/gpt-4",
    byok_api_key="sk-your-openai-key-here"
)

# Use your own Google API key for image generation
response = client.images(
    prompt="A beautiful sunset",
    model="google/imagen-3.0-generate-002",
    aspect_ratio="16:9",
    byok_api_key="your-google-api-key-here"
)

BYOK Benefits:

  • No credit deduction from your IndoxRouter account
  • No platform rate limiting
  • Direct provider access with your own API keys
  • Cost control - pay providers directly at their rates

Text-to-Speech

# Generate audio from text
response = client.text_to_speech(
    input="Hello, welcome to IndoxRouter!",
    model="openai/tts-1",
    voice="alloy",  # Options: alloy, echo, fable, onyx, nova, shimmer
    response_format="mp3",  # Options: mp3, opus, aac, flac
    speed=1.0  # Range: 0.25 to 4.0
)

print(f"Audio generated successfully: {response['success']}")
print(f"Audio data available: {'data' in response}")

Streaming Responses

for chunk in client.chat(
    messages=[{"role": "user", "content": "Write a short story."}],
    model="openai/gpt-4o-mini",
    stream=True
):
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

Getting Available Models

# Get all providers and models
providers = client.models()
for provider in providers:
    print(f"Provider: {provider['name']}")
    for model in provider["models"]:
        print(f"  - {model['id']}: {model['description'] or ''}")

# Get models for a specific provider
openai_provider = client.models("openai")
print(f"OpenAI models: {[m['id'] for m in openai_provider['models']]}")

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.27.tar.gz (25.3 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.27-py3-none-any.whl (24.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: indoxrouter-0.1.27.tar.gz
  • Upload date:
  • Size: 25.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for indoxrouter-0.1.27.tar.gz
Algorithm Hash digest
SHA256 6faf81e5544f8125e43d45b30676d6a4ee48fa25892651f7fd879323d37f0c6f
MD5 afd8b7fcae396c34b923e55f966cd034
BLAKE2b-256 76ad8c0ad9741754f3f86d443e3cafb6f966f82039904a660bb88a3f8fe6dc38

See more details on using hashes here.

File details

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

File metadata

  • Download URL: indoxrouter-0.1.27-py3-none-any.whl
  • Upload date:
  • Size: 24.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for indoxrouter-0.1.27-py3-none-any.whl
Algorithm Hash digest
SHA256 875b277ad1b6df56248a5a097c9f9af3defef6be4273b172b7bfb45644065531
MD5 b4c0d96901563cc4f59c83bcb43c11a8
BLAKE2b-256 8b58ca7e95cfd7ce49d503357c3d63a9ed6f83b8b304876f2eb4b837d4b8ee78

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