paygent-sdk 1.0.0__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.
@@ -0,0 +1,383 @@
1
+ Metadata-Version: 2.4
2
+ Name: paygent-sdk
3
+ Version: 1.0.0
4
+ Summary: Official Python SDK for Paygent - Track AI usage and costs across multiple providers (OpenAI, Anthropic, Google, DeepSeek, etc.)
5
+ Home-page: https://github.com/paygent/paygent-sdk-python
6
+ Author: Paygent
7
+ Author-email: Paygent Team <support@paygent.com>
8
+ Maintainer-email: Paygent Team <support@paygent.com>
9
+ License: MIT
10
+ Project-URL: Homepage, https://paygent.com
11
+ Project-URL: Repository, https://github.com/paygent/paygent-sdk-python
12
+ Project-URL: Documentation, https://github.com/paygent/paygent-sdk-python#readme
13
+ Project-URL: Bug Tracker, https://github.com/paygent/paygent-sdk-python/issues
14
+ Project-URL: Changelog, https://github.com/paygent/paygent-sdk-python/releases
15
+ Project-URL: Source Code, https://github.com/paygent/paygent-sdk-python
16
+ Keywords: paygent,sdk,ai,llm,usage,tracking,costs,openai,anthropic,claude,gpt,gemini,deepseek,token-counting,cost-calculation,api-integration
17
+ Classifier: Development Status :: 5 - Production/Stable
18
+ Classifier: Intended Audience :: Developers
19
+ Classifier: License :: OSI Approved :: MIT License
20
+ Classifier: Operating System :: OS Independent
21
+ Classifier: Programming Language :: Python :: 3
22
+ Classifier: Programming Language :: Python :: 3.7
23
+ Classifier: Programming Language :: Python :: 3.8
24
+ Classifier: Programming Language :: Python :: 3.9
25
+ Classifier: Programming Language :: Python :: 3.10
26
+ Classifier: Programming Language :: Python :: 3.11
27
+ Classifier: Programming Language :: Python :: 3.12
28
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
29
+ Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
30
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
31
+ Classifier: Typing :: Typed
32
+ Requires-Python: >=3.7
33
+ Description-Content-Type: text/markdown
34
+ License-File: LICENSE
35
+ Requires-Dist: requests>=2.25.0
36
+ Requires-Dist: urllib3>=1.26.0
37
+ Requires-Dist: tiktoken>=0.5.0
38
+ Provides-Extra: dev
39
+ Requires-Dist: pytest>=6.0; extra == "dev"
40
+ Requires-Dist: pytest-cov>=2.0; extra == "dev"
41
+ Requires-Dist: black>=21.0; extra == "dev"
42
+ Requires-Dist: flake8>=3.8; extra == "dev"
43
+ Requires-Dist: mypy>=0.800; extra == "dev"
44
+ Dynamic: author
45
+ Dynamic: home-page
46
+ Dynamic: license-file
47
+ Dynamic: requires-python
48
+
49
+ # Paygent SDK for Python
50
+
51
+ A Python SDK for integrating with the Paygent API to track usage and costs for AI models.
52
+
53
+ ## Installation
54
+
55
+ ```bash
56
+ pip install paygent-sdk-python
57
+ ```
58
+
59
+ ## Usage
60
+
61
+ ### Basic Usage
62
+
63
+ ```python
64
+ import logging
65
+ from paygent_sdk import Client, UsageData
66
+
67
+ def main():
68
+ # Create a new client with your API key
69
+ client = Client.new_client("your-paygent-api-key")
70
+
71
+ # Set log level (optional)
72
+ client.set_log_level(logging.INFO)
73
+
74
+ # Define usage data
75
+ usage_data = UsageData(
76
+ model="llama",
77
+ prompt_tokens=756,
78
+ completion_tokens=244,
79
+ total_tokens=1000
80
+ )
81
+
82
+ # Send usage data
83
+ try:
84
+ client.send_usage("agent-123", "customer-456", "email-sent", usage_data)
85
+ print("Usage data sent successfully!")
86
+ except Exception as e:
87
+ print(f"Failed to send usage: {e}")
88
+
89
+ if __name__ == "__main__":
90
+ main()
91
+ ```
92
+
93
+ ### Using SendUsageWithTokenString
94
+
95
+ ```python
96
+ import logging
97
+ from paygent_sdk import Client, UsageDataWithStrings
98
+
99
+ def main():
100
+ # Create a new client
101
+ client = Client.new_client_with_url("your-api-key", "http://localhost:8080")
102
+ client.set_log_level(logging.INFO)
103
+
104
+ # Define usage data with prompt and output strings
105
+ usage_data = UsageDataWithStrings(
106
+ service_provider="OpenAI",
107
+ model="gpt-4",
108
+ prompt_string="What is the capital of France? Please provide a detailed explanation.",
109
+ output_string="The capital of France is Paris. Paris is located in the north-central part of France and is the country's largest city and economic center."
110
+ )
111
+
112
+ # Send usage data (tokens will be automatically counted)
113
+ try:
114
+ client.send_usage_with_token_string("agent-123", "customer-456", "question-answer", usage_data)
115
+ print("Usage data sent successfully!")
116
+ except Exception as e:
117
+ print(f"Failed to send usage: {e}")
118
+
119
+ if __name__ == "__main__":
120
+ main()
121
+ ```
122
+
123
+ ### Using Model Constants
124
+
125
+ The SDK provides predefined constants for all supported models and service providers:
126
+
127
+ ```python
128
+ import logging
129
+ from paygent_sdk import (
130
+ Client,
131
+ UsageData,
132
+ OpenAIModels,
133
+ AnthropicModels,
134
+ ServiceProvider,
135
+ is_model_supported
136
+ )
137
+
138
+ def main():
139
+ client = Client.new_client("your-api-key")
140
+
141
+ # Use model constants
142
+ usage_data = UsageData(
143
+ service_provider=ServiceProvider.OPENAI,
144
+ model=OpenAIModels.GPT_4O,
145
+ prompt_tokens=1000,
146
+ completion_tokens=500,
147
+ total_tokens=1500
148
+ )
149
+
150
+ client.send_usage("agent-123", "customer-456", "chat-completion", usage_data)
151
+
152
+ # Check if a model is supported
153
+ if is_model_supported(OpenAIModels.GPT_5):
154
+ print("GPT-5 is supported!")
155
+
156
+ if __name__ == "__main__":
157
+ main()
158
+ ```
159
+
160
+ #### Available Model Constants
161
+
162
+ - **OpenAI**: `OpenAIModels.GPT_5`, `OpenAIModels.GPT_4O`, `OpenAIModels.GPT_4O_MINI`, `OpenAIModels.O1`, `OpenAIModels.O3`, etc.
163
+ - **Anthropic**: `AnthropicModels.SONNET_4_5`, `AnthropicModels.HAIKU_4_5`, `AnthropicModels.OPUS_4_1`, etc.
164
+ - **Google DeepMind**: `GoogleDeepMindModels.GEMINI_2_5_PRO`, `GoogleDeepMindModels.GEMINI_2_5_FLASH`, etc.
165
+ - **Meta**: `MetaModels.LLAMA_4_MAVERICK`, `MetaModels.LLAMA_3_1_405B_INSTRUCT_TURBO`, etc.
166
+ - **AWS**: `AWSModels.AMAZON_NOVA_PRO`, `AWSModels.AMAZON_NOVA_LITE`, etc.
167
+ - **Mistral AI**: `MistralAIModels.MISTRAL_LARGE`, `MistralAIModels.MISTRAL_MEDIUM`, etc.
168
+ - **Cohere**: `CohereModels.COMMAND_R_PLUS`, `CohereModels.COMMAND_R`, etc.
169
+ - **DeepSeek**: `DeepSeekModels.DEEPSEEK_R1_GLOBAL`, `DeepSeekModels.DEEPSEEK_REASONER`, etc.
170
+
171
+ ### Advanced Usage
172
+
173
+ ```python
174
+ import logging
175
+ from paygent_sdk import Client, UsageData, UsageDataWithStrings
176
+
177
+ def main():
178
+ # Create client with custom base URL
179
+ client = Client.new_client_with_url("your-api-key", "https://custom-api.paygent.com")
180
+
181
+ # Set debug logging
182
+ client.set_log_level(logging.DEBUG)
183
+
184
+ # Get logger for custom logging
185
+ logger = client.get_logger()
186
+ logger.info("Starting usage tracking...")
187
+
188
+ # Method 1: Send usage data with pre-calculated tokens
189
+ usage_data = UsageData(
190
+ model="gpt-4",
191
+ prompt_tokens=1000,
192
+ completion_tokens=500,
193
+ total_tokens=1500
194
+ )
195
+
196
+ try:
197
+ client.send_usage("agent-789", "customer-101", "chat-completion", usage_data)
198
+ logger.info("Usage data sent successfully!")
199
+ except Exception as e:
200
+ logger.error(f"Failed to send usage: {e}")
201
+
202
+ # Method 2: Send usage data with automatic token counting
203
+ usage_data_strings = UsageDataWithStrings(
204
+ service_provider="Anthropic",
205
+ model="claude-3-sonnet",
206
+ prompt_string="Hello, how are you?",
207
+ output_string="I'm doing well, thank you for asking!"
208
+ )
209
+
210
+ try:
211
+ client.send_usage_with_token_string("agent-789", "customer-101", "greeting", usage_data_strings)
212
+ logger.info("Usage data with token strings sent successfully!")
213
+ except Exception as e:
214
+ logger.error(f"Failed to send usage with token strings: {e}")
215
+
216
+ if __name__ == "__main__":
217
+ main()
218
+ ```
219
+
220
+ ## API Reference
221
+
222
+ ### Client
223
+
224
+ #### `Client.new_client(api_key: str) -> Client`
225
+ Creates a new Paygent SDK client with the default API URL.
226
+
227
+ #### `Client.new_client_with_url(api_key: str, base_url: str) -> Client`
228
+ Creates a new Paygent SDK client with a custom base URL.
229
+
230
+ #### `send_usage(agent_id: str, customer_id: str, indicator: str, usage_data: UsageData) -> None`
231
+ Sends usage data to the Paygent API with pre-calculated token counts. Raises an exception if the request fails.
232
+
233
+ #### `send_usage_with_token_string(agent_id: str, customer_id: str, indicator: str, usage_data: UsageDataWithStrings) -> None`
234
+ Sends usage data to the Paygent API using prompt and output strings. The function automatically counts tokens using proper tokenizers for each model provider and calculates costs. Raises an exception if the request fails.
235
+
236
+ #### `set_log_level(level: int) -> None`
237
+ Sets the logging level for the client.
238
+
239
+ #### `get_logger() -> logging.Logger`
240
+ Returns the logger instance for custom logging.
241
+
242
+ ### Types
243
+
244
+ #### `UsageData`
245
+ ```python
246
+ @dataclass
247
+ class UsageData:
248
+ model: str
249
+ prompt_tokens: int
250
+ completion_tokens: int
251
+ total_tokens: int
252
+ ```
253
+
254
+ #### `UsageDataWithStrings`
255
+ ```python
256
+ @dataclass
257
+ class UsageDataWithStrings:
258
+ service_provider: str
259
+ model: str
260
+ prompt_string: str
261
+ output_string: str
262
+ ```
263
+
264
+ ## Supported Models
265
+
266
+ The SDK includes built-in pricing for models from the following providers:
267
+
268
+ ### OpenAI
269
+ - `gpt-3.5-turbo` - $1.50 prompt, $2.00 completion (per 1000 tokens)
270
+ - `gpt-3.5-turbo-16k` - $3.00 prompt, $4.00 completion (per 1000 tokens)
271
+ - `gpt-4` - $30.00 prompt, $60.00 completion (per 1000 tokens)
272
+ - `gpt-4-turbo` - $10.00 prompt, $30.00 completion (per 1000 tokens)
273
+ - `gpt-4o` - $5.00 prompt, $15.00 completion (per 1000 tokens)
274
+ - `gpt-4o-mini` - $0.15 prompt, $0.60 completion (per 1000 tokens)
275
+
276
+ ### Anthropic
277
+ - `claude-3-haiku` - $0.25 prompt, $1.25 completion (per 1000 tokens)
278
+ - `claude-3-sonnet` - $3.00 prompt, $15.00 completion (per 1000 tokens)
279
+ - `claude-3-opus` - $15.00 prompt, $75.00 completion (per 1000 tokens)
280
+ - `claude-3.5-sonnet` - $3.00 prompt, $15.00 completion (per 1000 tokens)
281
+
282
+ ### Google DeepMind
283
+ - `gemini-pro` - $0.50 prompt, $1.50 completion (per 1000 tokens)
284
+ - `gemini-1.5-pro` - $1.25 prompt, $5.00 completion (per 1000 tokens)
285
+ - `gemini-1.5-flash` - $0.075 prompt, $0.30 completion (per 1000 tokens)
286
+
287
+ ### Meta
288
+ - `llama-2-7b` - $0.10 per 1000 tokens
289
+ - `llama-2-13b` - $0.20 per 1000 tokens
290
+ - `llama-2-70b` - $0.70 per 1000 tokens
291
+ - `llama-3-8b` - $0.10 per 1000 tokens
292
+ - `llama-3-70b` - $0.70 per 1000 tokens
293
+
294
+ ### AWS
295
+ - `claude-3-haiku-aws` - $0.25 prompt, $1.25 completion (per 1000 tokens)
296
+ - `claude-3-sonnet-aws` - $3.00 prompt, $15.00 completion (per 1000 tokens)
297
+ - `titan-text-express` - $0.80 prompt, $1.60 completion (per 1000 tokens)
298
+
299
+ ### Mistral AI
300
+ - `mistral-7b` - $0.10 per 1000 tokens
301
+ - `mistral-large` - $2.00 prompt, $6.00 completion (per 1000 tokens)
302
+
303
+ ### Cohere
304
+ - `command` - $1.50 prompt, $2.00 completion (per 1000 tokens)
305
+ - `command-r-plus` - $3.00 prompt, $15.00 completion (per 1000 tokens)
306
+
307
+ ### DeepSeek
308
+ - `deepseek-chat` - $0.10 prompt, $0.20 completion (per 1000 tokens)
309
+
310
+ For unknown models, the SDK will use default pricing of $0.10 per 1000 tokens.
311
+
312
+ ## Token Counting
313
+
314
+ The SDK uses accurate token counting for different model providers:
315
+
316
+ - **OpenAI GPT models**: Uses the official tiktoken library with model-specific encodings
317
+ - **Anthropic Claude models**: Uses cl100k_base encoding (same as GPT-4)
318
+ - **Google Gemini models**: Uses cl100k_base encoding as approximation
319
+ - **Meta Llama models**: Uses cl100k_base encoding as approximation
320
+ - **Mistral models**: Uses cl100k_base encoding as approximation
321
+ - **Cohere models**: Uses cl100k_base encoding as approximation
322
+ - **DeepSeek models**: Uses cl100k_base encoding as approximation
323
+ - **AWS Titan models**: Uses cl100k_base encoding as approximation
324
+ - **Unknown models**: Falls back to word-based estimation (1.3 tokens per word)
325
+
326
+ The token counting is performed automatically when using `send_usage_with_token_string()`.
327
+
328
+ ## Logging
329
+
330
+ The SDK uses Python's built-in logging module. You can control the log level and access the logger for custom logging.
331
+
332
+ ```python
333
+ import logging
334
+
335
+ # Set log level
336
+ client.set_log_level(logging.DEBUG)
337
+
338
+ # Get logger for custom logging
339
+ logger = client.get_logger()
340
+ logger.info("Custom log message")
341
+ ```
342
+
343
+ ## Authentication
344
+
345
+ The SDK uses the `paygent-api-key` header for authentication. Make sure to provide a valid API key when creating the client.
346
+
347
+ ## Error Handling
348
+
349
+ The SDK raises appropriate exceptions for various failure scenarios:
350
+
351
+ - `requests.RequestException` - Network and HTTP errors
352
+ - `ValueError` - Invalid usage data or cost calculation errors
353
+
354
+ ```python
355
+ try:
356
+ client.send_usage("agent-123", "customer-456", "test", usage_data)
357
+ except requests.RequestException as e:
358
+ print(f"Network error: {e}")
359
+ except ValueError as e:
360
+ print(f"Invalid data: {e}")
361
+ ```
362
+
363
+ ## Development
364
+
365
+ ### Running Tests
366
+
367
+ ```bash
368
+ python -m pytest tests/
369
+ ```
370
+
371
+ ### Running Examples
372
+
373
+ ```bash
374
+ # Basic usage
375
+ python examples/basic_usage.py
376
+
377
+ # Advanced usage
378
+ python examples/advanced_usage.py
379
+ ```
380
+
381
+ ## License
382
+
383
+ MIT
@@ -0,0 +1,15 @@
1
+ examples/__init__.py,sha256=rkdmhcIN-xvRIaDWOWpUGQcdWZLopvjiK-4A2n40wQI,19
2
+ examples/advanced_usage.py,sha256=a8GlGg2mlbi0KccOJMXZihfJKJsZvOcjAa0vutoCTHQ,3619
3
+ examples/basic_usage.py,sha256=FvFR7t5Xs1eeV1-C6aAVQx2mhY8S8nJGGaJQd_Es0vg,1039
4
+ examples/constants_usage.py,sha256=fdmgbdAnVDlvdxuWIfpGX49NxuMGK3dwQ780D10ltmQ,4490
5
+ paygent_sdk/__init__.py,sha256=HUhtOr2BAyY16isDoVuNjUIv8Q-9dkmUT4hN-udWX2U,991
6
+ paygent_sdk/client.py,sha256=ypaKKrKNvDb-OW9bh5ex2C1YEiZ0_QYcGQKszd0tpSo,15819
7
+ paygent_sdk/constants.py,sha256=kTfLex00p8z8w7jBTfwMCYTks1BGYlmcWWGbPkXILc4,6355
8
+ paygent_sdk/models.py,sha256=RMa0SKj1U8mFXNFpD9d7EVWB4PXx9qj4KLZe-qlMAtw,20237
9
+ paygent_sdk-1.0.0.dist-info/licenses/LICENSE,sha256=HXncQw9T-dF8ItNiDu_T-Mv_A3Fl73Is7a8K8ZDXgZI,1064
10
+ tests/__init__.py,sha256=Wk73Io62J15BtlLVIzxmASDWaaJkQLevS4BLK5LDAQg,16
11
+ tests/test_client.py,sha256=63es9cOeWyclR9yM0SLcV8rSfOtlqr6YRjWG4sCTbMg,10500
12
+ paygent_sdk-1.0.0.dist-info/METADATA,sha256=C3a9o9DoKGHXz0tojaTwjphQtGK2UqDSoq2wEC8yu8g,12493
13
+ paygent_sdk-1.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
+ paygent_sdk-1.0.0.dist-info/top_level.txt,sha256=tWbxCRKTt8EeYPhYm8mE6QukqT6EVfai6RMaT9GnVkk,27
15
+ paygent_sdk-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Paygent
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ examples
2
+ paygent_sdk
3
+ tests
tests/__init__.py ADDED
@@ -0,0 +1 @@
1
+ # Tests package