indoxrouter 0.1.23__py3-none-any.whl → 0.1.26__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
@@ -13,6 +13,7 @@ USE_COOKIES = True # Always use cookie-based authentication
13
13
  DEFAULT_MODEL = "openai/gpt-4o-mini"
14
14
  DEFAULT_EMBEDDING_MODEL = "openai/text-embedding-3-small"
15
15
  DEFAULT_IMAGE_MODEL = "openai/dall-e-3"
16
+ DEFAULT_TTS_MODEL = "openai/tts-1"
16
17
  GOOGLE_IMAGE_MODEL = "google/imagen-3.0-generate-002"
17
18
  XAI_IMAGE_MODEL = "xai/grok-2-image"
18
19
  XAI_IMAGE_LATEST_MODEL = "xai/grok-2-image-latest"
@@ -23,6 +24,7 @@ CHAT_ENDPOINT = "chat/completions"
23
24
  COMPLETION_ENDPOINT = "completions"
24
25
  EMBEDDING_ENDPOINT = "embeddings"
25
26
  IMAGE_ENDPOINT = "images/generations"
27
+ TTS_ENDPOINT = "tts/generations"
26
28
  MODEL_ENDPOINT = "models"
27
29
  USAGE_ENDPOINT = "user/usage"
28
30
 
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,234 +1,179 @@
1
- Metadata-Version: 2.4
2
- Name: indoxrouter
3
- Version: 0.1.23
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
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
- Requires-Dist: requests>=2.25.0
22
- Requires-Dist: python-dotenv>=1.0.0
23
-
24
- # IndoxRouter Client
25
-
26
- A unified client for various AI providers, including OpenAI, anthropic, Google, and Mistral.
27
-
28
- ## Features
29
-
30
- - **Unified API**: Access multiple AI providers through a single API
31
- - **Simple Interface**: Easy-to-use methods for chat, completion, embeddings, and image generation
32
- - **Error Handling**: Standardized error handling across providers
33
- - **Authentication**: Secure cookie-based authentication
34
-
35
- ## Installation
36
-
37
- ```bash
38
- pip install indoxrouter
39
- ```
40
-
41
- ## Usage
42
-
43
- ### Initialization
44
-
45
- ```python
46
- from indoxrouter import Client
47
-
48
- # Initialize with API key
49
- client = Client(api_key="your_api_key")
50
-
51
- # Using environment variables
52
- # Set INDOX_ROUTER_API_KEY environment variable
53
- import os
54
- os.environ["INDOX_ROUTER_API_KEY"] = "your_api_key"
55
- client = Client()
56
-
57
- # Connect to a custom server
58
- client = Client(
59
- api_key="your_api_key",
60
- base_url="https://your-indoxrouter-server.com"
61
- )
62
- ```
63
-
64
- ### Authentication
65
-
66
- IndoxRouter uses cookie-based authentication with JWT tokens. The client handles this automatically by:
67
-
68
- 1. Taking your API key and exchanging it for JWT tokens using the server's authentication endpoints
69
- 2. Storing the JWT tokens in cookies
70
- 3. Using the cookies for subsequent requests
71
- 4. Automatically refreshing tokens when they expire
72
-
73
- ```python
74
- # Authentication is handled automatically when creating the client
75
- client = Client(api_key="your_api_key")
76
- ```
77
-
78
- ### Testing Your API Key
79
-
80
- The package includes a test script to verify your API key and connection:
81
-
82
- ```bash
83
- # Run the test script with your API key
84
- python -m indoxrouter.test_api_key --api-key YOUR_API_KEY
85
-
86
- # Or set the environment variable and run
87
- export INDOX_ROUTER_API_KEY=YOUR_API_KEY
88
- python -m indoxrouter.test_api_key
89
-
90
- # To see detailed debugging information
91
- python -m indoxrouter.test_api_key --debug
92
- ```
93
-
94
- ### Chat Completions
95
-
96
- ```python
97
- response = client.chat(
98
- messages=[
99
- {"role": "system", "content": "You are a helpful assistant."},
100
- {"role": "user", "content": "Tell me a joke."}
101
- ],
102
- model="openai/gpt-4o-mini", # Provider/model format
103
- temperature=0.7
104
- )
105
-
106
- print(response["choices"][0]["message"]["content"])
107
- ```
108
-
109
- ### Text Completions
110
-
111
- ```python
112
- response = client.completion(
113
- prompt="Once upon a time,",
114
- model="openai/gpt-4o-mini",
115
- max_tokens=100
116
- )
117
-
118
- print(response["choices"][0]["text"])
119
- ```
120
-
121
- ### Embeddings
122
-
123
- ```python
124
- response = client.embeddings(
125
- text=["Hello world", "AI is amazing"],
126
- model="openai/text-embedding-3-small"
127
- )
128
-
129
- print(f"Dimensions: {len(response['data'][0]['embedding'])}")
130
- print(f"First embedding: {response['data'][0]['embedding'][:5]}...")
131
- ```
132
-
133
- ### Image Generation
134
-
135
- ```python
136
- # OpenAI Image Generation
137
- response = client.images(
138
- prompt="A serene landscape with mountains and a lake",
139
- model="openai/dall-e-3",
140
- size="1024x1024",
141
- quality="standard", # Options: standard, hd
142
- style="vivid" # Options: vivid, natural
143
- )
144
-
145
- print(f"Image URL: {response['data'][0]['url']}")
146
-
147
- # Google Imagen Image Generation
148
- from indoxrouter.constants import GOOGLE_IMAGE_MODEL
149
-
150
- response = client.images(
151
- prompt="A robot holding a red skateboard in a futuristic city",
152
- model=GOOGLE_IMAGE_MODEL,
153
- n=2, # Generate 2 images
154
- negative_prompt="broken, damaged, low quality",
155
- guidance_scale=7.5, # Control adherence to prompt
156
- seed=42, # For reproducible results
157
- )
158
-
159
- # xAI Grok Image Generation
160
- from indoxrouter.constants import XAI_IMAGE_MODEL
161
-
162
- response = client.images(
163
- prompt="A cat in a tree",
164
- model=XAI_IMAGE_MODEL,
165
- n=1,
166
- response_format="b64_json" # Get base64 encoded image
167
- )
168
-
169
- # Access base64 encoded image data
170
- if "b64_json" in response["data"][0]:
171
- b64_data = response["data"][0]["b64_json"]
172
- # Use the base64 data (e.g., to display in HTML or save to file)
173
- ```
174
-
175
- ### Streaming Responses
176
-
177
- ```python
178
- for chunk in client.chat(
179
- messages=[{"role": "user", "content": "Write a short story."}],
180
- model="openai/gpt-4o-mini",
181
- stream=True
182
- ):
183
- if chunk.get("choices") and len(chunk["choices"]) > 0:
184
- content = chunk["choices"][0].get("delta", {}).get("content", "")
185
- print(content, end="", flush=True)
186
- ```
187
-
188
- ### Getting Available Models
189
-
190
- ```python
191
- # Get all providers and models
192
- providers = client.models()
193
- for provider in providers:
194
- print(f"Provider: {provider['name']}")
195
- for model in provider["models"]:
196
- print(f" - {model['id']}: {model['description'] or ''}")
197
-
198
- # Get models for a specific provider
199
- openai_provider = client.models("openai")
200
- print(f"OpenAI models: {[m['id'] for m in openai_provider['models']]}")
201
- ```
202
-
203
- ## Error Handling
204
-
205
- ```python
206
- from indoxrouter import Client, ModelNotFoundError, ProviderError
207
-
208
- try:
209
- client = Client(api_key="your_api_key")
210
- response = client.chat(
211
- messages=[{"role": "user", "content": "Hello"}],
212
- model="nonexistent-provider/nonexistent-model"
213
- )
214
- except ModelNotFoundError as e:
215
- print(f"Model not found: {e}")
216
- except ProviderError as e:
217
- print(f"Provider error: {e}")
218
- ```
219
-
220
- ## Context Manager
221
-
222
- ```python
223
- with Client(api_key="your_api_key") as client:
224
- response = client.chat(
225
- messages=[{"role": "user", "content": "Hello!"}],
226
- model="openai/gpt-4o-mini"
227
- )
228
- print(response["choices"][0]["message"]["content"])
229
- # Client is automatically closed when exiting the block
230
- ```
231
-
232
- ## License
233
-
234
- 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.26
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.
@@ -0,0 +1,9 @@
1
+ indoxrouter/__init__.py,sha256=NhFlmJxbxcM3XCF21YZv9QsOk-k50rsqzw5Bk3mmr6E,1561
2
+ indoxrouter/client.py,sha256=KQpOFaTntNYmPgYjBJHq0z921vgKlyeUcaTYgZX7axM,43764
3
+ indoxrouter/constants.py,sha256=HqTXfNpL_UvWsR5mod8YZgWOs1W6x6itr1BSbmyYEHY,1451
4
+ indoxrouter/exceptions.py,sha256=cGlXNF8dd4X8UBWgxTA099nRhEkIjcqE_4iGOlIVVp8,1632
5
+ indoxrouter-0.1.26.dist-info/licenses/LICENSE,sha256=5n28CfoynFakg-QJIHnecEXcveN8gq-ZwhC0h7ATse0,24232
6
+ indoxrouter-0.1.26.dist-info/METADATA,sha256=nzfcnbrzEJznKEPA1gAG34-C5KjemPqUavXO2e8-3fs,4909
7
+ indoxrouter-0.1.26.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
+ indoxrouter-0.1.26.dist-info/top_level.txt,sha256=v6FGWkw0QAnXhyYtnXLI1cxzna0iveNvZUotVzCWabM,12
9
+ indoxrouter-0.1.26.dist-info/RECORD,,