indoxrouter 0.1.7__py3-none-any.whl → 0.1.9__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/client.py +39 -3
- indoxrouter/constants.py +4 -1
- {indoxrouter-0.1.7.dist-info → indoxrouter-0.1.9.dist-info}/METADATA +20 -3
- indoxrouter-0.1.9.dist-info/RECORD +8 -0
- indoxrouter-0.1.7.dist-info/RECORD +0 -8
- {indoxrouter-0.1.7.dist-info → indoxrouter-0.1.9.dist-info}/WHEEL +0 -0
- {indoxrouter-0.1.7.dist-info → indoxrouter-0.1.9.dist-info}/top_level.txt +0 -0
indoxrouter/client.py
CHANGED
@@ -5,6 +5,10 @@ This module provides a client for interacting with the IndoxRouter API, which se
|
|
5
5
|
interface to multiple AI providers and models. The client handles authentication, rate limiting,
|
6
6
|
error handling, and provides a standardized response format across different AI services.
|
7
7
|
|
8
|
+
IMPORTANT: The IndoxRouter server now supports only cookie-based authentication. This client
|
9
|
+
will use cookie-based authentication by default. The 'use_cookies' parameter is kept for
|
10
|
+
backward compatibility but should always be set to True for newer server versions.
|
11
|
+
|
8
12
|
The Client class offers methods for:
|
9
13
|
- Authentication and session management
|
10
14
|
- Making API requests with automatic token refresh
|
@@ -71,6 +75,7 @@ from .constants import (
|
|
71
75
|
IMAGE_ENDPOINT,
|
72
76
|
MODEL_ENDPOINT,
|
73
77
|
USAGE_ENDPOINT,
|
78
|
+
USE_COOKIES,
|
74
79
|
)
|
75
80
|
|
76
81
|
logger = logging.getLogger(__name__)
|
@@ -84,7 +89,6 @@ class Client:
|
|
84
89
|
def __init__(
|
85
90
|
self,
|
86
91
|
api_key: Optional[str] = None,
|
87
|
-
base_url: Optional[str] = None,
|
88
92
|
timeout: int = DEFAULT_TIMEOUT,
|
89
93
|
):
|
90
94
|
"""
|
@@ -96,16 +100,48 @@ class Client:
|
|
96
100
|
base_url: Custom base URL for the API. If not provided, the default base URL will be used.
|
97
101
|
timeout: Request timeout in seconds.
|
98
102
|
"""
|
103
|
+
|
104
|
+
use_cookies = USE_COOKIES
|
99
105
|
self.api_key = api_key or os.environ.get("INDOX_ROUTER_API_KEY")
|
100
106
|
if not self.api_key:
|
101
107
|
raise ValueError(
|
102
108
|
"API key must be provided either as an argument or as the INDOX_ROUTER_API_KEY environment variable."
|
103
109
|
)
|
104
110
|
|
105
|
-
self.base_url =
|
111
|
+
self.base_url = DEFAULT_BASE_URL
|
106
112
|
self.timeout = timeout
|
113
|
+
self.use_cookies = use_cookies
|
107
114
|
self.session = requests.Session()
|
108
|
-
|
115
|
+
|
116
|
+
# Set up authentication method based on preference
|
117
|
+
if use_cookies:
|
118
|
+
# Set cookie for authentication - using access_token as that's what the server expects
|
119
|
+
self.session.cookies.set(
|
120
|
+
"access_token", self.api_key, domain=self._get_domain(), path="/"
|
121
|
+
)
|
122
|
+
else:
|
123
|
+
# Warning: Authorization header is no longer supported by the server
|
124
|
+
logger.warning(
|
125
|
+
"WARNING: The IndoxRouter server no longer supports Authorization header authentication. "
|
126
|
+
"Using cookie-based authentication instead."
|
127
|
+
)
|
128
|
+
# Still set the cookie despite the use_cookies=False setting
|
129
|
+
self.session.cookies.set(
|
130
|
+
"access_token", self.api_key, domain=self._get_domain(), path="/"
|
131
|
+
)
|
132
|
+
|
133
|
+
def _get_domain(self):
|
134
|
+
"""
|
135
|
+
Extract domain from the base URL for cookie setting.
|
136
|
+
"""
|
137
|
+
try:
|
138
|
+
from urllib.parse import urlparse
|
139
|
+
|
140
|
+
parsed_url = urlparse(self.base_url)
|
141
|
+
return parsed_url.netloc
|
142
|
+
except Exception:
|
143
|
+
# If parsing fails, return a default value
|
144
|
+
return ""
|
109
145
|
|
110
146
|
def enable_debug(self, level=logging.DEBUG):
|
111
147
|
"""
|
indoxrouter/constants.py
CHANGED
@@ -4,7 +4,7 @@ Constants for the IndoxRouter client.
|
|
4
4
|
|
5
5
|
# API settings
|
6
6
|
DEFAULT_API_VERSION = "v1"
|
7
|
-
DEFAULT_BASE_URL = "https://
|
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
10
|
|
@@ -29,3 +29,6 @@ ERROR_PROVIDER_NOT_FOUND = "Provider not found"
|
|
29
29
|
ERROR_MODEL_NOT_FOUND = "Model not found"
|
30
30
|
ERROR_INVALID_PARAMETERS = "Invalid parameters provided"
|
31
31
|
ERROR_INSUFFICIENT_CREDITS = "Insufficient credits"
|
32
|
+
|
33
|
+
|
34
|
+
USE_COOKIES = True
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: indoxrouter
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.9
|
4
4
|
Summary: A unified client for various AI providers
|
5
5
|
Home-page: https://github.com/indoxrouter/indoxrouter
|
6
6
|
Author: indoxRouter Team
|
@@ -45,7 +45,7 @@ A unified client for various AI providers, including OpenAI, Anthropic, Google,
|
|
45
45
|
- **Unified API**: Access multiple AI providers through a single API
|
46
46
|
- **Simple Interface**: Easy-to-use methods for chat, completion, embeddings, and image generation
|
47
47
|
- **Error Handling**: Standardized error handling across providers
|
48
|
-
- **Authentication**:
|
48
|
+
- **Authentication**: Secure cookie-based authentication
|
49
49
|
|
50
50
|
## Installation
|
51
51
|
|
@@ -60,7 +60,7 @@ pip install indoxrouter
|
|
60
60
|
```python
|
61
61
|
from indoxrouter import Client
|
62
62
|
|
63
|
-
# Initialize with API key
|
63
|
+
# Initialize with API key
|
64
64
|
client = Client(api_key="your_api_key")
|
65
65
|
|
66
66
|
# Using environment variables
|
@@ -68,8 +68,25 @@ client = Client(api_key="your_api_key")
|
|
68
68
|
import os
|
69
69
|
os.environ["INDOX_ROUTER_API_KEY"] = "your_api_key"
|
70
70
|
client = Client()
|
71
|
+
|
72
|
+
# Connect to a custom server
|
73
|
+
client = Client(
|
74
|
+
api_key="your_api_key",
|
75
|
+
base_url="https://your-indoxrouter-server.com"
|
76
|
+
)
|
71
77
|
```
|
72
78
|
|
79
|
+
### Authentication
|
80
|
+
|
81
|
+
IndoxRouter uses cookie-based authentication, which securely transmits your API key in cookies rather than headers. This is handled automatically by the client.
|
82
|
+
|
83
|
+
```python
|
84
|
+
# Authentication is handled automatically when creating the client
|
85
|
+
client = Client(api_key="your_api_key")
|
86
|
+
```
|
87
|
+
|
88
|
+
> **Note**: The `use_cookies` parameter is kept for backward compatibility but should always be set to `True` as the server no longer supports header-based authentication.
|
89
|
+
|
73
90
|
### Chat Completions
|
74
91
|
|
75
92
|
```python
|
@@ -0,0 +1,8 @@
|
|
1
|
+
indoxrouter/__init__.py,sha256=28pdx482uGFF_S1msov0LTTGsFTvVBKRqMkDmoXWUBY,1416
|
2
|
+
indoxrouter/client.py,sha256=RgMgL_jN25_WNZkl3jxyU70joH-0ACBn4HN6X0Ls1t0,25495
|
3
|
+
indoxrouter/constants.py,sha256=vF9Ct7dLOUMAfU-FZk0datWEUOjUdS8k-BWB3iibFwA,1144
|
4
|
+
indoxrouter/exceptions.py,sha256=0ULxtK9va4718PGTO5VoClXYEJeojpiM-7AganeiZZ4,1263
|
5
|
+
indoxrouter-0.1.9.dist-info/METADATA,sha256=1pXMsjMZcwKcHZQwHWxDX6jd5DZTQWsvXgIb1yA4DUY,5564
|
6
|
+
indoxrouter-0.1.9.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
7
|
+
indoxrouter-0.1.9.dist-info/top_level.txt,sha256=v6FGWkw0QAnXhyYtnXLI1cxzna0iveNvZUotVzCWabM,12
|
8
|
+
indoxrouter-0.1.9.dist-info/RECORD,,
|
@@ -1,8 +0,0 @@
|
|
1
|
-
indoxrouter/__init__.py,sha256=28pdx482uGFF_S1msov0LTTGsFTvVBKRqMkDmoXWUBY,1416
|
2
|
-
indoxrouter/client.py,sha256=1XhBiz6CBoN_jNgKmmHvyXecdHZftDckssY2lAir_tA,24044
|
3
|
-
indoxrouter/constants.py,sha256=fBY0HNsVqiqk29QR2nkU_GjLEhT7IHg5k1d0wAIHDo8,1112
|
4
|
-
indoxrouter/exceptions.py,sha256=0ULxtK9va4718PGTO5VoClXYEJeojpiM-7AganeiZZ4,1263
|
5
|
-
indoxrouter-0.1.7.dist-info/METADATA,sha256=ZsIozuWEnCp_8oXrR1ABmTgiu2-4E3wrfaTOdjyW1xM,4971
|
6
|
-
indoxrouter-0.1.7.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
7
|
-
indoxrouter-0.1.7.dist-info/top_level.txt,sha256=v6FGWkw0QAnXhyYtnXLI1cxzna0iveNvZUotVzCWabM,12
|
8
|
-
indoxrouter-0.1.7.dist-info/RECORD,,
|
File without changes
|
File without changes
|