indoxrouter 0.1.9__tar.gz → 0.1.11__tar.gz
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-0.1.9/indoxrouter.egg-info → indoxrouter-0.1.11}/PKG-INFO +22 -3
- {indoxrouter-0.1.9 → indoxrouter-0.1.11}/README.md +21 -2
- {indoxrouter-0.1.9 → indoxrouter-0.1.11}/cookbook/indoxRouter_cookbook.ipynb +1 -1
- {indoxrouter-0.1.9 → indoxrouter-0.1.11}/indoxrouter/client.py +75 -18
- {indoxrouter-0.1.9 → indoxrouter-0.1.11}/indoxrouter/constants.py +1 -3
- indoxrouter-0.1.11/indoxrouter/test_api_key.py +98 -0
- {indoxrouter-0.1.9 → indoxrouter-0.1.11/indoxrouter.egg-info}/PKG-INFO +22 -3
- {indoxrouter-0.1.9 → indoxrouter-0.1.11}/indoxrouter.egg-info/SOURCES.txt +1 -0
- {indoxrouter-0.1.9 → indoxrouter-0.1.11}/setup.py +1 -1
- {indoxrouter-0.1.9 → indoxrouter-0.1.11}/MANIFEST.in +0 -0
- {indoxrouter-0.1.9 → indoxrouter-0.1.11}/cookbook/README.md +0 -0
- {indoxrouter-0.1.9 → indoxrouter-0.1.11}/indoxrouter/__init__.py +0 -0
- {indoxrouter-0.1.9 → indoxrouter-0.1.11}/indoxrouter/exceptions.py +0 -0
- {indoxrouter-0.1.9 → indoxrouter-0.1.11}/indoxrouter.egg-info/dependency_links.txt +0 -0
- {indoxrouter-0.1.9 → indoxrouter-0.1.11}/indoxrouter.egg-info/requires.txt +0 -0
- {indoxrouter-0.1.9 → indoxrouter-0.1.11}/indoxrouter.egg-info/top_level.txt +0 -0
- {indoxrouter-0.1.9 → indoxrouter-0.1.11}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: indoxrouter
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.11
|
4
4
|
Summary: A unified client for various AI providers
|
5
5
|
Home-page: https://github.com/indoxrouter/indoxrouter
|
6
6
|
Author: indoxRouter Team
|
@@ -78,14 +78,33 @@ client = Client(
|
|
78
78
|
|
79
79
|
### Authentication
|
80
80
|
|
81
|
-
IndoxRouter uses cookie-based authentication
|
81
|
+
IndoxRouter uses cookie-based authentication with JWT tokens. The client handles this automatically by:
|
82
|
+
|
83
|
+
1. Taking your API key and exchanging it for JWT tokens using the server's authentication endpoints
|
84
|
+
2. Storing the JWT tokens in cookies
|
85
|
+
3. Using the cookies for subsequent requests
|
86
|
+
4. Automatically refreshing tokens when they expire
|
82
87
|
|
83
88
|
```python
|
84
89
|
# Authentication is handled automatically when creating the client
|
85
90
|
client = Client(api_key="your_api_key")
|
86
91
|
```
|
87
92
|
|
88
|
-
|
93
|
+
### Testing Your API Key
|
94
|
+
|
95
|
+
The package includes a test script to verify your API key and connection:
|
96
|
+
|
97
|
+
```bash
|
98
|
+
# Run the test script with your API key
|
99
|
+
python -m indoxrouter.test_api_key --api-key YOUR_API_KEY
|
100
|
+
|
101
|
+
# Or set the environment variable and run
|
102
|
+
export INDOX_ROUTER_API_KEY=YOUR_API_KEY
|
103
|
+
python -m indoxrouter.test_api_key
|
104
|
+
|
105
|
+
# To see detailed debugging information
|
106
|
+
python -m indoxrouter.test_api_key --debug
|
107
|
+
```
|
89
108
|
|
90
109
|
### Chat Completions
|
91
110
|
|
@@ -40,14 +40,33 @@ client = Client(
|
|
40
40
|
|
41
41
|
### Authentication
|
42
42
|
|
43
|
-
IndoxRouter uses cookie-based authentication
|
43
|
+
IndoxRouter uses cookie-based authentication with JWT tokens. The client handles this automatically by:
|
44
|
+
|
45
|
+
1. Taking your API key and exchanging it for JWT tokens using the server's authentication endpoints
|
46
|
+
2. Storing the JWT tokens in cookies
|
47
|
+
3. Using the cookies for subsequent requests
|
48
|
+
4. Automatically refreshing tokens when they expire
|
44
49
|
|
45
50
|
```python
|
46
51
|
# Authentication is handled automatically when creating the client
|
47
52
|
client = Client(api_key="your_api_key")
|
48
53
|
```
|
49
54
|
|
50
|
-
|
55
|
+
### Testing Your API Key
|
56
|
+
|
57
|
+
The package includes a test script to verify your API key and connection:
|
58
|
+
|
59
|
+
```bash
|
60
|
+
# Run the test script with your API key
|
61
|
+
python -m indoxrouter.test_api_key --api-key YOUR_API_KEY
|
62
|
+
|
63
|
+
# Or set the environment variable and run
|
64
|
+
export INDOX_ROUTER_API_KEY=YOUR_API_KEY
|
65
|
+
python -m indoxrouter.test_api_key
|
66
|
+
|
67
|
+
# To see detailed debugging information
|
68
|
+
python -m indoxrouter.test_api_key --debug
|
69
|
+
```
|
51
70
|
|
52
71
|
### Chat Completions
|
53
72
|
|
@@ -6,8 +6,7 @@ interface to multiple AI providers and models. The client handles authentication
|
|
6
6
|
error handling, and provides a standardized response format across different AI services.
|
7
7
|
|
8
8
|
IMPORTANT: The IndoxRouter server now supports only cookie-based authentication. This client
|
9
|
-
|
10
|
-
backward compatibility but should always be set to True for newer server versions.
|
9
|
+
automatically handles authentication by exchanging your API key for a JWT token through the login endpoint.
|
11
10
|
|
12
11
|
The Client class offers methods for:
|
13
12
|
- Authentication and session management
|
@@ -97,7 +96,6 @@ class Client:
|
|
97
96
|
Args:
|
98
97
|
api_key: API key for authentication. If not provided, the client will look for the
|
99
98
|
INDOX_ROUTER_API_KEY environment variable.
|
100
|
-
base_url: Custom base URL for the API. If not provided, the default base URL will be used.
|
101
99
|
timeout: Request timeout in seconds.
|
102
100
|
"""
|
103
101
|
|
@@ -113,23 +111,64 @@ class Client:
|
|
113
111
|
self.use_cookies = use_cookies
|
114
112
|
self.session = requests.Session()
|
115
113
|
|
116
|
-
#
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
114
|
+
# Authenticate and get JWT tokens
|
115
|
+
self._authenticate()
|
116
|
+
|
117
|
+
def _authenticate(self):
|
118
|
+
"""
|
119
|
+
Authenticate with the server and get JWT tokens.
|
120
|
+
This uses the /auth/token endpoint to get JWT tokens using the API key.
|
121
|
+
"""
|
122
|
+
try:
|
123
|
+
# First try using the API key as a username with empty password (API key flow)
|
124
|
+
logger.debug("Authenticating with API key as username")
|
125
|
+
response = self.session.post(
|
126
|
+
f"{self.base_url}/api/v1/auth/token",
|
127
|
+
data={
|
128
|
+
"username": self.api_key,
|
129
|
+
"password": "",
|
130
|
+
},
|
131
|
+
timeout=self.timeout,
|
131
132
|
)
|
132
133
|
|
134
|
+
if response.status_code != 200:
|
135
|
+
# Try using email:api_key format if the first method fails
|
136
|
+
logger.debug(
|
137
|
+
"First auth method failed, trying with API key as password"
|
138
|
+
)
|
139
|
+
response = self.session.post(
|
140
|
+
f"{self.base_url}/api/v1/auth/login",
|
141
|
+
json={
|
142
|
+
"username": "pip_client",
|
143
|
+
"password": self.api_key,
|
144
|
+
},
|
145
|
+
timeout=self.timeout,
|
146
|
+
)
|
147
|
+
|
148
|
+
if response.status_code != 200:
|
149
|
+
error_data = {}
|
150
|
+
try:
|
151
|
+
error_data = response.json()
|
152
|
+
except:
|
153
|
+
error_data = {"detail": response.text}
|
154
|
+
|
155
|
+
raise AuthenticationError(
|
156
|
+
f"Authentication failed: {error_data.get('detail', 'Unknown error')}"
|
157
|
+
)
|
158
|
+
|
159
|
+
# At this point, the cookies should be set in the session
|
160
|
+
logger.debug("Authentication successful")
|
161
|
+
|
162
|
+
# Check if we have the cookies we need
|
163
|
+
if "access_token" not in self.session.cookies:
|
164
|
+
logger.warning(
|
165
|
+
"Authentication succeeded but no access_token cookie was set"
|
166
|
+
)
|
167
|
+
|
168
|
+
except requests.RequestException as e:
|
169
|
+
logger.error(f"Authentication request failed: {str(e)}")
|
170
|
+
raise NetworkError(f"Network error during authentication: {str(e)}")
|
171
|
+
|
133
172
|
def _get_domain(self):
|
134
173
|
"""
|
135
174
|
Extract domain from the base URL for cookie setting.
|
@@ -213,6 +252,24 @@ class Client:
|
|
213
252
|
if stream:
|
214
253
|
return response
|
215
254
|
|
255
|
+
# Check if we need to reauthenticate (401 Unauthorized)
|
256
|
+
if response.status_code == 401:
|
257
|
+
logger.debug("Received 401, attempting to reauthenticate")
|
258
|
+
self._authenticate()
|
259
|
+
|
260
|
+
# Retry the request after reauthentication
|
261
|
+
response = self.session.request(
|
262
|
+
method,
|
263
|
+
url,
|
264
|
+
headers=headers,
|
265
|
+
json=data,
|
266
|
+
timeout=self.timeout,
|
267
|
+
stream=stream,
|
268
|
+
)
|
269
|
+
|
270
|
+
if stream:
|
271
|
+
return response
|
272
|
+
|
216
273
|
response.raise_for_status()
|
217
274
|
return response.json()
|
218
275
|
except requests.HTTPError as e:
|
@@ -7,6 +7,7 @@ DEFAULT_API_VERSION = "v1"
|
|
7
7
|
DEFAULT_BASE_URL = "https://api.indox.org" # Production server URL with HTTPS
|
8
8
|
# DEFAULT_BASE_URL = "http://localhost:8000" # Local development server
|
9
9
|
DEFAULT_TIMEOUT = 60
|
10
|
+
USE_COOKIES = True # Always use cookie-based authentication
|
10
11
|
|
11
12
|
# Default models
|
12
13
|
DEFAULT_MODEL = "openai/gpt-4o-mini"
|
@@ -29,6 +30,3 @@ ERROR_PROVIDER_NOT_FOUND = "Provider not found"
|
|
29
30
|
ERROR_MODEL_NOT_FOUND = "Model not found"
|
30
31
|
ERROR_INVALID_PARAMETERS = "Invalid parameters provided"
|
31
32
|
ERROR_INSUFFICIENT_CREDITS = "Insufficient credits"
|
32
|
-
|
33
|
-
|
34
|
-
USE_COOKIES = True
|
@@ -0,0 +1,98 @@
|
|
1
|
+
#!/usr/bin/env python
|
2
|
+
"""
|
3
|
+
Test script for the IndoxRouter client.
|
4
|
+
This script tests authentication and basic functionality of the client.
|
5
|
+
"""
|
6
|
+
|
7
|
+
import os
|
8
|
+
import sys
|
9
|
+
import logging
|
10
|
+
from indoxrouter import Client, AuthenticationError, NetworkError
|
11
|
+
|
12
|
+
# Set up logging
|
13
|
+
logging.basicConfig(
|
14
|
+
level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
15
|
+
)
|
16
|
+
logger = logging.getLogger("indoxrouter_test")
|
17
|
+
|
18
|
+
|
19
|
+
def test_client(api_key=None, debug=False):
|
20
|
+
"""
|
21
|
+
Test the IndoxRouter client with the provided API key.
|
22
|
+
|
23
|
+
Args:
|
24
|
+
api_key: API key to use for authentication
|
25
|
+
debug: Whether to enable debug logging
|
26
|
+
"""
|
27
|
+
if debug:
|
28
|
+
logging.getLogger("indoxrouter").setLevel(logging.DEBUG)
|
29
|
+
|
30
|
+
logger.info("Testing IndoxRouter client...")
|
31
|
+
|
32
|
+
# If no API key is provided, try to get it from environment variable
|
33
|
+
if not api_key:
|
34
|
+
api_key = os.environ.get("INDOX_ROUTER_API_KEY")
|
35
|
+
if not api_key:
|
36
|
+
logger.error(
|
37
|
+
"No API key provided. Please provide an API key as an argument or set the INDOX_ROUTER_API_KEY environment variable."
|
38
|
+
)
|
39
|
+
sys.exit(1)
|
40
|
+
|
41
|
+
try:
|
42
|
+
# Initialize client
|
43
|
+
logger.info("Initializing client...")
|
44
|
+
client = Client(api_key=api_key)
|
45
|
+
|
46
|
+
# Test connection
|
47
|
+
logger.info("Testing connection...")
|
48
|
+
connection_info = client.test_connection()
|
49
|
+
logger.info(f"Connection test: {connection_info['status']}")
|
50
|
+
|
51
|
+
# Try to get available models
|
52
|
+
logger.info("Fetching available models...")
|
53
|
+
models = client.models()
|
54
|
+
|
55
|
+
# Display some models
|
56
|
+
providers = [p.get("name") for p in models]
|
57
|
+
logger.info(f"Available providers: {', '.join(providers)}")
|
58
|
+
|
59
|
+
# Try a simple chat completion
|
60
|
+
logger.info("Testing chat completion...")
|
61
|
+
response = client.chat(
|
62
|
+
messages=[{"role": "user", "content": "Hello, who are you?"}],
|
63
|
+
model="openai/gpt-3.5-turbo",
|
64
|
+
max_tokens=30,
|
65
|
+
)
|
66
|
+
|
67
|
+
logger.info("Chat completion successful!")
|
68
|
+
logger.info(f"Response: {response['choices'][0]['message']['content']}")
|
69
|
+
|
70
|
+
logger.info("All tests passed! The client is working correctly.")
|
71
|
+
|
72
|
+
except AuthenticationError as e:
|
73
|
+
logger.error(f"Authentication error: {e}")
|
74
|
+
logger.error("Please check that your API key is correct.")
|
75
|
+
sys.exit(1)
|
76
|
+
except NetworkError as e:
|
77
|
+
logger.error(f"Network error: {e}")
|
78
|
+
logger.error(
|
79
|
+
"Please check your internet connection and that the IndoxRouter server is accessible."
|
80
|
+
)
|
81
|
+
sys.exit(1)
|
82
|
+
except Exception as e:
|
83
|
+
logger.error(f"Unexpected error: {e}")
|
84
|
+
sys.exit(1)
|
85
|
+
|
86
|
+
|
87
|
+
if __name__ == "__main__":
|
88
|
+
import argparse
|
89
|
+
|
90
|
+
parser = argparse.ArgumentParser(description="Test the IndoxRouter client")
|
91
|
+
parser.add_argument("--api-key", "-k", help="API key to use for authentication")
|
92
|
+
parser.add_argument(
|
93
|
+
"--debug", "-d", action="store_true", help="Enable debug logging"
|
94
|
+
)
|
95
|
+
|
96
|
+
args = parser.parse_args()
|
97
|
+
|
98
|
+
test_client(api_key=args.api_key, debug=args.debug)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: indoxrouter
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.11
|
4
4
|
Summary: A unified client for various AI providers
|
5
5
|
Home-page: https://github.com/indoxrouter/indoxrouter
|
6
6
|
Author: indoxRouter Team
|
@@ -78,14 +78,33 @@ client = Client(
|
|
78
78
|
|
79
79
|
### Authentication
|
80
80
|
|
81
|
-
IndoxRouter uses cookie-based authentication
|
81
|
+
IndoxRouter uses cookie-based authentication with JWT tokens. The client handles this automatically by:
|
82
|
+
|
83
|
+
1. Taking your API key and exchanging it for JWT tokens using the server's authentication endpoints
|
84
|
+
2. Storing the JWT tokens in cookies
|
85
|
+
3. Using the cookies for subsequent requests
|
86
|
+
4. Automatically refreshing tokens when they expire
|
82
87
|
|
83
88
|
```python
|
84
89
|
# Authentication is handled automatically when creating the client
|
85
90
|
client = Client(api_key="your_api_key")
|
86
91
|
```
|
87
92
|
|
88
|
-
|
93
|
+
### Testing Your API Key
|
94
|
+
|
95
|
+
The package includes a test script to verify your API key and connection:
|
96
|
+
|
97
|
+
```bash
|
98
|
+
# Run the test script with your API key
|
99
|
+
python -m indoxrouter.test_api_key --api-key YOUR_API_KEY
|
100
|
+
|
101
|
+
# Or set the environment variable and run
|
102
|
+
export INDOX_ROUTER_API_KEY=YOUR_API_KEY
|
103
|
+
python -m indoxrouter.test_api_key
|
104
|
+
|
105
|
+
# To see detailed debugging information
|
106
|
+
python -m indoxrouter.test_api_key --debug
|
107
|
+
```
|
89
108
|
|
90
109
|
### Chat Completions
|
91
110
|
|
@@ -9,7 +9,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
|
|
9
9
|
|
10
10
|
setup(
|
11
11
|
name="indoxrouter",
|
12
|
-
version="0.1.
|
12
|
+
version="0.1.11",
|
13
13
|
author="indoxRouter Team",
|
14
14
|
author_email="ashkan.eskandari.dev@gmail.com",
|
15
15
|
description="A unified client for various AI providers",
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|