indoxrouter 0.1.11__py3-none-any.whl → 0.1.12__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 CHANGED
@@ -120,31 +120,38 @@ class Client:
120
120
  This uses the /auth/token endpoint to get JWT tokens using the API key.
121
121
  """
122
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")
123
+ # First try with the dedicated API key endpoint
124
+ logger.debug("Authenticating with dedicated API key endpoint")
125
125
  response = self.session.post(
126
- f"{self.base_url}/api/v1/auth/token",
127
- data={
128
- "username": self.api_key,
129
- "password": "",
130
- },
126
+ f"{self.base_url}/api/v1/auth/api-key",
127
+ headers={"X-API-Key": self.api_key},
131
128
  timeout=self.timeout,
132
129
  )
133
130
 
134
131
  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
- )
132
+ # If dedicated endpoint fails, try using the API key as a username
133
+ logger.debug("API key endpoint failed, trying with API key as username")
139
134
  response = self.session.post(
140
- f"{self.base_url}/api/v1/auth/login",
141
- json={
142
- "username": "pip_client",
143
- "password": self.api_key,
135
+ f"{self.base_url}/api/v1/auth/token",
136
+ data={
137
+ "username": self.api_key,
138
+ "password": self.api_key, # Try using API key as both username and password
144
139
  },
145
140
  timeout=self.timeout,
146
141
  )
147
142
 
143
+ if response.status_code != 200:
144
+ # Try one more method - the token endpoint with different format
145
+ logger.debug("Trying with API key as token parameter")
146
+ response = self.session.post(
147
+ f"{self.base_url}/api/v1/auth/token",
148
+ data={
149
+ "username": "pip_client",
150
+ "password": self.api_key,
151
+ },
152
+ timeout=self.timeout,
153
+ )
154
+
148
155
  if response.status_code != 200:
149
156
  error_data = {}
150
157
  try:
@@ -156,6 +163,17 @@ class Client:
156
163
  f"Authentication failed: {error_data.get('detail', 'Unknown error')}"
157
164
  )
158
165
 
166
+ # Check if we have a token in the response body
167
+ try:
168
+ response_data = response.json()
169
+ if "access_token" in response_data:
170
+ # Store token in the session object for later use
171
+ self.access_token = response_data["access_token"]
172
+ logger.debug("Retrieved access token from response body")
173
+ except:
174
+ # If we couldn't parse JSON, that's fine - we'll rely on cookies
175
+ logger.debug("No token found in response body, will rely on cookies")
176
+
159
177
  # At this point, the cookies should be set in the session
160
178
  logger.debug("Authentication successful")
161
179
 
@@ -227,6 +245,10 @@ class Client:
227
245
  url = f"{self.base_url}/{endpoint}"
228
246
  headers = {"Content-Type": "application/json"}
229
247
 
248
+ # Add Authorization header if we have an access token
249
+ if hasattr(self, "access_token") and self.access_token:
250
+ headers["Authorization"] = f"Bearer {self.access_token}"
251
+
230
252
  # logger.debug(f"Making {method} request to {url}")
231
253
  # if data:
232
254
  # logger.debug(f"Request data: {json.dumps(data, indent=2)}")
@@ -257,6 +279,10 @@ class Client:
257
279
  logger.debug("Received 401, attempting to reauthenticate")
258
280
  self._authenticate()
259
281
 
282
+ # Update Authorization header with new token if available
283
+ if hasattr(self, "access_token") and self.access_token:
284
+ headers["Authorization"] = f"Bearer {self.access_token}"
285
+
260
286
  # Retry the request after reauthentication
261
287
  response = self.session.request(
262
288
  method,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: indoxrouter
3
- Version: 0.1.11
3
+ Version: 0.1.12
4
4
  Summary: A unified client for various AI providers
5
5
  Home-page: https://github.com/indoxrouter/indoxrouter
6
6
  Author: indoxRouter Team
@@ -1,9 +1,9 @@
1
1
  indoxrouter/__init__.py,sha256=28pdx482uGFF_S1msov0LTTGsFTvVBKRqMkDmoXWUBY,1416
2
- indoxrouter/client.py,sha256=Bt8JuU7G_TSX2sVn3Voi6UBXeZnmG-vLCGniAGh_r5U,27387
2
+ indoxrouter/client.py,sha256=ixzCJP28ddYFQxwRiqdY5Fp1CB978DJpI4yCiOI3s4o,28898
3
3
  indoxrouter/constants.py,sha256=D-l5qhEmeDIXOEfogvf6lJI1Sw_fXSKZy-Nj_l_MV7E,1184
4
4
  indoxrouter/exceptions.py,sha256=0ULxtK9va4718PGTO5VoClXYEJeojpiM-7AganeiZZ4,1263
5
5
  indoxrouter/test_api_key.py,sha256=u4fUTJwxC7-kTrLdCq8u5a1Mx66jeExfsBlHLhyzNmA,3229
6
- indoxrouter-0.1.11.dist-info/METADATA,sha256=3SEOZwK_ZKPQCfZc7BRKYQ8q3u4meMtmSIbSY4VYZxg,6004
7
- indoxrouter-0.1.11.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
8
- indoxrouter-0.1.11.dist-info/top_level.txt,sha256=v6FGWkw0QAnXhyYtnXLI1cxzna0iveNvZUotVzCWabM,12
9
- indoxrouter-0.1.11.dist-info/RECORD,,
6
+ indoxrouter-0.1.12.dist-info/METADATA,sha256=pRupY-6V6GrozkXidKGm_qf6fBY2clAqYwgKAU5OJww,6004
7
+ indoxrouter-0.1.12.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
8
+ indoxrouter-0.1.12.dist-info/top_level.txt,sha256=v6FGWkw0QAnXhyYtnXLI1cxzna0iveNvZUotVzCWabM,12
9
+ indoxrouter-0.1.12.dist-info/RECORD,,