indoxrouter 0.1.25__py3-none-any.whl → 0.1.27__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
indoxrouter/constants.py CHANGED
@@ -1,38 +1,38 @@
1
- """
2
- Constants for the IndoxRouter client.
3
- """
4
-
5
- # API settings
6
- DEFAULT_API_VERSION = "v1"
7
- DEFAULT_BASE_URL = "https://api.indoxrouter.com" # Production server URL with HTTPS
8
- # DEFAULT_BASE_URL = "http://localhost:8000" # Local development server
9
- DEFAULT_TIMEOUT = 60
10
- USE_COOKIES = True # Always use cookie-based authentication
11
-
12
- # Default models
13
- DEFAULT_MODEL = "openai/gpt-4o-mini"
14
- DEFAULT_EMBEDDING_MODEL = "openai/text-embedding-3-small"
15
- DEFAULT_IMAGE_MODEL = "openai/dall-e-3"
16
- DEFAULT_TTS_MODEL = "openai/tts-1"
17
- GOOGLE_IMAGE_MODEL = "google/imagen-3.0-generate-002"
18
- XAI_IMAGE_MODEL = "xai/grok-2-image"
19
- XAI_IMAGE_LATEST_MODEL = "xai/grok-2-image-latest"
20
- XAI_IMAGE_SPECIFIC_MODEL = "xai/grok-2-image-1212"
21
-
22
- # API endpoints
23
- CHAT_ENDPOINT = "chat/completions"
24
- COMPLETION_ENDPOINT = "completions"
25
- EMBEDDING_ENDPOINT = "embeddings"
26
- IMAGE_ENDPOINT = "images/generations"
27
- TTS_ENDPOINT = "tts/generations"
28
- MODEL_ENDPOINT = "models"
29
- USAGE_ENDPOINT = "user/usage"
30
-
31
- # Error messages
32
- ERROR_INVALID_API_KEY = "API key must be provided either as an argument or as the INDOXROUTER_API_KEY environment variable"
33
- ERROR_NETWORK = "Network error occurred while communicating with the IndoxRouter API"
34
- ERROR_RATE_LIMIT = "Rate limit exceeded for the IndoxRouter API"
35
- ERROR_PROVIDER_NOT_FOUND = "Provider not found"
36
- ERROR_MODEL_NOT_FOUND = "Model not found"
37
- ERROR_INVALID_PARAMETERS = "Invalid parameters provided"
38
- ERROR_INSUFFICIENT_CREDITS = "Insufficient credits"
1
+ """
2
+ Constants for the IndoxRouter client.
3
+ """
4
+
5
+ # API settings
6
+ DEFAULT_API_VERSION = "v1"
7
+ DEFAULT_BASE_URL = "https://api.indoxrouter.com" # Production server URL with HTTPS
8
+ # DEFAULT_BASE_URL = "http://localhost:8000" # Local development server
9
+ DEFAULT_TIMEOUT = 60
10
+ USE_COOKIES = True # Always use cookie-based authentication
11
+
12
+ # Default models
13
+ DEFAULT_MODEL = "openai/gpt-4o-mini"
14
+ DEFAULT_EMBEDDING_MODEL = "openai/text-embedding-3-small"
15
+ DEFAULT_IMAGE_MODEL = "openai/dall-e-3"
16
+ DEFAULT_TTS_MODEL = "openai/tts-1"
17
+ GOOGLE_IMAGE_MODEL = "google/imagen-3.0-generate-002"
18
+ XAI_IMAGE_MODEL = "xai/grok-2-image"
19
+ XAI_IMAGE_LATEST_MODEL = "xai/grok-2-image-latest"
20
+ XAI_IMAGE_SPECIFIC_MODEL = "xai/grok-2-image-1212"
21
+
22
+ # API endpoints
23
+ CHAT_ENDPOINT = "chat/completions"
24
+ COMPLETION_ENDPOINT = "completions"
25
+ EMBEDDING_ENDPOINT = "embeddings"
26
+ IMAGE_ENDPOINT = "images/generations"
27
+ TTS_ENDPOINT = "tts/generations"
28
+ MODEL_ENDPOINT = "models"
29
+ USAGE_ENDPOINT = "user/usage"
30
+
31
+ # Error messages
32
+ ERROR_INVALID_API_KEY = "API key must be provided either as an argument or as the INDOXROUTER_API_KEY environment variable"
33
+ ERROR_NETWORK = "Network error occurred while communicating with the IndoxRouter API"
34
+ ERROR_RATE_LIMIT = "Rate limit exceeded for the IndoxRouter API"
35
+ ERROR_PROVIDER_NOT_FOUND = "Provider not found"
36
+ ERROR_MODEL_NOT_FOUND = "Model not found"
37
+ ERROR_INVALID_PARAMETERS = "Invalid parameters provided"
38
+ ERROR_INSUFFICIENT_CREDITS = "Insufficient credits"
indoxrouter/exceptions.py CHANGED
@@ -1,86 +1,86 @@
1
- """
2
- Exceptions for the IndoxRouter client.
3
- """
4
-
5
- from datetime import datetime
6
- from typing import Optional
7
-
8
-
9
- class IndoxRouterError(Exception):
10
- """Base exception for all IndoxRouter errors."""
11
-
12
- pass
13
-
14
-
15
- class AuthenticationError(IndoxRouterError):
16
- """Raised when authentication fails."""
17
-
18
- pass
19
-
20
-
21
- class NetworkError(IndoxRouterError):
22
- """Raised when a network error occurs."""
23
-
24
- pass
25
-
26
-
27
- class RateLimitError(IndoxRouterError):
28
- """Raised when rate limits are exceeded."""
29
-
30
- def __init__(self, message: str, reset_time: Optional[datetime] = None):
31
- super().__init__(message)
32
- self.reset_time = reset_time
33
-
34
-
35
- class ProviderError(IndoxRouterError):
36
- """Raised when a provider returns an error."""
37
-
38
- pass
39
-
40
-
41
- class ProviderNotFoundError(ProviderError):
42
- """Raised when a requested provider is not found."""
43
-
44
- pass
45
-
46
-
47
- class ModelNotFoundError(ProviderError):
48
- """Raised when a requested model is not found."""
49
-
50
- pass
51
-
52
-
53
- class ModelNotAvailableError(ProviderError):
54
- """Raised when a model is disabled or not supported by the provider."""
55
-
56
- pass
57
-
58
-
59
- class InvalidParametersError(IndoxRouterError):
60
- """Raised when invalid parameters are provided."""
61
-
62
- pass
63
-
64
-
65
- class RequestError(IndoxRouterError):
66
- """Raised when a request to a provider fails."""
67
-
68
- pass
69
-
70
-
71
- class InsufficientCreditsError(IndoxRouterError):
72
- """Raised when the user doesn't have enough credits."""
73
-
74
- pass
75
-
76
-
77
- class ValidationError(IndoxRouterError):
78
- """Raised when request validation fails."""
79
-
80
- pass
81
-
82
-
83
- class APIError(IndoxRouterError):
84
- """Raised when the API returns an error."""
85
-
86
- pass
1
+ """
2
+ Exceptions for the IndoxRouter client.
3
+ """
4
+
5
+ from datetime import datetime
6
+ from typing import Optional
7
+
8
+
9
+ class IndoxRouterError(Exception):
10
+ """Base exception for all IndoxRouter errors."""
11
+
12
+ pass
13
+
14
+
15
+ class AuthenticationError(IndoxRouterError):
16
+ """Raised when authentication fails."""
17
+
18
+ pass
19
+
20
+
21
+ class NetworkError(IndoxRouterError):
22
+ """Raised when a network error occurs."""
23
+
24
+ pass
25
+
26
+
27
+ class RateLimitError(IndoxRouterError):
28
+ """Raised when rate limits are exceeded."""
29
+
30
+ def __init__(self, message: str, reset_time: Optional[datetime] = None):
31
+ super().__init__(message)
32
+ self.reset_time = reset_time
33
+
34
+
35
+ class ProviderError(IndoxRouterError):
36
+ """Raised when a provider returns an error."""
37
+
38
+ pass
39
+
40
+
41
+ class ProviderNotFoundError(ProviderError):
42
+ """Raised when a requested provider is not found."""
43
+
44
+ pass
45
+
46
+
47
+ class ModelNotFoundError(ProviderError):
48
+ """Raised when a requested model is not found."""
49
+
50
+ pass
51
+
52
+
53
+ class ModelNotAvailableError(ProviderError):
54
+ """Raised when a model is disabled or not supported by the provider."""
55
+
56
+ pass
57
+
58
+
59
+ class InvalidParametersError(IndoxRouterError):
60
+ """Raised when invalid parameters are provided."""
61
+
62
+ pass
63
+
64
+
65
+ class RequestError(IndoxRouterError):
66
+ """Raised when a request to a provider fails."""
67
+
68
+ pass
69
+
70
+
71
+ class InsufficientCreditsError(IndoxRouterError):
72
+ """Raised when the user doesn't have enough credits."""
73
+
74
+ pass
75
+
76
+
77
+ class ValidationError(IndoxRouterError):
78
+ """Raised when request validation fails."""
79
+
80
+ pass
81
+
82
+
83
+ class APIError(IndoxRouterError):
84
+ """Raised when the API returns an error."""
85
+
86
+ pass
@@ -1,179 +1,208 @@
1
- Metadata-Version: 2.4
2
- Name: indoxrouter
3
- Version: 0.1.25
4
- Summary: A unified client for various AI providers
5
- Author-email: indoxRouter Team <ashkan.eskandari.dev@gmail.com>
6
- License: MIT
7
- Project-URL: Homepage, https://github.com/indoxrouter/indoxrouter
8
- Project-URL: Repository, https://github.com/indoxrouter/indoxrouter
9
- Project-URL: Issues, https://github.com/indoxrouter/indoxrouter/issues
10
- Keywords: ai,api,client,openai,anthropic,google,mistral,xai,imagen,grok,image-generation,text-to-speech,tts,audio
11
- Classifier: Development Status :: 3 - Alpha
12
- Classifier: Intended Audience :: Developers
13
- Classifier: Programming Language :: Python :: 3
14
- Classifier: Programming Language :: Python :: 3.8
15
- Classifier: Programming Language :: Python :: 3.9
16
- Classifier: Programming Language :: Python :: 3.10
17
- Classifier: Programming Language :: Python :: 3.11
18
- Classifier: Programming Language :: Python :: 3.12
19
- Requires-Python: >=3.8
20
- Description-Content-Type: text/markdown
21
- License-File: LICENSE
22
- Requires-Dist: requests>=2.25.0
23
- Requires-Dist: python-dotenv>=1.0.0
24
- Dynamic: license-file
25
-
26
- # IndoxRouter
27
-
28
- A unified client for various AI providers, including OpenAI, anthropic, Google, and Mistral.
29
-
30
- ## Features
31
-
32
- - **Unified API**: Access multiple AI providers through a single API
33
- - **Simple Interface**: Easy-to-use methods for chat, completion, embeddings, image generation, and text-to-speech
34
- - **Error Handling**: Standardized error handling across providers
35
- - **Authentication**: Secure cookie-based authentication
36
-
37
- ## Installation
38
-
39
- ```bash
40
- pip install indoxrouter
41
- ```
42
-
43
- ## Usage
44
-
45
- ### Initialization
46
-
47
- ```python
48
- from indoxrouter import Client
49
-
50
- # Initialize with API key
51
- client = Client(api_key="your_api_key")
52
-
53
- # Using environment variables
54
- # Set INDOX_ROUTER_API_KEY environment variable
55
- import os
56
- os.environ["INDOX_ROUTER_API_KEY"] = "your_api_key"
57
- client = Client()
58
- ```
59
-
60
- ### Authentication
61
-
62
- IndoxRouter uses cookie-based authentication with JWT tokens. The client handles this automatically by:
63
-
64
- 1. Taking your API key and exchanging it for JWT tokens using the server's authentication endpoints
65
- 2. Storing the JWT tokens in cookies
66
- 3. Using the cookies for subsequent requests
67
- 4. Automatically refreshing tokens when they expire
68
-
69
- ```python
70
- # Authentication is handled automatically when creating the client
71
- client = Client(api_key="your_api_key")
72
- ```
73
-
74
- ### Chat Completions
75
-
76
- ```python
77
- response = client.chat(
78
- messages=[
79
- {"role": "system", "content": "You are a helpful assistant."},
80
- {"role": "user", "content": "Tell me a joke."}
81
- ],
82
- model="openai/gpt-4o-mini", # Provider/model format
83
- temperature=0.7
84
- )
85
-
86
- print(response["data"])
87
- ```
88
-
89
- ### Text Completions
90
-
91
- ```python
92
- response = client.completion(
93
- prompt="Once upon a time,",
94
- model="openai/gpt-4o-mini",
95
- max_tokens=100
96
- )
97
-
98
- print(response["data"])
99
- ```
100
-
101
- ### Embeddings
102
-
103
- ```python
104
- response = client.embeddings(
105
- text=["Hello world", "AI is amazing"],
106
- model="openai/text-embedding-3-small"
107
- )
108
-
109
- print(f"Dimensions: {len(response['data'][0]['embedding'])}")
110
- print(f"First embedding: {response['data'][0]['embedding'][:5]}...")
111
- ```
112
-
113
- ### Image Generation
114
-
115
- ```python
116
- # OpenAI Image Generation
117
- response = client.images(
118
- prompt="A serene landscape with mountains and a lake",
119
- model="openai/dall-e-3",
120
- size="1024x1024",
121
- quality="standard", # Options: standard, hd
122
- style="vivid" # Options: vivid, natural
123
- )
124
-
125
- print(f"Image URL: {response['data'][0]['url']}")
126
-
127
-
128
- # Access base64 encoded image data
129
- if "b64_json" in response["data"][0]:
130
- b64_data = response["data"][0]["b64_json"]
131
- # Use the base64 data (e.g., to display in HTML or save to file)
132
- ```
133
-
134
- ### Text-to-Speech
135
-
136
- ```python
137
- # Generate audio from text
138
- response = client.text_to_speech(
139
- input="Hello, welcome to IndoxRouter!",
140
- model="openai/tts-1",
141
- voice="alloy", # Options: alloy, echo, fable, onyx, nova, shimmer
142
- response_format="mp3", # Options: mp3, opus, aac, flac
143
- speed=1.0 # Range: 0.25 to 4.0
144
- )
145
-
146
- print(f"Audio generated successfully: {response['success']}")
147
- print(f"Audio data available: {'data' in response}")
148
- ```
149
-
150
- ### Streaming Responses
151
-
152
- ```python
153
- for chunk in client.chat(
154
- messages=[{"role": "user", "content": "Write a short story."}],
155
- model="openai/gpt-4o-mini",
156
- stream=True
157
- ):
158
- if chunk.choices[0].delta.content:
159
- print(chunk.choices[0].delta.content, end="", flush=True)
160
- ```
161
-
162
- ### Getting Available Models
163
-
164
- ```python
165
- # Get all providers and models
166
- providers = client.models()
167
- for provider in providers:
168
- print(f"Provider: {provider['name']}")
169
- for model in provider["models"]:
170
- print(f" - {model['id']}: {model['description'] or ''}")
171
-
172
- # Get models for a specific provider
173
- openai_provider = client.models("openai")
174
- print(f"OpenAI models: {[m['id'] for m in openai_provider['models']]}")
175
- ```
176
-
177
- ## License
178
-
179
- This project is licensed under the MIT License - see the LICENSE file for details.
1
+ Metadata-Version: 2.4
2
+ Name: indoxrouter
3
+ Version: 0.1.27
4
+ Summary: A unified client for various AI providers
5
+ Author-email: indoxRouter Team <ashkan.eskandari.dev@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/indoxrouter/indoxrouter
8
+ Project-URL: Repository, https://github.com/indoxrouter/indoxrouter
9
+ Project-URL: Issues, https://github.com/indoxrouter/indoxrouter/issues
10
+ Keywords: ai,api,client,openai,anthropic,google,mistral,xai,imagen,grok,image-generation,text-to-speech,tts,audio
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Requires-Python: >=3.8
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: requests>=2.25.0
23
+ Requires-Dist: python-dotenv>=1.0.0
24
+ Dynamic: license-file
25
+
26
+ # IndoxRouter
27
+
28
+ A unified client for various AI providers, including OpenAI, anthropic, Google, and Mistral.
29
+
30
+ ## Features
31
+
32
+ - **Unified API**: Access multiple AI providers through a single API
33
+ - **Simple Interface**: Easy-to-use methods for chat, completion, embeddings, image generation, and text-to-speech
34
+ - **Error Handling**: Standardized error handling across providers
35
+ - **Authentication**: Secure cookie-based authentication
36
+ - **BYOK Support**: Bring Your Own Key support for using your own provider API keys
37
+
38
+ ## Installation
39
+
40
+ ```bash
41
+ pip install indoxrouter
42
+ ```
43
+
44
+ ## Usage
45
+
46
+ ### Initialization
47
+
48
+ ```python
49
+ from indoxrouter import Client
50
+
51
+ # Initialize with API key
52
+ client = Client(api_key="your_api_key")
53
+
54
+ # Using environment variables
55
+ # Set INDOX_ROUTER_API_KEY environment variable
56
+ import os
57
+ os.environ["INDOX_ROUTER_API_KEY"] = "your_api_key"
58
+ client = Client()
59
+ ```
60
+
61
+ ### Authentication
62
+
63
+ IndoxRouter uses cookie-based authentication with JWT tokens. The client handles this automatically by:
64
+
65
+ 1. Taking your API key and exchanging it for JWT tokens using the server's authentication endpoints
66
+ 2. Storing the JWT tokens in cookies
67
+ 3. Using the cookies for subsequent requests
68
+ 4. Automatically refreshing tokens when they expire
69
+
70
+ ```python
71
+ # Authentication is handled automatically when creating the client
72
+ client = Client(api_key="your_api_key")
73
+ ```
74
+
75
+ ### Chat Completions
76
+
77
+ ```python
78
+ response = client.chat(
79
+ messages=[
80
+ {"role": "system", "content": "You are a helpful assistant."},
81
+ {"role": "user", "content": "Tell me a joke."}
82
+ ],
83
+ model="openai/gpt-4o-mini", # Provider/model format
84
+ temperature=0.7
85
+ )
86
+
87
+ print(response["data"])
88
+ ```
89
+
90
+ ### Text Completions
91
+
92
+ ```python
93
+ response = client.completion(
94
+ prompt="Once upon a time,",
95
+ model="openai/gpt-4o-mini",
96
+ max_tokens=100
97
+ )
98
+
99
+ print(response["data"])
100
+ ```
101
+
102
+ ### Embeddings
103
+
104
+ ```python
105
+ response = client.embeddings(
106
+ text=["Hello world", "AI is amazing"],
107
+ model="openai/text-embedding-3-small"
108
+ )
109
+
110
+ print(f"Dimensions: {len(response['data'][0]['embedding'])}")
111
+ print(f"First embedding: {response['data'][0]['embedding'][:5]}...")
112
+ ```
113
+
114
+ ### Image Generation
115
+
116
+ ```python
117
+ # OpenAI Image Generation
118
+ response = client.images(
119
+ prompt="A serene landscape with mountains and a lake",
120
+ model="openai/dall-e-3",
121
+ size="1024x1024",
122
+ quality="standard", # Options: standard, hd
123
+ style="vivid" # Options: vivid, natural
124
+ )
125
+
126
+ print(f"Image URL: {response['data'][0]['url']}")
127
+
128
+
129
+ # Access base64 encoded image data
130
+ if "b64_json" in response["data"][0]:
131
+ b64_data = response["data"][0]["b64_json"]
132
+ # Use the base64 data (e.g., to display in HTML or save to file)
133
+ ```
134
+
135
+ ### BYOK (Bring Your Own Key) Support
136
+
137
+ IndoxRouter supports BYOK, allowing you to use your own API keys for AI providers:
138
+
139
+ ```python
140
+ # Use your own OpenAI API key
141
+ response = client.chat(
142
+ messages=[{"role": "user", "content": "Hello!"}],
143
+ model="openai/gpt-4",
144
+ byok_api_key="sk-your-openai-key-here"
145
+ )
146
+
147
+ # Use your own Google API key for image generation
148
+ response = client.images(
149
+ prompt="A beautiful sunset",
150
+ model="google/imagen-3.0-generate-002",
151
+ aspect_ratio="16:9",
152
+ byok_api_key="your-google-api-key-here"
153
+ )
154
+ ```
155
+
156
+ **BYOK Benefits:**
157
+
158
+ - No credit deduction from your IndoxRouter account
159
+ - No platform rate limiting
160
+ - Direct provider access with your own API keys
161
+ - Cost control - pay providers directly at their rates
162
+
163
+ ### Text-to-Speech
164
+
165
+ ```python
166
+ # Generate audio from text
167
+ response = client.text_to_speech(
168
+ input="Hello, welcome to IndoxRouter!",
169
+ model="openai/tts-1",
170
+ voice="alloy", # Options: alloy, echo, fable, onyx, nova, shimmer
171
+ response_format="mp3", # Options: mp3, opus, aac, flac
172
+ speed=1.0 # Range: 0.25 to 4.0
173
+ )
174
+
175
+ print(f"Audio generated successfully: {response['success']}")
176
+ print(f"Audio data available: {'data' in response}")
177
+ ```
178
+
179
+ ### Streaming Responses
180
+
181
+ ```python
182
+ for chunk in client.chat(
183
+ messages=[{"role": "user", "content": "Write a short story."}],
184
+ model="openai/gpt-4o-mini",
185
+ stream=True
186
+ ):
187
+ if chunk.choices[0].delta.content:
188
+ print(chunk.choices[0].delta.content, end="", flush=True)
189
+ ```
190
+
191
+ ### Getting Available Models
192
+
193
+ ```python
194
+ # Get all providers and models
195
+ providers = client.models()
196
+ for provider in providers:
197
+ print(f"Provider: {provider['name']}")
198
+ for model in provider["models"]:
199
+ print(f" - {model['id']}: {model['description'] or ''}")
200
+
201
+ # Get models for a specific provider
202
+ openai_provider = client.models("openai")
203
+ print(f"OpenAI models: {[m['id'] for m in openai_provider['models']]}")
204
+ ```
205
+
206
+ ## License
207
+
208
+ This project is licensed under the MIT License - see the LICENSE file for details.
@@ -0,0 +1,9 @@
1
+ indoxrouter/__init__.py,sha256=P_2eiiAi-DrkkeeJndQdEMqnVheWzOZIjWkDayrwxuk,1561
2
+ indoxrouter/client.py,sha256=AirPauY2kFqpR46LWOtDBKs--_9ilFTc2RQHb7vsLnM,45694
3
+ indoxrouter/constants.py,sha256=HqTXfNpL_UvWsR5mod8YZgWOs1W6x6itr1BSbmyYEHY,1451
4
+ indoxrouter/exceptions.py,sha256=cGlXNF8dd4X8UBWgxTA099nRhEkIjcqE_4iGOlIVVp8,1632
5
+ indoxrouter-0.1.27.dist-info/licenses/LICENSE,sha256=5n28CfoynFakg-QJIHnecEXcveN8gq-ZwhC0h7ATse0,24232
6
+ indoxrouter-0.1.27.dist-info/METADATA,sha256=5bZ0cAhmLFMuRP8h_5uNOEPwu39xjIqUaT_6CEjyi_k,5740
7
+ indoxrouter-0.1.27.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
+ indoxrouter-0.1.27.dist-info/top_level.txt,sha256=v6FGWkw0QAnXhyYtnXLI1cxzna0iveNvZUotVzCWabM,12
9
+ indoxrouter-0.1.27.dist-info/RECORD,,