aiutils-sdk 0.3.0__tar.gz → 0.4.0__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.
- {aiutils_sdk-0.3.0/aiutils_sdk.egg-info → aiutils_sdk-0.4.0}/PKG-INFO +81 -3
- aiutils_sdk-0.3.0/PKG-INFO → aiutils_sdk-0.4.0/README.md +76 -19
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.4.0}/aiutils_sdk/__init__.py +3 -3
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.4.0}/aiutils_sdk/client.py +63 -20
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.4.0}/aiutils_sdk/exceptions.py +9 -1
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.4.0}/aiutils_sdk/files.py +0 -10
- aiutils_sdk-0.4.0/aiutils_sdk/referrals.py +38 -0
- aiutils_sdk-0.4.0/aiutils_sdk/teams.py +88 -0
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.4.0}/aiutils_sdk/tools_and_batch.py +1 -1
- aiutils_sdk-0.4.0/aiutils_sdk/usage.py +85 -0
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.4.0}/aiutils_sdk/wallet.py +9 -9
- aiutils_sdk-0.3.0/README.md → aiutils_sdk-0.4.0/aiutils_sdk.egg-info/PKG-INFO +97 -2
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.4.0}/aiutils_sdk.egg-info/SOURCES.txt +3 -1
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.4.0}/pyproject.toml +7 -1
- aiutils_sdk-0.4.0/tests/test_sdk.py +950 -0
- aiutils_sdk-0.3.0/aiutils_sdk/research.py +0 -101
- aiutils_sdk-0.3.0/tests/test_sdk.py +0 -466
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.4.0}/aiutils_sdk/chat.py +0 -0
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.4.0}/aiutils_sdk/embeddings.py +0 -0
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.4.0}/aiutils_sdk/generations.py +0 -0
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.4.0}/aiutils_sdk/images.py +0 -0
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.4.0}/aiutils_sdk/models.py +0 -0
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.4.0}/aiutils_sdk/webhooks.py +0 -0
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.4.0}/aiutils_sdk.egg-info/dependency_links.txt +0 -0
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.4.0}/aiutils_sdk.egg-info/requires.txt +0 -0
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.4.0}/aiutils_sdk.egg-info/top_level.txt +0 -0
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.4.0}/setup.cfg +0 -0
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: aiutils-sdk
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Python SDK for the AiUtils Developer API — 100+ AI models via one unified API
|
|
5
5
|
Author-email: AiUtils Team <dev@aiutils.io>
|
|
6
6
|
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://developer.aiutils.io
|
|
8
|
+
Project-URL: Documentation, https://developer.aiutils.io/docs
|
|
9
|
+
Project-URL: Repository, https://github.com/Elidia-Technology/aiutils-sdks/tree/main/python
|
|
10
|
+
Project-URL: Issues, https://github.com/Elidia-Technology/aiutils-sdks/issues
|
|
7
11
|
Keywords: ai,llm,openai,anthropic,generation,sdk
|
|
8
12
|
Classifier: Development Status :: 4 - Beta
|
|
9
13
|
Classifier: Intended Audience :: Developers
|
|
@@ -17,7 +21,7 @@ Requires-Dist: pydantic>=2.0
|
|
|
17
21
|
|
|
18
22
|
# AiUtils Python SDK
|
|
19
23
|
|
|
20
|
-
Official Python SDK for the [AiUtils Developer API](https://developer.aiutils.io) — access 1400+ AI models (LLM, image, video, audio, 3D) through one unified API.
|
|
24
|
+
Official Python SDK for the [AiUtils Developer API](https://developer.aiutils.io) — access 1400+ AI models (LLM, image, video, audio, 3D) through one unified API. **v0.3.1**
|
|
21
25
|
|
|
22
26
|
## Install
|
|
23
27
|
|
|
@@ -341,13 +345,15 @@ estimate = client.wallet.estimate_cost(
|
|
|
341
345
|
```python
|
|
342
346
|
from aiutils_sdk import (
|
|
343
347
|
AiUtils, AuthenticationError, InsufficientDTError,
|
|
344
|
-
RateLimitError, APIError, ProviderError,
|
|
348
|
+
RateLimitError, ForbiddenError, APIError, ProviderError,
|
|
345
349
|
)
|
|
346
350
|
|
|
347
351
|
try:
|
|
348
352
|
response = client.chat.completions.create(...)
|
|
349
353
|
except AuthenticationError:
|
|
350
354
|
print("Invalid API key — check developer.aiutils.io/api-keys")
|
|
355
|
+
except ForbiddenError:
|
|
356
|
+
print("Insufficient scopes — check API key permissions")
|
|
351
357
|
except InsufficientDTError:
|
|
352
358
|
print("Not enough DT — top up at developer.aiutils.io/billing")
|
|
353
359
|
except RateLimitError:
|
|
@@ -388,6 +394,78 @@ with AiUtils(api_key="ak-dev-YOUR_KEY") as client:
|
|
|
388
394
|
|
|
389
395
|
---
|
|
390
396
|
|
|
397
|
+
## Billing
|
|
398
|
+
|
|
399
|
+
Purchase DT packs and view invoices.
|
|
400
|
+
|
|
401
|
+
```python
|
|
402
|
+
# List available DT packs
|
|
403
|
+
packs = client.billing.list_packs()
|
|
404
|
+
for p in packs:
|
|
405
|
+
print(f"{p['name']}: {p['dt_amount']} DT for ${p['price_usd']}")
|
|
406
|
+
|
|
407
|
+
# Create checkout session
|
|
408
|
+
checkout = client.billing.checkout(pack_slug="pack_10k")
|
|
409
|
+
print(checkout) # Checkout session created
|
|
410
|
+
|
|
411
|
+
# View invoice (returns PDF bytes)
|
|
412
|
+
invoice_bytes = client.billing.get_invoice(transaction_id="txn_abc123")
|
|
413
|
+
with open("invoice.pdf", "wb") as f:
|
|
414
|
+
f.write(invoice_bytes)
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
## File Upload
|
|
418
|
+
|
|
419
|
+
Upload images for vision analysis in chat completions.
|
|
420
|
+
|
|
421
|
+
```python
|
|
422
|
+
# Upload an image
|
|
423
|
+
file = client.files.upload("photo.jpg")
|
|
424
|
+
|
|
425
|
+
# List uploaded files
|
|
426
|
+
files = client.files.list()
|
|
427
|
+
for f in files:
|
|
428
|
+
print(f"{f['id']}: {f['filename']}")
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
## Portal Tools
|
|
432
|
+
|
|
433
|
+
Access 147+ built-in AI tools — email, calendar, database, browser, and more.
|
|
434
|
+
|
|
435
|
+
```python
|
|
436
|
+
# List tool categories
|
|
437
|
+
genres = client.tools.genres()
|
|
438
|
+
|
|
439
|
+
# Execute a tool
|
|
440
|
+
result = client.tools.execute(
|
|
441
|
+
tool_slug="email-send",
|
|
442
|
+
to="user@example.com",
|
|
443
|
+
subject="Hello",
|
|
444
|
+
body="Test email"
|
|
445
|
+
)
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
## Batch Requests
|
|
449
|
+
|
|
450
|
+
Submit multiple requests in one API call.
|
|
451
|
+
|
|
452
|
+
```python
|
|
453
|
+
# Create a batch
|
|
454
|
+
batch = client.batch.create(requests=[
|
|
455
|
+
{"method": "POST", "path": "/v1/chat/completions", "body": {
|
|
456
|
+
"model": "gen:deepseek:deepseek-v4-flash",
|
|
457
|
+
"messages": [{"role": "user", "content": "Hi"}]
|
|
458
|
+
}},
|
|
459
|
+
{"method": "POST", "path": "/v1/chat/completions", "body": {
|
|
460
|
+
"model": "gen:anthropic:claude-haiku-4-5",
|
|
461
|
+
"messages": [{"role": "user", "content": "Hello"}]
|
|
462
|
+
}},
|
|
463
|
+
])
|
|
464
|
+
|
|
465
|
+
# Check batch status
|
|
466
|
+
status = client.batch.status(batch_id=batch["batch_id"])
|
|
467
|
+
```
|
|
468
|
+
|
|
391
469
|
## Links
|
|
392
470
|
|
|
393
471
|
- [Developer Console](https://developer.aiutils.io)
|
|
@@ -1,23 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: aiutils-sdk
|
|
3
|
-
Version: 0.3.0
|
|
4
|
-
Summary: Python SDK for the AiUtils Developer API — 100+ AI models via one unified API
|
|
5
|
-
Author-email: AiUtils Team <dev@aiutils.io>
|
|
6
|
-
License-Expression: MIT
|
|
7
|
-
Keywords: ai,llm,openai,anthropic,generation,sdk
|
|
8
|
-
Classifier: Development Status :: 4 - Beta
|
|
9
|
-
Classifier: Intended Audience :: Developers
|
|
10
|
-
Classifier: Programming Language :: Python :: 3
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
-
Requires-Python: >=3.9
|
|
14
|
-
Description-Content-Type: text/markdown
|
|
15
|
-
Requires-Dist: httpx>=0.25.0
|
|
16
|
-
Requires-Dist: pydantic>=2.0
|
|
17
|
-
|
|
18
1
|
# AiUtils Python SDK
|
|
19
2
|
|
|
20
|
-
Official Python SDK for the [AiUtils Developer API](https://developer.aiutils.io) — access 1400+ AI models (LLM, image, video, audio, 3D) through one unified API.
|
|
3
|
+
Official Python SDK for the [AiUtils Developer API](https://developer.aiutils.io) — access 1400+ AI models (LLM, image, video, audio, 3D) through one unified API. **v0.3.1**
|
|
21
4
|
|
|
22
5
|
## Install
|
|
23
6
|
|
|
@@ -341,13 +324,15 @@ estimate = client.wallet.estimate_cost(
|
|
|
341
324
|
```python
|
|
342
325
|
from aiutils_sdk import (
|
|
343
326
|
AiUtils, AuthenticationError, InsufficientDTError,
|
|
344
|
-
RateLimitError, APIError, ProviderError,
|
|
327
|
+
RateLimitError, ForbiddenError, APIError, ProviderError,
|
|
345
328
|
)
|
|
346
329
|
|
|
347
330
|
try:
|
|
348
331
|
response = client.chat.completions.create(...)
|
|
349
332
|
except AuthenticationError:
|
|
350
333
|
print("Invalid API key — check developer.aiutils.io/api-keys")
|
|
334
|
+
except ForbiddenError:
|
|
335
|
+
print("Insufficient scopes — check API key permissions")
|
|
351
336
|
except InsufficientDTError:
|
|
352
337
|
print("Not enough DT — top up at developer.aiutils.io/billing")
|
|
353
338
|
except RateLimitError:
|
|
@@ -388,6 +373,78 @@ with AiUtils(api_key="ak-dev-YOUR_KEY") as client:
|
|
|
388
373
|
|
|
389
374
|
---
|
|
390
375
|
|
|
376
|
+
## Billing
|
|
377
|
+
|
|
378
|
+
Purchase DT packs and view invoices.
|
|
379
|
+
|
|
380
|
+
```python
|
|
381
|
+
# List available DT packs
|
|
382
|
+
packs = client.billing.list_packs()
|
|
383
|
+
for p in packs:
|
|
384
|
+
print(f"{p['name']}: {p['dt_amount']} DT for ${p['price_usd']}")
|
|
385
|
+
|
|
386
|
+
# Create checkout session
|
|
387
|
+
checkout = client.billing.checkout(pack_slug="pack_10k")
|
|
388
|
+
print(checkout) # Checkout session created
|
|
389
|
+
|
|
390
|
+
# View invoice (returns PDF bytes)
|
|
391
|
+
invoice_bytes = client.billing.get_invoice(transaction_id="txn_abc123")
|
|
392
|
+
with open("invoice.pdf", "wb") as f:
|
|
393
|
+
f.write(invoice_bytes)
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
## File Upload
|
|
397
|
+
|
|
398
|
+
Upload images for vision analysis in chat completions.
|
|
399
|
+
|
|
400
|
+
```python
|
|
401
|
+
# Upload an image
|
|
402
|
+
file = client.files.upload("photo.jpg")
|
|
403
|
+
|
|
404
|
+
# List uploaded files
|
|
405
|
+
files = client.files.list()
|
|
406
|
+
for f in files:
|
|
407
|
+
print(f"{f['id']}: {f['filename']}")
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
## Portal Tools
|
|
411
|
+
|
|
412
|
+
Access 147+ built-in AI tools — email, calendar, database, browser, and more.
|
|
413
|
+
|
|
414
|
+
```python
|
|
415
|
+
# List tool categories
|
|
416
|
+
genres = client.tools.genres()
|
|
417
|
+
|
|
418
|
+
# Execute a tool
|
|
419
|
+
result = client.tools.execute(
|
|
420
|
+
tool_slug="email-send",
|
|
421
|
+
to="user@example.com",
|
|
422
|
+
subject="Hello",
|
|
423
|
+
body="Test email"
|
|
424
|
+
)
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
## Batch Requests
|
|
428
|
+
|
|
429
|
+
Submit multiple requests in one API call.
|
|
430
|
+
|
|
431
|
+
```python
|
|
432
|
+
# Create a batch
|
|
433
|
+
batch = client.batch.create(requests=[
|
|
434
|
+
{"method": "POST", "path": "/v1/chat/completions", "body": {
|
|
435
|
+
"model": "gen:deepseek:deepseek-v4-flash",
|
|
436
|
+
"messages": [{"role": "user", "content": "Hi"}]
|
|
437
|
+
}},
|
|
438
|
+
{"method": "POST", "path": "/v1/chat/completions", "body": {
|
|
439
|
+
"model": "gen:anthropic:claude-haiku-4-5",
|
|
440
|
+
"messages": [{"role": "user", "content": "Hello"}]
|
|
441
|
+
}},
|
|
442
|
+
])
|
|
443
|
+
|
|
444
|
+
# Check batch status
|
|
445
|
+
status = client.batch.status(batch_id=batch["batch_id"])
|
|
446
|
+
```
|
|
447
|
+
|
|
391
448
|
## Links
|
|
392
449
|
|
|
393
450
|
- [Developer Console](https://developer.aiutils.io)
|
|
@@ -3,13 +3,13 @@ from aiutils_sdk.client import AiUtils
|
|
|
3
3
|
from aiutils_sdk.chat import ChatResponse, ChatStreamChunk
|
|
4
4
|
from aiutils_sdk.exceptions import (
|
|
5
5
|
AiUtilsError, AuthenticationError, InsufficientDTError,
|
|
6
|
-
RateLimitError, APIError, ProviderError,
|
|
6
|
+
RateLimitError, ForbiddenError, APIError, ProviderError,
|
|
7
7
|
)
|
|
8
8
|
|
|
9
|
-
__version__ = "0.
|
|
9
|
+
__version__ = "0.4.0"
|
|
10
10
|
__all__ = [
|
|
11
11
|
"AiUtils",
|
|
12
12
|
"ChatResponse", "ChatStreamChunk",
|
|
13
13
|
"AiUtilsError", "AuthenticationError", "InsufficientDTError",
|
|
14
|
-
"RateLimitError", "APIError", "ProviderError",
|
|
14
|
+
"RateLimitError", "ForbiddenError", "APIError", "ProviderError",
|
|
15
15
|
]
|
|
@@ -11,11 +11,13 @@ from aiutils_sdk.images import Images
|
|
|
11
11
|
from aiutils_sdk.embeddings import Embeddings
|
|
12
12
|
from aiutils_sdk.generations import Generations
|
|
13
13
|
from aiutils_sdk.models import Models
|
|
14
|
-
from aiutils_sdk.research import Research
|
|
15
14
|
from aiutils_sdk.wallet import Wallet, Billing
|
|
16
15
|
from aiutils_sdk.webhooks import Webhooks
|
|
17
16
|
from aiutils_sdk.files import Files
|
|
18
17
|
from aiutils_sdk.tools_and_batch import Tools, Batch
|
|
18
|
+
from aiutils_sdk.teams import Teams
|
|
19
|
+
from aiutils_sdk.usage import Usage
|
|
20
|
+
from aiutils_sdk.referrals import Referrals
|
|
19
21
|
from aiutils_sdk.exceptions import AuthenticationError, APIError
|
|
20
22
|
|
|
21
23
|
logger = logging.getLogger(__name__)
|
|
@@ -54,47 +56,91 @@ class AiUtils:
|
|
|
54
56
|
self.embeddings = Embeddings(self)
|
|
55
57
|
self.generations = Generations(self)
|
|
56
58
|
self.models = Models(self)
|
|
57
|
-
self.research = Research(self)
|
|
58
59
|
self.wallet = Wallet(self)
|
|
59
60
|
self.webhooks = Webhooks(self)
|
|
60
61
|
self.billing = Billing(self)
|
|
61
62
|
self.files = Files(self)
|
|
62
63
|
self.tools = Tools(self)
|
|
63
64
|
self.batch = Batch(self)
|
|
65
|
+
self.teams = Teams(self)
|
|
66
|
+
self.usage = Usage(self)
|
|
67
|
+
self.referrals = Referrals(self)
|
|
64
68
|
|
|
65
|
-
def _request(self, method: str, path: str, **kwargs) -> dict:
|
|
66
|
-
"""Make a synchronous HTTP request.
|
|
69
|
+
def _request(self, method: str, path: str, raw: bool = False, **kwargs) -> dict | bytes:
|
|
70
|
+
"""Make a synchronous HTTP request.
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
raw: If True, return the raw response body (bytes) instead of
|
|
74
|
+
parsing JSON. Used for binary endpoints such as PDF invoices.
|
|
75
|
+
"""
|
|
67
76
|
url = f"{self.base_url}{path}"
|
|
68
77
|
logger.debug(f"Entered into _request: {method} {path}")
|
|
69
|
-
response = self._client.request(method, url, headers=self.
|
|
70
|
-
return self._handle_response(response)
|
|
78
|
+
response = self._client.request(method, url, headers=self._request_headers(kwargs), **kwargs)
|
|
79
|
+
return self._handle_response(response, raw=raw)
|
|
80
|
+
|
|
81
|
+
async def _request_async(self, method: str, path: str, raw: bool = False, **kwargs) -> dict | bytes:
|
|
82
|
+
"""Make an async HTTP request.
|
|
71
83
|
|
|
72
|
-
|
|
73
|
-
|
|
84
|
+
Args:
|
|
85
|
+
raw: If True, return the raw response body (bytes) instead of
|
|
86
|
+
parsing JSON. Used for binary endpoints such as PDF invoices.
|
|
87
|
+
"""
|
|
74
88
|
url = f"{self.base_url}{path}"
|
|
75
89
|
logger.debug(f"Entered into _request_async: {method} {path}")
|
|
76
90
|
if self._async_client is None:
|
|
77
91
|
self._async_client = httpx.AsyncClient(timeout=self._client.timeout)
|
|
78
|
-
response = await self._async_client.request(method, url, headers=self.
|
|
79
|
-
return self._handle_response(response)
|
|
92
|
+
response = await self._async_client.request(method, url, headers=self._request_headers(kwargs), **kwargs)
|
|
93
|
+
return self._handle_response(response, raw=raw)
|
|
94
|
+
|
|
95
|
+
def _request_headers(self, kwargs: dict) -> dict:
|
|
96
|
+
"""Build request headers.
|
|
97
|
+
|
|
98
|
+
For multipart uploads (files=), the hardcoded JSON Content-Type must be
|
|
99
|
+
dropped so httpx can set the correct ``multipart/form-data`` header
|
|
100
|
+
with its generated boundary; otherwise the server rejects the body.
|
|
101
|
+
"""
|
|
102
|
+
if kwargs.get("files"):
|
|
103
|
+
return {k: v for k, v in self._headers.items() if k.lower() != "content-type"}
|
|
104
|
+
return self._headers
|
|
80
105
|
|
|
81
|
-
def _handle_response(self, response: httpx.Response) -> dict:
|
|
106
|
+
def _handle_response(self, response: httpx.Response, raw: bool = False) -> dict | bytes:
|
|
82
107
|
"""Parse response and raise appropriate errors."""
|
|
83
108
|
if response.status_code == 401:
|
|
84
109
|
raise AuthenticationError("Invalid or expired API key")
|
|
85
110
|
if response.status_code == 429:
|
|
86
111
|
from aiutils_sdk.exceptions import RateLimitError
|
|
87
|
-
retry_after = response.headers.get("
|
|
112
|
+
retry_after = response.headers.get("Retry-After", "60")
|
|
88
113
|
raise RateLimitError(f"Rate limit exceeded. Retry after {retry_after}s")
|
|
114
|
+
if response.status_code == 403:
|
|
115
|
+
from aiutils_sdk.exceptions import ForbiddenError
|
|
116
|
+
raise ForbiddenError(response.text[:500] or "Access forbidden — check your API key scopes")
|
|
89
117
|
if response.status_code == 402:
|
|
90
118
|
from aiutils_sdk.exceptions import InsufficientDTError
|
|
91
|
-
|
|
119
|
+
try:
|
|
120
|
+
detail = response.json().get("detail", "Insufficient DT balance")
|
|
121
|
+
except Exception:
|
|
122
|
+
detail = response.text[:500] or "Insufficient DT balance"
|
|
92
123
|
raise InsufficientDTError(detail)
|
|
124
|
+
if response.status_code in (502, 503):
|
|
125
|
+
from aiutils_sdk.exceptions import ProviderError
|
|
126
|
+
try:
|
|
127
|
+
body = response.json()
|
|
128
|
+
detail = body.get("detail") or body.get("error", {}).get("message", str(body))
|
|
129
|
+
except Exception:
|
|
130
|
+
detail = response.text[:500] or "AI provider temporarily unavailable"
|
|
131
|
+
raise ProviderError(detail, status_code=response.status_code)
|
|
93
132
|
if response.status_code >= 400:
|
|
133
|
+
try:
|
|
134
|
+
body = response.json()
|
|
135
|
+
detail = body.get("detail") or body.get("error", {}).get("message", str(body))
|
|
136
|
+
except Exception:
|
|
137
|
+
detail = response.text[:500]
|
|
94
138
|
raise APIError(
|
|
95
|
-
|
|
139
|
+
detail,
|
|
96
140
|
status_code=response.status_code,
|
|
97
141
|
)
|
|
142
|
+
if raw:
|
|
143
|
+
return response.content
|
|
98
144
|
return response.json()
|
|
99
145
|
|
|
100
146
|
def close(self):
|
|
@@ -103,13 +149,10 @@ class AiUtils:
|
|
|
103
149
|
if self._async_client:
|
|
104
150
|
import asyncio
|
|
105
151
|
try:
|
|
106
|
-
loop = asyncio.
|
|
107
|
-
|
|
108
|
-
loop.create_task(self._async_client.aclose())
|
|
109
|
-
else:
|
|
110
|
-
loop.run_until_complete(self._async_client.aclose())
|
|
152
|
+
loop = asyncio.get_running_loop()
|
|
153
|
+
loop.create_task(self._async_client.aclose())
|
|
111
154
|
except RuntimeError:
|
|
112
|
-
|
|
155
|
+
asyncio.run(self._async_client.aclose())
|
|
113
156
|
|
|
114
157
|
def __enter__(self):
|
|
115
158
|
return self
|
|
@@ -18,6 +18,10 @@ class RateLimitError(AiUtilsError):
|
|
|
18
18
|
"""Too many requests — retry after the indicated delay."""
|
|
19
19
|
|
|
20
20
|
|
|
21
|
+
class ForbiddenError(AiUtilsError):
|
|
22
|
+
"""API key lacks required scopes for this endpoint."""
|
|
23
|
+
|
|
24
|
+
|
|
21
25
|
class APIError(AiUtilsError):
|
|
22
26
|
"""Generic API error with HTTP status code."""
|
|
23
27
|
|
|
@@ -27,4 +31,8 @@ class APIError(AiUtilsError):
|
|
|
27
31
|
|
|
28
32
|
|
|
29
33
|
class ProviderError(AiUtilsError):
|
|
30
|
-
"""The
|
|
34
|
+
"""The upstream AI provider returned an error (502/503)."""
|
|
35
|
+
|
|
36
|
+
def __init__(self, message: str, status_code: int = 502):
|
|
37
|
+
super().__init__(message)
|
|
38
|
+
self.status_code = status_code
|
|
@@ -27,13 +27,3 @@ class Files:
|
|
|
27
27
|
logger.debug("Entered into Files.list")
|
|
28
28
|
data = self._client._request("GET", "/v1/files")
|
|
29
29
|
return data.get("data", data.get("files", []))
|
|
30
|
-
|
|
31
|
-
def get(self, file_id: str) -> dict:
|
|
32
|
-
"""Get file metadata."""
|
|
33
|
-
logger.debug(f"Entered into Files.get: {file_id}")
|
|
34
|
-
return self._client._request("GET", f"/v1/files/{file_id}")
|
|
35
|
-
|
|
36
|
-
def delete(self, file_id: str) -> dict:
|
|
37
|
-
"""Delete a file."""
|
|
38
|
-
logger.debug(f"Entered into Files.delete: {file_id}")
|
|
39
|
-
return self._client._request("DELETE", f"/v1/files/{file_id}")
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""Referrals resource — referral program enrollment and claiming."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import logging
|
|
5
|
+
|
|
6
|
+
logger = logging.getLogger(__name__)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Referrals:
|
|
10
|
+
"""Referrals namespace — manage referral codes and claim rewards."""
|
|
11
|
+
|
|
12
|
+
def __init__(self, client):
|
|
13
|
+
self._client = client
|
|
14
|
+
|
|
15
|
+
def status(self) -> dict:
|
|
16
|
+
"""Get your referral code, stats, and earned credits."""
|
|
17
|
+
logger.debug("Entered into Referrals.status")
|
|
18
|
+
return self._client._request("GET", "/v1/referrals")
|
|
19
|
+
|
|
20
|
+
def enroll(self) -> dict:
|
|
21
|
+
"""Activate your referral program and get a shareable referral code.
|
|
22
|
+
|
|
23
|
+
Called once per developer. Returns the referral code and URL.
|
|
24
|
+
"""
|
|
25
|
+
logger.debug("Entered into Referrals.enroll")
|
|
26
|
+
return self._client._request("POST", "/v1/referrals/enroll")
|
|
27
|
+
|
|
28
|
+
def claim(self, referral_code: str) -> dict:
|
|
29
|
+
"""Claim referral credits using a referral code.
|
|
30
|
+
|
|
31
|
+
Awards DT to both the referrer and the new developer.
|
|
32
|
+
Idempotent — the same developer cannot claim the same code twice.
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
referral_code: The referral code to claim (format: AIUT-XXXXXXXX).
|
|
36
|
+
"""
|
|
37
|
+
logger.debug(f"Entered into Referrals.claim: code={referral_code}")
|
|
38
|
+
return self._client._request("POST", "/v1/referrals/claim", json={"referral_code": referral_code})
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""Teams resource — create teams, manage members, assign API keys."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import logging
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
logger = logging.getLogger(__name__)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Teams:
|
|
11
|
+
"""Teams namespace — manage developer teams and API key assignments."""
|
|
12
|
+
|
|
13
|
+
def __init__(self, client):
|
|
14
|
+
self._client = client
|
|
15
|
+
|
|
16
|
+
def create(self, name: str) -> dict:
|
|
17
|
+
"""Create a new team.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
name: Team name (1-255 characters).
|
|
21
|
+
"""
|
|
22
|
+
logger.debug(f"Entered into Teams.create: name={name}")
|
|
23
|
+
return self._client._request("POST", "/v1/teams", json={"name": name})
|
|
24
|
+
|
|
25
|
+
def list(self) -> dict:
|
|
26
|
+
"""List all teams the authenticated developer belongs to."""
|
|
27
|
+
logger.debug("Entered into Teams.list")
|
|
28
|
+
return self._client._request("GET", "/v1/teams")
|
|
29
|
+
|
|
30
|
+
def get(self, team_id: str) -> dict:
|
|
31
|
+
"""Get details of a specific team.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
team_id: The team's UUID.
|
|
35
|
+
"""
|
|
36
|
+
logger.debug(f"Entered into Teams.get: team_id={team_id}")
|
|
37
|
+
return self._client._request("GET", f"/v1/teams/{team_id}")
|
|
38
|
+
|
|
39
|
+
def add_member(
|
|
40
|
+
self,
|
|
41
|
+
team_id: str,
|
|
42
|
+
developer_id: str,
|
|
43
|
+
role: str = "member",
|
|
44
|
+
) -> dict:
|
|
45
|
+
"""Add a developer to a team.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
team_id: The team's UUID.
|
|
49
|
+
developer_id: The developer's UUID to add.
|
|
50
|
+
role: One of 'admin', 'member', 'viewer'. Default: 'member'.
|
|
51
|
+
"""
|
|
52
|
+
logger.debug(f"Entered into Teams.add_member: team={team_id}, dev={developer_id}")
|
|
53
|
+
return self._client._request("POST", f"/v1/teams/{team_id}/members", json={
|
|
54
|
+
"developer_id": developer_id,
|
|
55
|
+
"role": role,
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
def remove_member(self, team_id: str, developer_id: str) -> dict:
|
|
59
|
+
"""Remove a developer from a team.
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
team_id: The team's UUID.
|
|
63
|
+
developer_id: The developer's UUID to remove.
|
|
64
|
+
"""
|
|
65
|
+
logger.debug(f"Entered into Teams.remove_member: team={team_id}, dev={developer_id}")
|
|
66
|
+
return self._client._request("DELETE", f"/v1/teams/{team_id}/members/{developer_id}")
|
|
67
|
+
|
|
68
|
+
def assign_key(self, key_id: str, team_id: Optional[str] = None) -> dict:
|
|
69
|
+
"""Assign an API key to a team.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
key_id: The API key's UUID.
|
|
73
|
+
team_id: The team's UUID. If None, unassigns the key from any team.
|
|
74
|
+
"""
|
|
75
|
+
logger.debug(f"Entered into Teams.assign_key: key={key_id}, team={team_id}")
|
|
76
|
+
body: dict = {"key_id": key_id}
|
|
77
|
+
if team_id is not None:
|
|
78
|
+
body["team_id"] = team_id
|
|
79
|
+
return self._client._request("POST", "/v1/teams/assign-key", json=body)
|
|
80
|
+
|
|
81
|
+
def list_keys(self, team_id: str) -> dict:
|
|
82
|
+
"""List API keys assigned to a team.
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
team_id: The team's UUID.
|
|
86
|
+
"""
|
|
87
|
+
logger.debug(f"Entered into Teams.list_keys: team_id={team_id}")
|
|
88
|
+
return self._client._request("GET", f"/v1/teams/{team_id}/keys")
|
|
@@ -20,7 +20,7 @@ class Tools:
|
|
|
20
20
|
def execute(self, tool_slug: str, **params) -> dict:
|
|
21
21
|
"""Execute a portal tool by slug."""
|
|
22
22
|
logger.debug(f"Entered into Tools.execute: {tool_slug}")
|
|
23
|
-
return self._client._request("POST", f"/v1/tools/{tool_slug}/execute", json=params)
|
|
23
|
+
return self._client._request("POST", f"/v1/tools/{tool_slug}/execute", json={"inputs": params})
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
class Batch:
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""Usage & analytics resource — request history, per-key audit, analytics."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import logging
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
logger = logging.getLogger(__name__)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Usage:
|
|
11
|
+
"""Usage namespace — request history and analytics dashboards."""
|
|
12
|
+
|
|
13
|
+
def __init__(self, client):
|
|
14
|
+
self._client = client
|
|
15
|
+
|
|
16
|
+
def requests(
|
|
17
|
+
self,
|
|
18
|
+
limit: int = 20,
|
|
19
|
+
model: Optional[str] = None,
|
|
20
|
+
status: Optional[str] = None,
|
|
21
|
+
after: Optional[str] = None,
|
|
22
|
+
) -> dict:
|
|
23
|
+
"""Get paginated request history.
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
limit: Max items per page (1-100, default 20).
|
|
27
|
+
model: Filter by model name.
|
|
28
|
+
status: Filter by outcome — 'success' or 'error'.
|
|
29
|
+
after: Cursor for pagination (created_at of last item).
|
|
30
|
+
"""
|
|
31
|
+
logger.debug(f"Entered into Usage.requests: limit={limit}, model={model}")
|
|
32
|
+
params: dict = {"limit": limit}
|
|
33
|
+
if model:
|
|
34
|
+
params["model"] = model
|
|
35
|
+
if status:
|
|
36
|
+
params["status"] = status
|
|
37
|
+
if after:
|
|
38
|
+
params["after"] = after
|
|
39
|
+
return self._client._request("GET", "/v1/usage/requests", params=params)
|
|
40
|
+
|
|
41
|
+
def by_key(self, days: int = 30) -> dict:
|
|
42
|
+
"""Get per-API-key usage breakdown for audit purposes.
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
days: Look-back window in days (1-365, default 30).
|
|
46
|
+
"""
|
|
47
|
+
logger.debug(f"Entered into Usage.by_key: days={days}")
|
|
48
|
+
return self._client._request("GET", "/v1/usage/by-key", params={"days": days})
|
|
49
|
+
|
|
50
|
+
def analytics_daily(self, days: int = 30) -> dict:
|
|
51
|
+
"""Get daily DT usage time series.
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
days: Look-back window in days (1-365, default 30).
|
|
55
|
+
"""
|
|
56
|
+
logger.debug(f"Entered into Usage.analytics_daily: days={days}")
|
|
57
|
+
return self._client._request("GET", "/v1/usage/analytics/daily", params={"days": days})
|
|
58
|
+
|
|
59
|
+
def analytics_by_model(self, days: int = 30) -> dict:
|
|
60
|
+
"""Get DT spending breakdown by model.
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
days: Look-back window in days (1-365, default 30).
|
|
64
|
+
"""
|
|
65
|
+
logger.debug(f"Entered into Usage.analytics_by_model: days={days}")
|
|
66
|
+
return self._client._request("GET", "/v1/usage/analytics/by-model", params={"days": days})
|
|
67
|
+
|
|
68
|
+
def analytics_by_provider(self, days: int = 30) -> dict:
|
|
69
|
+
"""Get DT spending breakdown by provider.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
days: Look-back window in days (1-365, default 30).
|
|
73
|
+
"""
|
|
74
|
+
logger.debug(f"Entered into Usage.analytics_by_provider: days={days}")
|
|
75
|
+
return self._client._request("GET", "/v1/usage/analytics/by-provider", params={"days": days})
|
|
76
|
+
|
|
77
|
+
def analytics_top_endpoints(self, days: int = 30, limit: int = 10) -> dict:
|
|
78
|
+
"""Get top API endpoints by request volume.
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
days: Look-back window in days (1-365, default 30).
|
|
82
|
+
limit: Number of top endpoints to return (1-50, default 10).
|
|
83
|
+
"""
|
|
84
|
+
logger.debug(f"Entered into Usage.analytics_top_endpoints: days={days}, limit={limit}")
|
|
85
|
+
return self._client._request("GET", "/v1/usage/analytics/top-endpoints", params={"days": days, "limit": limit})
|