# 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
## Installation
```bash
pip install indoxrouter
```
## Usage
### Initialization
```python
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
```python
# Authentication is handled automatically when creating the client
client = Client(api_key="your_api_key")
```
### Chat Completions
```python
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
```python
response = client.completion(
prompt="Once upon a time,",
model="openai/gpt-4o-mini",
max_tokens=100
)
print(response["data"])
```
### Embeddings
```python
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
```python
# 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)
```
### Text-to-Speech
```python
# 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
```python
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
```python
# 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.
Raw data
{
"_id": null,
"home_page": null,
"name": "indoxrouter",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "ai, api, client, openai, anthropic, google, mistral, xai, imagen, grok, image-generation, text-to-speech, tts, audio",
"author": null,
"author_email": "indoxRouter Team <ashkan.eskandari.dev@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/4d/6f/ed7f5d9836c7e74cd5e098c08c6309aec52a9870d282772fbd0d5745ffd5/indoxrouter-0.1.25.tar.gz",
"platform": null,
"description": "# IndoxRouter\r\n\r\nA unified client for various AI providers, including OpenAI, anthropic, Google, and Mistral.\r\n\r\n## Features\r\n\r\n- **Unified API**: Access multiple AI providers through a single API\r\n- **Simple Interface**: Easy-to-use methods for chat, completion, embeddings, image generation, and text-to-speech\r\n- **Error Handling**: Standardized error handling across providers\r\n- **Authentication**: Secure cookie-based authentication\r\n\r\n## Installation\r\n\r\n```bash\r\npip install indoxrouter\r\n```\r\n\r\n## Usage\r\n\r\n### Initialization\r\n\r\n```python\r\nfrom indoxrouter import Client\r\n\r\n# Initialize with API key\r\nclient = Client(api_key=\"your_api_key\")\r\n\r\n# Using environment variables\r\n# Set INDOX_ROUTER_API_KEY environment variable\r\nimport os\r\nos.environ[\"INDOX_ROUTER_API_KEY\"] = \"your_api_key\"\r\nclient = Client()\r\n```\r\n\r\n### Authentication\r\n\r\nIndoxRouter uses cookie-based authentication with JWT tokens. The client handles this automatically by:\r\n\r\n1. Taking your API key and exchanging it for JWT tokens using the server's authentication endpoints\r\n2. Storing the JWT tokens in cookies\r\n3. Using the cookies for subsequent requests\r\n4. Automatically refreshing tokens when they expire\r\n\r\n```python\r\n# Authentication is handled automatically when creating the client\r\nclient = Client(api_key=\"your_api_key\")\r\n```\r\n\r\n### Chat Completions\r\n\r\n```python\r\nresponse = client.chat(\r\n messages=[\r\n {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\r\n {\"role\": \"user\", \"content\": \"Tell me a joke.\"}\r\n ],\r\n model=\"openai/gpt-4o-mini\", # Provider/model format\r\n temperature=0.7\r\n)\r\n\r\nprint(response[\"data\"])\r\n```\r\n\r\n### Text Completions\r\n\r\n```python\r\nresponse = client.completion(\r\n prompt=\"Once upon a time,\",\r\n model=\"openai/gpt-4o-mini\",\r\n max_tokens=100\r\n)\r\n\r\nprint(response[\"data\"])\r\n```\r\n\r\n### Embeddings\r\n\r\n```python\r\nresponse = client.embeddings(\r\n text=[\"Hello world\", \"AI is amazing\"],\r\n model=\"openai/text-embedding-3-small\"\r\n)\r\n\r\nprint(f\"Dimensions: {len(response['data'][0]['embedding'])}\")\r\nprint(f\"First embedding: {response['data'][0]['embedding'][:5]}...\")\r\n```\r\n\r\n### Image Generation\r\n\r\n```python\r\n# OpenAI Image Generation\r\nresponse = client.images(\r\n prompt=\"A serene landscape with mountains and a lake\",\r\n model=\"openai/dall-e-3\",\r\n size=\"1024x1024\",\r\n quality=\"standard\", # Options: standard, hd\r\n style=\"vivid\" # Options: vivid, natural\r\n)\r\n\r\nprint(f\"Image URL: {response['data'][0]['url']}\")\r\n\r\n\r\n# Access base64 encoded image data\r\nif \"b64_json\" in response[\"data\"][0]:\r\n b64_data = response[\"data\"][0][\"b64_json\"]\r\n # Use the base64 data (e.g., to display in HTML or save to file)\r\n```\r\n\r\n### Text-to-Speech\r\n\r\n```python\r\n# Generate audio from text\r\nresponse = client.text_to_speech(\r\n input=\"Hello, welcome to IndoxRouter!\",\r\n model=\"openai/tts-1\",\r\n voice=\"alloy\", # Options: alloy, echo, fable, onyx, nova, shimmer\r\n response_format=\"mp3\", # Options: mp3, opus, aac, flac\r\n speed=1.0 # Range: 0.25 to 4.0\r\n)\r\n\r\nprint(f\"Audio generated successfully: {response['success']}\")\r\nprint(f\"Audio data available: {'data' in response}\")\r\n```\r\n\r\n### Streaming Responses\r\n\r\n```python\r\nfor chunk in client.chat(\r\n messages=[{\"role\": \"user\", \"content\": \"Write a short story.\"}],\r\n model=\"openai/gpt-4o-mini\",\r\n stream=True\r\n):\r\n if chunk.choices[0].delta.content:\r\n print(chunk.choices[0].delta.content, end=\"\", flush=True)\r\n```\r\n\r\n### Getting Available Models\r\n\r\n```python\r\n# Get all providers and models\r\nproviders = client.models()\r\nfor provider in providers:\r\n print(f\"Provider: {provider['name']}\")\r\n for model in provider[\"models\"]:\r\n print(f\" - {model['id']}: {model['description'] or ''}\")\r\n\r\n# Get models for a specific provider\r\nopenai_provider = client.models(\"openai\")\r\nprint(f\"OpenAI models: {[m['id'] for m in openai_provider['models']]}\")\r\n```\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License - see the LICENSE file for details.\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A unified client for various AI providers",
"version": "0.1.25",
"project_urls": {
"Homepage": "https://github.com/indoxrouter/indoxrouter",
"Issues": "https://github.com/indoxrouter/indoxrouter/issues",
"Repository": "https://github.com/indoxrouter/indoxrouter"
},
"split_keywords": [
"ai",
" api",
" client",
" openai",
" anthropic",
" google",
" mistral",
" xai",
" imagen",
" grok",
" image-generation",
" text-to-speech",
" tts",
" audio"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "b117a2c7faa7b85a3ffc6ea50db8d7b1e9bda5d0316664de6fbb41617e8aa137",
"md5": "04ce8a66687c747865223eee997f897e",
"sha256": "78d646158dfaba0724acc9bc2d9b9eb3770eae1c64a6e4f83df74f3e05e3748d"
},
"downloads": -1,
"filename": "indoxrouter-0.1.25-py3-none-any.whl",
"has_sig": false,
"md5_digest": "04ce8a66687c747865223eee997f897e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 23460,
"upload_time": "2025-07-27T10:28:10",
"upload_time_iso_8601": "2025-07-27T10:28:10.045424Z",
"url": "https://files.pythonhosted.org/packages/b1/17/a2c7faa7b85a3ffc6ea50db8d7b1e9bda5d0316664de6fbb41617e8aa137/indoxrouter-0.1.25-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "4d6fed7f5d9836c7e74cd5e098c08c6309aec52a9870d282772fbd0d5745ffd5",
"md5": "de3d3552d1cd436670156d1a827ac41e",
"sha256": "06f9b5fd9fe3381f38d519dd381500310b2c7854d51e3781149f7c8b95d40c1f"
},
"downloads": -1,
"filename": "indoxrouter-0.1.25.tar.gz",
"has_sig": false,
"md5_digest": "de3d3552d1cd436670156d1a827ac41e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 36129,
"upload_time": "2025-07-27T10:28:11",
"upload_time_iso_8601": "2025-07-27T10:28:11.815982Z",
"url": "https://files.pythonhosted.org/packages/4d/6f/ed7f5d9836c7e74cd5e098c08c6309aec52a9870d282772fbd0d5745ffd5/indoxrouter-0.1.25.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-27 10:28:11",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "indoxrouter",
"github_project": "indoxrouter",
"github_not_found": true,
"lcname": "indoxrouter"
}