aiutils-sdk 0.3.0__tar.gz → 0.3.1__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-0.3.1}/PKG-INFO +74 -2
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.3.1}/README.md +73 -1
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.3.1}/aiutils_sdk/__init__.py +3 -3
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.3.1}/aiutils_sdk/client.py +46 -14
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.3.1}/aiutils_sdk/exceptions.py +4 -0
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.3.1}/aiutils_sdk/files.py +0 -10
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.3.1}/aiutils_sdk/tools_and_batch.py +1 -1
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.3.1}/aiutils_sdk/wallet.py +9 -9
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.3.1}/aiutils_sdk.egg-info/PKG-INFO +74 -2
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.3.1}/aiutils_sdk.egg-info/SOURCES.txt +0 -1
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.3.1}/pyproject.toml +1 -1
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.3.1}/tests/test_sdk.py +69 -0
- aiutils_sdk-0.3.0/aiutils_sdk/research.py +0 -101
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.3.1}/aiutils_sdk/chat.py +0 -0
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.3.1}/aiutils_sdk/embeddings.py +0 -0
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.3.1}/aiutils_sdk/generations.py +0 -0
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.3.1}/aiutils_sdk/images.py +0 -0
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.3.1}/aiutils_sdk/models.py +0 -0
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.3.1}/aiutils_sdk/webhooks.py +0 -0
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.3.1}/aiutils_sdk.egg-info/dependency_links.txt +0 -0
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.3.1}/aiutils_sdk.egg-info/requires.txt +0 -0
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.3.1}/aiutils_sdk.egg-info/top_level.txt +0 -0
- {aiutils_sdk-0.3.0 → aiutils_sdk-0.3.1}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: aiutils-sdk
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.1
|
|
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
|
|
@@ -17,7 +17,7 @@ Requires-Dist: pydantic>=2.0
|
|
|
17
17
|
|
|
18
18
|
# AiUtils Python SDK
|
|
19
19
|
|
|
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.
|
|
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. **v0.3.0**
|
|
21
21
|
|
|
22
22
|
## Install
|
|
23
23
|
|
|
@@ -388,6 +388,78 @@ with AiUtils(api_key="ak-dev-YOUR_KEY") as client:
|
|
|
388
388
|
|
|
389
389
|
---
|
|
390
390
|
|
|
391
|
+
## Billing
|
|
392
|
+
|
|
393
|
+
Purchase DT packs and view invoices.
|
|
394
|
+
|
|
395
|
+
```python
|
|
396
|
+
# List available DT packs
|
|
397
|
+
packs = client.billing.list_packs()
|
|
398
|
+
for p in packs:
|
|
399
|
+
print(f"{p['name']}: {p['dt_amount']} DT for ${p['price_usd']}")
|
|
400
|
+
|
|
401
|
+
# Create checkout session
|
|
402
|
+
checkout = client.billing.checkout(pack_slug="pack_10k")
|
|
403
|
+
print(checkout) # Checkout session created
|
|
404
|
+
|
|
405
|
+
# View invoice (returns PDF bytes)
|
|
406
|
+
invoice_bytes = client.billing.get_invoice(transaction_id="txn_abc123")
|
|
407
|
+
with open("invoice.pdf", "wb") as f:
|
|
408
|
+
f.write(invoice_bytes)
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
## File Upload
|
|
412
|
+
|
|
413
|
+
Upload images for vision analysis in chat completions.
|
|
414
|
+
|
|
415
|
+
```python
|
|
416
|
+
# Upload an image
|
|
417
|
+
file = client.files.upload("photo.jpg")
|
|
418
|
+
|
|
419
|
+
# List uploaded files
|
|
420
|
+
files = client.files.list()
|
|
421
|
+
for f in files:
|
|
422
|
+
print(f"{f['id']}: {f['filename']}")
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
## Portal Tools
|
|
426
|
+
|
|
427
|
+
Access 147+ built-in AI tools — email, calendar, database, browser, and more.
|
|
428
|
+
|
|
429
|
+
```python
|
|
430
|
+
# List tool categories
|
|
431
|
+
genres = client.tools.genres()
|
|
432
|
+
|
|
433
|
+
# Execute a tool
|
|
434
|
+
result = client.tools.execute(
|
|
435
|
+
tool_slug="email-send",
|
|
436
|
+
to="user@example.com",
|
|
437
|
+
subject="Hello",
|
|
438
|
+
body="Test email"
|
|
439
|
+
)
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
## Batch Requests
|
|
443
|
+
|
|
444
|
+
Submit multiple requests in one API call.
|
|
445
|
+
|
|
446
|
+
```python
|
|
447
|
+
# Create a batch
|
|
448
|
+
batch = client.batch.create(requests=[
|
|
449
|
+
{"method": "POST", "path": "/v1/chat/completions", "body": {
|
|
450
|
+
"model": "gen:deepseek:deepseek-v4-flash",
|
|
451
|
+
"messages": [{"role": "user", "content": "Hi"}]
|
|
452
|
+
}},
|
|
453
|
+
{"method": "POST", "path": "/v1/chat/completions", "body": {
|
|
454
|
+
"model": "gen:anthropic:claude-haiku-4-5",
|
|
455
|
+
"messages": [{"role": "user", "content": "Hello"}]
|
|
456
|
+
}},
|
|
457
|
+
])
|
|
458
|
+
|
|
459
|
+
# Check batch status
|
|
460
|
+
status = client.batch.status(batch_id=batch["batch_id"])
|
|
461
|
+
```
|
|
462
|
+
|
|
391
463
|
## Links
|
|
392
464
|
|
|
393
465
|
- [Developer Console](https://developer.aiutils.io)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# AiUtils Python SDK
|
|
2
2
|
|
|
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.
|
|
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.0**
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -371,6 +371,78 @@ with AiUtils(api_key="ak-dev-YOUR_KEY") as client:
|
|
|
371
371
|
|
|
372
372
|
---
|
|
373
373
|
|
|
374
|
+
## Billing
|
|
375
|
+
|
|
376
|
+
Purchase DT packs and view invoices.
|
|
377
|
+
|
|
378
|
+
```python
|
|
379
|
+
# List available DT packs
|
|
380
|
+
packs = client.billing.list_packs()
|
|
381
|
+
for p in packs:
|
|
382
|
+
print(f"{p['name']}: {p['dt_amount']} DT for ${p['price_usd']}")
|
|
383
|
+
|
|
384
|
+
# Create checkout session
|
|
385
|
+
checkout = client.billing.checkout(pack_slug="pack_10k")
|
|
386
|
+
print(checkout) # Checkout session created
|
|
387
|
+
|
|
388
|
+
# View invoice (returns PDF bytes)
|
|
389
|
+
invoice_bytes = client.billing.get_invoice(transaction_id="txn_abc123")
|
|
390
|
+
with open("invoice.pdf", "wb") as f:
|
|
391
|
+
f.write(invoice_bytes)
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
## File Upload
|
|
395
|
+
|
|
396
|
+
Upload images for vision analysis in chat completions.
|
|
397
|
+
|
|
398
|
+
```python
|
|
399
|
+
# Upload an image
|
|
400
|
+
file = client.files.upload("photo.jpg")
|
|
401
|
+
|
|
402
|
+
# List uploaded files
|
|
403
|
+
files = client.files.list()
|
|
404
|
+
for f in files:
|
|
405
|
+
print(f"{f['id']}: {f['filename']}")
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
## Portal Tools
|
|
409
|
+
|
|
410
|
+
Access 147+ built-in AI tools — email, calendar, database, browser, and more.
|
|
411
|
+
|
|
412
|
+
```python
|
|
413
|
+
# List tool categories
|
|
414
|
+
genres = client.tools.genres()
|
|
415
|
+
|
|
416
|
+
# Execute a tool
|
|
417
|
+
result = client.tools.execute(
|
|
418
|
+
tool_slug="email-send",
|
|
419
|
+
to="user@example.com",
|
|
420
|
+
subject="Hello",
|
|
421
|
+
body="Test email"
|
|
422
|
+
)
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
## Batch Requests
|
|
426
|
+
|
|
427
|
+
Submit multiple requests in one API call.
|
|
428
|
+
|
|
429
|
+
```python
|
|
430
|
+
# Create a batch
|
|
431
|
+
batch = client.batch.create(requests=[
|
|
432
|
+
{"method": "POST", "path": "/v1/chat/completions", "body": {
|
|
433
|
+
"model": "gen:deepseek:deepseek-v4-flash",
|
|
434
|
+
"messages": [{"role": "user", "content": "Hi"}]
|
|
435
|
+
}},
|
|
436
|
+
{"method": "POST", "path": "/v1/chat/completions", "body": {
|
|
437
|
+
"model": "gen:anthropic:claude-haiku-4-5",
|
|
438
|
+
"messages": [{"role": "user", "content": "Hello"}]
|
|
439
|
+
}},
|
|
440
|
+
])
|
|
441
|
+
|
|
442
|
+
# Check batch status
|
|
443
|
+
status = client.batch.status(batch_id=batch["batch_id"])
|
|
444
|
+
```
|
|
445
|
+
|
|
374
446
|
## Links
|
|
375
447
|
|
|
376
448
|
- [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.3.
|
|
9
|
+
__version__ = "0.3.1"
|
|
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,7 +11,6 @@ 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
|
|
@@ -54,7 +53,6 @@ class AiUtils:
|
|
|
54
53
|
self.embeddings = Embeddings(self)
|
|
55
54
|
self.generations = Generations(self)
|
|
56
55
|
self.models = Models(self)
|
|
57
|
-
self.research = Research(self)
|
|
58
56
|
self.wallet = Wallet(self)
|
|
59
57
|
self.webhooks = Webhooks(self)
|
|
60
58
|
self.billing = Billing(self)
|
|
@@ -62,39 +60,73 @@ class AiUtils:
|
|
|
62
60
|
self.tools = Tools(self)
|
|
63
61
|
self.batch = Batch(self)
|
|
64
62
|
|
|
65
|
-
def _request(self, method: str, path: str, **kwargs) -> dict:
|
|
66
|
-
"""Make a synchronous HTTP request.
|
|
63
|
+
def _request(self, method: str, path: str, raw: bool = False, **kwargs) -> dict | bytes:
|
|
64
|
+
"""Make a synchronous HTTP request.
|
|
65
|
+
|
|
66
|
+
Args:
|
|
67
|
+
raw: If True, return the raw response body (bytes) instead of
|
|
68
|
+
parsing JSON. Used for binary endpoints such as PDF invoices.
|
|
69
|
+
"""
|
|
67
70
|
url = f"{self.base_url}{path}"
|
|
68
71
|
logger.debug(f"Entered into _request: {method} {path}")
|
|
69
|
-
response = self._client.request(method, url, headers=self.
|
|
70
|
-
return self._handle_response(response)
|
|
72
|
+
response = self._client.request(method, url, headers=self._request_headers(kwargs), **kwargs)
|
|
73
|
+
return self._handle_response(response, raw=raw)
|
|
74
|
+
|
|
75
|
+
async def _request_async(self, method: str, path: str, raw: bool = False, **kwargs) -> dict | bytes:
|
|
76
|
+
"""Make an async HTTP request.
|
|
71
77
|
|
|
72
|
-
|
|
73
|
-
|
|
78
|
+
Args:
|
|
79
|
+
raw: If True, return the raw response body (bytes) instead of
|
|
80
|
+
parsing JSON. Used for binary endpoints such as PDF invoices.
|
|
81
|
+
"""
|
|
74
82
|
url = f"{self.base_url}{path}"
|
|
75
83
|
logger.debug(f"Entered into _request_async: {method} {path}")
|
|
76
84
|
if self._async_client is None:
|
|
77
85
|
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)
|
|
86
|
+
response = await self._async_client.request(method, url, headers=self._request_headers(kwargs), **kwargs)
|
|
87
|
+
return self._handle_response(response, raw=raw)
|
|
88
|
+
|
|
89
|
+
def _request_headers(self, kwargs: dict) -> dict:
|
|
90
|
+
"""Build request headers.
|
|
80
91
|
|
|
81
|
-
|
|
92
|
+
For multipart uploads (files=), the hardcoded JSON Content-Type must be
|
|
93
|
+
dropped so httpx can set the correct ``multipart/form-data`` header
|
|
94
|
+
with its generated boundary; otherwise the server rejects the body.
|
|
95
|
+
"""
|
|
96
|
+
if kwargs.get("files"):
|
|
97
|
+
return {k: v for k, v in self._headers.items() if k.lower() != "content-type"}
|
|
98
|
+
return self._headers
|
|
99
|
+
|
|
100
|
+
def _handle_response(self, response: httpx.Response, raw: bool = False) -> dict | bytes:
|
|
82
101
|
"""Parse response and raise appropriate errors."""
|
|
83
102
|
if response.status_code == 401:
|
|
84
103
|
raise AuthenticationError("Invalid or expired API key")
|
|
85
104
|
if response.status_code == 429:
|
|
86
105
|
from aiutils_sdk.exceptions import RateLimitError
|
|
87
|
-
retry_after = response.headers.get("
|
|
106
|
+
retry_after = response.headers.get("Retry-After", "60")
|
|
88
107
|
raise RateLimitError(f"Rate limit exceeded. Retry after {retry_after}s")
|
|
108
|
+
if response.status_code == 403:
|
|
109
|
+
from aiutils_sdk.exceptions import ForbiddenError
|
|
110
|
+
raise ForbiddenError(response.text[:500] or "Access forbidden — check your API key scopes")
|
|
89
111
|
if response.status_code == 402:
|
|
90
112
|
from aiutils_sdk.exceptions import InsufficientDTError
|
|
91
|
-
|
|
113
|
+
try:
|
|
114
|
+
detail = response.json().get("detail", "Insufficient DT balance")
|
|
115
|
+
except Exception:
|
|
116
|
+
detail = response.text[:500] or "Insufficient DT balance"
|
|
92
117
|
raise InsufficientDTError(detail)
|
|
93
118
|
if response.status_code >= 400:
|
|
119
|
+
try:
|
|
120
|
+
body = response.json()
|
|
121
|
+
detail = body.get("detail") or body.get("error", {}).get("message", str(body))
|
|
122
|
+
except Exception:
|
|
123
|
+
detail = response.text[:500]
|
|
94
124
|
raise APIError(
|
|
95
|
-
|
|
125
|
+
detail,
|
|
96
126
|
status_code=response.status_code,
|
|
97
127
|
)
|
|
128
|
+
if raw:
|
|
129
|
+
return response.content
|
|
98
130
|
return response.json()
|
|
99
131
|
|
|
100
132
|
def close(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,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}")
|
|
@@ -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:
|
|
@@ -105,10 +105,10 @@ class Wallet:
|
|
|
105
105
|
return PricingEstimate(**data)
|
|
106
106
|
|
|
107
107
|
|
|
108
|
-
def set_alert_threshold(self,
|
|
109
|
-
"""Set low balance alert threshold."""
|
|
108
|
+
def set_alert_threshold(self, threshold_dt: int) -> dict:
|
|
109
|
+
"""Set low balance alert threshold in DT. Pass 0 to disable alerts."""
|
|
110
110
|
logger.debug("Entered into Wallet.set_alert_threshold")
|
|
111
|
-
return self._client._request("POST", "/v1/wallet/alert-threshold", json={"
|
|
111
|
+
return self._client._request("POST", "/v1/wallet/alert-threshold", json={"threshold_dt": threshold_dt})
|
|
112
112
|
|
|
113
113
|
|
|
114
114
|
class Billing:
|
|
@@ -123,12 +123,12 @@ class Billing:
|
|
|
123
123
|
data = self._client._request("GET", "/v1/billing/packs")
|
|
124
124
|
return data.get("packs", data.get("data", []))
|
|
125
125
|
|
|
126
|
-
def checkout(self,
|
|
127
|
-
"""Create a checkout session for a DT pack."""
|
|
126
|
+
def checkout(self, pack_slug: str) -> dict:
|
|
127
|
+
"""Create a checkout session for a DT pack (e.g. "pack-20000")."""
|
|
128
128
|
logger.debug("Entered into Billing.checkout")
|
|
129
|
-
return self._client._request("POST", "/v1/billing/checkout", json={"
|
|
129
|
+
return self._client._request("POST", "/v1/billing/checkout", json={"pack_slug": pack_slug})
|
|
130
130
|
|
|
131
|
-
def get_invoice(self, transaction_id: str) ->
|
|
132
|
-
"""
|
|
131
|
+
def get_invoice(self, transaction_id: str) -> bytes:
|
|
132
|
+
"""Download the PDF invoice for a billing transaction (raw bytes)."""
|
|
133
133
|
logger.debug("Entered into Billing.get_invoice")
|
|
134
|
-
return self._client._request("GET", f"/v1/billing/invoice/{transaction_id}")
|
|
134
|
+
return self._client._request("GET", f"/v1/billing/invoice/{transaction_id}", raw=True)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: aiutils-sdk
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.1
|
|
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
|
|
@@ -17,7 +17,7 @@ Requires-Dist: pydantic>=2.0
|
|
|
17
17
|
|
|
18
18
|
# AiUtils Python SDK
|
|
19
19
|
|
|
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.
|
|
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. **v0.3.0**
|
|
21
21
|
|
|
22
22
|
## Install
|
|
23
23
|
|
|
@@ -388,6 +388,78 @@ with AiUtils(api_key="ak-dev-YOUR_KEY") as client:
|
|
|
388
388
|
|
|
389
389
|
---
|
|
390
390
|
|
|
391
|
+
## Billing
|
|
392
|
+
|
|
393
|
+
Purchase DT packs and view invoices.
|
|
394
|
+
|
|
395
|
+
```python
|
|
396
|
+
# List available DT packs
|
|
397
|
+
packs = client.billing.list_packs()
|
|
398
|
+
for p in packs:
|
|
399
|
+
print(f"{p['name']}: {p['dt_amount']} DT for ${p['price_usd']}")
|
|
400
|
+
|
|
401
|
+
# Create checkout session
|
|
402
|
+
checkout = client.billing.checkout(pack_slug="pack_10k")
|
|
403
|
+
print(checkout) # Checkout session created
|
|
404
|
+
|
|
405
|
+
# View invoice (returns PDF bytes)
|
|
406
|
+
invoice_bytes = client.billing.get_invoice(transaction_id="txn_abc123")
|
|
407
|
+
with open("invoice.pdf", "wb") as f:
|
|
408
|
+
f.write(invoice_bytes)
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
## File Upload
|
|
412
|
+
|
|
413
|
+
Upload images for vision analysis in chat completions.
|
|
414
|
+
|
|
415
|
+
```python
|
|
416
|
+
# Upload an image
|
|
417
|
+
file = client.files.upload("photo.jpg")
|
|
418
|
+
|
|
419
|
+
# List uploaded files
|
|
420
|
+
files = client.files.list()
|
|
421
|
+
for f in files:
|
|
422
|
+
print(f"{f['id']}: {f['filename']}")
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
## Portal Tools
|
|
426
|
+
|
|
427
|
+
Access 147+ built-in AI tools — email, calendar, database, browser, and more.
|
|
428
|
+
|
|
429
|
+
```python
|
|
430
|
+
# List tool categories
|
|
431
|
+
genres = client.tools.genres()
|
|
432
|
+
|
|
433
|
+
# Execute a tool
|
|
434
|
+
result = client.tools.execute(
|
|
435
|
+
tool_slug="email-send",
|
|
436
|
+
to="user@example.com",
|
|
437
|
+
subject="Hello",
|
|
438
|
+
body="Test email"
|
|
439
|
+
)
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
## Batch Requests
|
|
443
|
+
|
|
444
|
+
Submit multiple requests in one API call.
|
|
445
|
+
|
|
446
|
+
```python
|
|
447
|
+
# Create a batch
|
|
448
|
+
batch = client.batch.create(requests=[
|
|
449
|
+
{"method": "POST", "path": "/v1/chat/completions", "body": {
|
|
450
|
+
"model": "gen:deepseek:deepseek-v4-flash",
|
|
451
|
+
"messages": [{"role": "user", "content": "Hi"}]
|
|
452
|
+
}},
|
|
453
|
+
{"method": "POST", "path": "/v1/chat/completions", "body": {
|
|
454
|
+
"model": "gen:anthropic:claude-haiku-4-5",
|
|
455
|
+
"messages": [{"role": "user", "content": "Hello"}]
|
|
456
|
+
}},
|
|
457
|
+
])
|
|
458
|
+
|
|
459
|
+
# Check batch status
|
|
460
|
+
status = client.batch.status(batch_id=batch["batch_id"])
|
|
461
|
+
```
|
|
462
|
+
|
|
391
463
|
## Links
|
|
392
464
|
|
|
393
465
|
- [Developer Console](https://developer.aiutils.io)
|
|
@@ -464,3 +464,72 @@ class TestDtCosting:
|
|
|
464
464
|
wait_for_completion=False,
|
|
465
465
|
)
|
|
466
466
|
assert resp.dt_reserved == 50
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
# ── Files / Billing / Alert Threshold (AIUT-2308, 2309, 2310, 2312) ──
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
class TestFilesAndBilling:
|
|
473
|
+
@patch.object(httpx.Client, "request")
|
|
474
|
+
def test_file_upload_uses_multipart_content_type(self, mock_req, client, mock_response, tmp_path):
|
|
475
|
+
"""AIUT-2308: multipart upload must not send hardcoded application/json."""
|
|
476
|
+
f = tmp_path / "test.png"
|
|
477
|
+
f.write_bytes(b"\x89PNG\r\n\x1a\n fake png bytes")
|
|
478
|
+
mock_req.return_value = mock_response(200, {
|
|
479
|
+
"id": "file-1", "url": "https://cdn.aiutils.io/f.png",
|
|
480
|
+
"content_type": "image/png", "width": 100, "height": 100,
|
|
481
|
+
"size_bytes": 16, "dt_consumed": 1,
|
|
482
|
+
})
|
|
483
|
+
|
|
484
|
+
result = client.files.upload(str(f))
|
|
485
|
+
|
|
486
|
+
call_kwargs = mock_req.call_args
|
|
487
|
+
headers = call_kwargs.kwargs["headers"]
|
|
488
|
+
assert "Content-Type" not in headers
|
|
489
|
+
assert "files" in call_kwargs.kwargs
|
|
490
|
+
assert result["id"] == "file-1"
|
|
491
|
+
|
|
492
|
+
@patch.object(httpx.Client, "request")
|
|
493
|
+
def test_checkout_sends_pack_slug(self, mock_req, client, mock_response):
|
|
494
|
+
"""AIUT-2309: checkout body must use pack_slug, not pack_id."""
|
|
495
|
+
mock_req.return_value = mock_response(200, {
|
|
496
|
+
"checkout_id": "dev_dt_abc", "pack_slug": "pack-20000",
|
|
497
|
+
"dt_amount": 20000, "status": "pending",
|
|
498
|
+
})
|
|
499
|
+
|
|
500
|
+
result = client.billing.checkout("pack-20000")
|
|
501
|
+
|
|
502
|
+
body = mock_req.call_args.kwargs["json"]
|
|
503
|
+
assert body["pack_slug"] == "pack-20000"
|
|
504
|
+
assert "pack_id" not in body
|
|
505
|
+
assert result["pack_slug"] == "pack-20000"
|
|
506
|
+
|
|
507
|
+
def test_get_invoice_returns_raw_pdf_bytes(self, client):
|
|
508
|
+
"""AIUT-2310: invoice endpoint returns a PDF; SDK must return bytes, not parse JSON."""
|
|
509
|
+
pdf_bytes = b"%PDF-1.4\n%fake-invoice\n"
|
|
510
|
+
resp = MagicMock(spec=httpx.Response)
|
|
511
|
+
resp.status_code = 200
|
|
512
|
+
resp.text = ""
|
|
513
|
+
resp.headers = {}
|
|
514
|
+
resp.content = pdf_bytes
|
|
515
|
+
resp.json.side_effect = lambda: (_ for _ in ()).throw(AssertionError("json() must not be called for PDF"))
|
|
516
|
+
client._client = MagicMock()
|
|
517
|
+
client._client.request.return_value = resp
|
|
518
|
+
|
|
519
|
+
result = client.billing.get_invoice("tx-123")
|
|
520
|
+
|
|
521
|
+
assert result == pdf_bytes
|
|
522
|
+
url = client._client.request.call_args.args[1]
|
|
523
|
+
assert url.endswith("/v1/billing/invoice/tx-123")
|
|
524
|
+
|
|
525
|
+
@patch.object(httpx.Client, "request")
|
|
526
|
+
def test_set_alert_threshold_sends_threshold_dt(self, mock_req, client, mock_response):
|
|
527
|
+
"""AIUT-2312: alert threshold body must use threshold_dt, not low_balance_dt."""
|
|
528
|
+
mock_req.return_value = mock_response(200, {"status": "updated", "threshold_dt": 1000})
|
|
529
|
+
|
|
530
|
+
result = client.wallet.set_alert_threshold(1000)
|
|
531
|
+
|
|
532
|
+
body = mock_req.call_args.kwargs["json"]
|
|
533
|
+
assert body["threshold_dt"] == 1000
|
|
534
|
+
assert "low_balance_dt" not in body
|
|
535
|
+
assert result["status"] == "updated"
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"""AiUtils SDK — Research endpoints (v1 YOYO + v2 HARNESS)."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
import logging
|
|
6
|
-
from typing import Any, Dict, List, Optional
|
|
7
|
-
|
|
8
|
-
logger = logging.getLogger(__name__)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class Research:
|
|
12
|
-
"""Research API client.
|
|
13
|
-
|
|
14
|
-
Args:
|
|
15
|
-
client: The AiUtils client instance.
|
|
16
|
-
"""
|
|
17
|
-
|
|
18
|
-
def __init__(self, client) -> None:
|
|
19
|
-
logger.debug("Entered into Research.__init__")
|
|
20
|
-
self._client = client
|
|
21
|
-
|
|
22
|
-
def run(
|
|
23
|
-
self,
|
|
24
|
-
*,
|
|
25
|
-
prompt: str,
|
|
26
|
-
thinking_level: str = "medium",
|
|
27
|
-
model_vendor: Optional[str] = None,
|
|
28
|
-
model_name: Optional[str] = None,
|
|
29
|
-
) -> Dict[str, Any]:
|
|
30
|
-
"""Run YOYO multi-agent deep research (v1)."""
|
|
31
|
-
logger.debug(f"Entered into Research.run: prompt={prompt[:60]!r}")
|
|
32
|
-
body: Dict[str, Any] = {"prompt": prompt, "thinking_level": thinking_level}
|
|
33
|
-
if model_vendor:
|
|
34
|
-
body["model_vendor"] = model_vendor
|
|
35
|
-
if model_name:
|
|
36
|
-
body["model_name"] = model_name
|
|
37
|
-
return self._client._request("POST", "/v1/research/run", json=body)
|
|
38
|
-
|
|
39
|
-
def run_v2(
|
|
40
|
-
self,
|
|
41
|
-
*,
|
|
42
|
-
prompt: str,
|
|
43
|
-
thinking_level: str = "medium",
|
|
44
|
-
domains: Optional[List[str]] = None,
|
|
45
|
-
max_agents: int = 5,
|
|
46
|
-
max_credits: float = 500.0,
|
|
47
|
-
model_vendor: Optional[str] = None,
|
|
48
|
-
model_name: Optional[str] = None,
|
|
49
|
-
) -> Dict[str, Any]:
|
|
50
|
-
"""Run collaborative multi-model research (v2 HARNESS)."""
|
|
51
|
-
logger.debug(f"Entered into Research.run_v2: prompt={prompt[:60]!r}")
|
|
52
|
-
body: Dict[str, Any] = {
|
|
53
|
-
"prompt": prompt,
|
|
54
|
-
"thinking_level": thinking_level,
|
|
55
|
-
"max_agents": max_agents,
|
|
56
|
-
"max_credits": max_credits,
|
|
57
|
-
}
|
|
58
|
-
if domains:
|
|
59
|
-
body["domains"] = domains
|
|
60
|
-
if model_vendor:
|
|
61
|
-
body["model_vendor"] = model_vendor
|
|
62
|
-
if model_name:
|
|
63
|
-
body["model_name"] = model_name
|
|
64
|
-
return self._client._request("POST", "/v1/research-v2", json=body)
|
|
65
|
-
|
|
66
|
-
def estimate_v2(
|
|
67
|
-
self,
|
|
68
|
-
*,
|
|
69
|
-
prompt: str,
|
|
70
|
-
thinking_level: str = "medium",
|
|
71
|
-
domains: Optional[List[str]] = None,
|
|
72
|
-
max_agents: int = 5,
|
|
73
|
-
) -> Dict[str, Any]:
|
|
74
|
-
"""Estimate credits for collaborative research."""
|
|
75
|
-
logger.debug(f"Entered into Research.estimate_v2: prompt={prompt[:60]!r}")
|
|
76
|
-
body: Dict[str, Any] = {
|
|
77
|
-
"prompt": prompt,
|
|
78
|
-
"thinking_level": thinking_level,
|
|
79
|
-
"max_agents": max_agents,
|
|
80
|
-
}
|
|
81
|
-
if domains:
|
|
82
|
-
body["domains"] = domains
|
|
83
|
-
return self._client._request("POST", "/v1/research-v2/estimate", json=body)
|
|
84
|
-
|
|
85
|
-
@staticmethod
|
|
86
|
-
def list_domains() -> List[Dict[str, str]]:
|
|
87
|
-
"""List all available research domains."""
|
|
88
|
-
return [
|
|
89
|
-
{"key": "pharma_research", "label": "Pharma Research", "primary_model": "claude-opus-5"},
|
|
90
|
-
{"key": "medical_research", "label": "Medical Research", "primary_model": "claude-sonnet-5"},
|
|
91
|
-
{"key": "business_enterprise", "label": "Business & Enterprise", "primary_model": "claude-sonnet-5"},
|
|
92
|
-
{"key": "legal_compliance", "label": "Legal & Compliance", "primary_model": "claude-opus-5"},
|
|
93
|
-
{"key": "seo_research", "label": "SEO Research", "primary_model": "deepseek-chat"},
|
|
94
|
-
{"key": "marketing_research", "label": "Marketing Research", "primary_model": "claude-sonnet-5"},
|
|
95
|
-
{"key": "product_research", "label": "Product Research", "primary_model": "claude-sonnet-5"},
|
|
96
|
-
{"key": "knowledge_research", "label": "Knowledge Research", "primary_model": "deepseek-reasoner"},
|
|
97
|
-
{"key": "idea_research", "label": "Idea Research", "primary_model": "claude-sonnet-5"},
|
|
98
|
-
{"key": "ads_research", "label": "Ads Research", "primary_model": "deepseek-chat"},
|
|
99
|
-
{"key": "technical_design", "label": "Technical Design", "primary_model": "claude-opus-5"},
|
|
100
|
-
{"key": "scientific_research", "label": "Scientific Research", "primary_model": "claude-opus-5"},
|
|
101
|
-
]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|