indoxrouter 0.1.8__tar.gz → 0.1.9__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: indoxrouter
3
- Version: 0.1.8
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**: Automatic token management
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 (default connects to localhost:8000)
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
@@ -7,7 +7,7 @@ A unified client for various AI providers, including OpenAI, Anthropic, Google,
7
7
  - **Unified API**: Access multiple AI providers through a single API
8
8
  - **Simple Interface**: Easy-to-use methods for chat, completion, embeddings, and image generation
9
9
  - **Error Handling**: Standardized error handling across providers
10
- - **Authentication**: Automatic token management
10
+ - **Authentication**: Secure cookie-based authentication
11
11
 
12
12
  ## Installation
13
13
 
@@ -22,7 +22,7 @@ pip install indoxrouter
22
22
  ```python
23
23
  from indoxrouter import Client
24
24
 
25
- # Initialize with API key (default connects to localhost:8000)
25
+ # Initialize with API key
26
26
  client = Client(api_key="your_api_key")
27
27
 
28
28
  # Using environment variables
@@ -30,8 +30,25 @@ client = Client(api_key="your_api_key")
30
30
  import os
31
31
  os.environ["INDOX_ROUTER_API_KEY"] = "your_api_key"
32
32
  client = Client()
33
+
34
+ # Connect to a custom server
35
+ client = Client(
36
+ api_key="your_api_key",
37
+ base_url="https://your-indoxrouter-server.com"
38
+ )
33
39
  ```
34
40
 
41
+ ### Authentication
42
+
43
+ IndoxRouter uses cookie-based authentication, which securely transmits your API key in cookies rather than headers. This is handled automatically by the client.
44
+
45
+ ```python
46
+ # Authentication is handled automatically when creating the client
47
+ client = Client(api_key="your_api_key")
48
+ ```
49
+
50
+ > **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.
51
+
35
52
  ### Chat Completions
36
53
 
37
54
  ```python
@@ -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 = base_url or DEFAULT_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
- self.session.headers.update({"Authorization": f"Bearer {self.api_key}"})
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
  """
@@ -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.8
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**: Automatic token management
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 (default connects to localhost:8000)
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
@@ -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.8",
12
+ version="0.1.9",
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