aiutils-sdk 0.2.3__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.2.3 → aiutils_sdk-0.3.1}/PKG-INFO +74 -2
- {aiutils_sdk-0.2.3 → aiutils_sdk-0.3.1}/README.md +73 -1
- {aiutils_sdk-0.2.3 → aiutils_sdk-0.3.1}/aiutils_sdk/__init__.py +3 -3
- {aiutils_sdk-0.2.3 → aiutils_sdk-0.3.1}/aiutils_sdk/client.py +53 -15
- {aiutils_sdk-0.2.3 → aiutils_sdk-0.3.1}/aiutils_sdk/exceptions.py +4 -0
- aiutils_sdk-0.3.1/aiutils_sdk/files.py +29 -0
- aiutils_sdk-0.3.1/aiutils_sdk/tools_and_batch.py +40 -0
- {aiutils_sdk-0.2.3 → aiutils_sdk-0.3.1}/aiutils_sdk/wallet.py +29 -0
- {aiutils_sdk-0.2.3 → aiutils_sdk-0.3.1}/aiutils_sdk.egg-info/PKG-INFO +74 -2
- {aiutils_sdk-0.2.3 → aiutils_sdk-0.3.1}/aiutils_sdk.egg-info/SOURCES.txt +2 -1
- {aiutils_sdk-0.2.3 → aiutils_sdk-0.3.1}/pyproject.toml +1 -1
- {aiutils_sdk-0.2.3 → aiutils_sdk-0.3.1}/tests/test_sdk.py +69 -0
- aiutils_sdk-0.2.3/aiutils_sdk/research.py +0 -101
- {aiutils_sdk-0.2.3 → aiutils_sdk-0.3.1}/aiutils_sdk/chat.py +0 -0
- {aiutils_sdk-0.2.3 → aiutils_sdk-0.3.1}/aiutils_sdk/embeddings.py +0 -0
- {aiutils_sdk-0.2.3 → aiutils_sdk-0.3.1}/aiutils_sdk/generations.py +0 -0
- {aiutils_sdk-0.2.3 → aiutils_sdk-0.3.1}/aiutils_sdk/images.py +0 -0
- {aiutils_sdk-0.2.3 → aiutils_sdk-0.3.1}/aiutils_sdk/models.py +0 -0
- {aiutils_sdk-0.2.3 → aiutils_sdk-0.3.1}/aiutils_sdk/webhooks.py +0 -0
- {aiutils_sdk-0.2.3 → aiutils_sdk-0.3.1}/aiutils_sdk.egg-info/dependency_links.txt +0 -0
- {aiutils_sdk-0.2.3 → aiutils_sdk-0.3.1}/aiutils_sdk.egg-info/requires.txt +0 -0
- {aiutils_sdk-0.2.3 → aiutils_sdk-0.3.1}/aiutils_sdk.egg-info/top_level.txt +0 -0
- {aiutils_sdk-0.2.3 → 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
|
+
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.
|
|
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,9 +11,10 @@ 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.
|
|
15
|
-
from aiutils_sdk.wallet import Wallet
|
|
14
|
+
from aiutils_sdk.wallet import Wallet, Billing
|
|
16
15
|
from aiutils_sdk.webhooks import Webhooks
|
|
16
|
+
from aiutils_sdk.files import Files
|
|
17
|
+
from aiutils_sdk.tools_and_batch import Tools, Batch
|
|
17
18
|
from aiutils_sdk.exceptions import AuthenticationError, APIError
|
|
18
19
|
|
|
19
20
|
logger = logging.getLogger(__name__)
|
|
@@ -52,43 +53,80 @@ class AiUtils:
|
|
|
52
53
|
self.embeddings = Embeddings(self)
|
|
53
54
|
self.generations = Generations(self)
|
|
54
55
|
self.models = Models(self)
|
|
55
|
-
self.research = Research(self)
|
|
56
56
|
self.wallet = Wallet(self)
|
|
57
57
|
self.webhooks = Webhooks(self)
|
|
58
|
+
self.billing = Billing(self)
|
|
59
|
+
self.files = Files(self)
|
|
60
|
+
self.tools = Tools(self)
|
|
61
|
+
self.batch = Batch(self)
|
|
58
62
|
|
|
59
|
-
def _request(self, method: str, path: str, **kwargs) -> dict:
|
|
60
|
-
"""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
|
+
"""
|
|
61
70
|
url = f"{self.base_url}{path}"
|
|
62
71
|
logger.debug(f"Entered into _request: {method} {path}")
|
|
63
|
-
response = self._client.request(method, url, headers=self.
|
|
64
|
-
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.
|
|
65
77
|
|
|
66
|
-
|
|
67
|
-
|
|
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
|
+
"""
|
|
68
82
|
url = f"{self.base_url}{path}"
|
|
69
83
|
logger.debug(f"Entered into _request_async: {method} {path}")
|
|
70
84
|
if self._async_client is None:
|
|
71
85
|
self._async_client = httpx.AsyncClient(timeout=self._client.timeout)
|
|
72
|
-
response = await self._async_client.request(method, url, headers=self.
|
|
73
|
-
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.
|
|
74
91
|
|
|
75
|
-
|
|
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:
|
|
76
101
|
"""Parse response and raise appropriate errors."""
|
|
77
102
|
if response.status_code == 401:
|
|
78
103
|
raise AuthenticationError("Invalid or expired API key")
|
|
79
104
|
if response.status_code == 429:
|
|
80
105
|
from aiutils_sdk.exceptions import RateLimitError
|
|
81
|
-
retry_after = response.headers.get("
|
|
106
|
+
retry_after = response.headers.get("Retry-After", "60")
|
|
82
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")
|
|
83
111
|
if response.status_code == 402:
|
|
84
112
|
from aiutils_sdk.exceptions import InsufficientDTError
|
|
85
|
-
|
|
113
|
+
try:
|
|
114
|
+
detail = response.json().get("detail", "Insufficient DT balance")
|
|
115
|
+
except Exception:
|
|
116
|
+
detail = response.text[:500] or "Insufficient DT balance"
|
|
86
117
|
raise InsufficientDTError(detail)
|
|
87
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]
|
|
88
124
|
raise APIError(
|
|
89
|
-
|
|
125
|
+
detail,
|
|
90
126
|
status_code=response.status_code,
|
|
91
127
|
)
|
|
128
|
+
if raw:
|
|
129
|
+
return response.content
|
|
92
130
|
return response.json()
|
|
93
131
|
|
|
94
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
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""File upload resource."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
import logging
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
logger = logging.getLogger(__name__)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Files:
|
|
10
|
+
"""File upload namespace."""
|
|
11
|
+
|
|
12
|
+
def __init__(self, client):
|
|
13
|
+
self._client = client
|
|
14
|
+
|
|
15
|
+
def upload(self, file_path: str, purpose: str = "assistants") -> dict:
|
|
16
|
+
"""Upload a file to the API."""
|
|
17
|
+
logger.debug(f"Entered into Files.upload: {file_path}")
|
|
18
|
+
with open(file_path, "rb") as f:
|
|
19
|
+
return self._client._request(
|
|
20
|
+
"POST", "/v1/files",
|
|
21
|
+
files={"file": f},
|
|
22
|
+
data={"purpose": purpose},
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
def list(self) -> list[dict]:
|
|
26
|
+
"""List uploaded files."""
|
|
27
|
+
logger.debug("Entered into Files.list")
|
|
28
|
+
data = self._client._request("GET", "/v1/files")
|
|
29
|
+
return data.get("data", data.get("files", []))
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Portal tools + batch endpoints."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
import logging
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
logger = logging.getLogger(__name__)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Tools:
|
|
10
|
+
"""Portal tools namespace."""
|
|
11
|
+
|
|
12
|
+
def __init__(self, client):
|
|
13
|
+
self._client = client
|
|
14
|
+
|
|
15
|
+
def genres(self) -> dict:
|
|
16
|
+
"""List available tool genres/categories."""
|
|
17
|
+
logger.debug("Entered into Tools.genres")
|
|
18
|
+
return self._client._request("GET", "/v1/tools/genres")
|
|
19
|
+
|
|
20
|
+
def execute(self, tool_slug: str, **params) -> dict:
|
|
21
|
+
"""Execute a portal tool by slug."""
|
|
22
|
+
logger.debug(f"Entered into Tools.execute: {tool_slug}")
|
|
23
|
+
return self._client._request("POST", f"/v1/tools/{tool_slug}/execute", json={"inputs": params})
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class Batch:
|
|
27
|
+
"""Batch request namespace."""
|
|
28
|
+
|
|
29
|
+
def __init__(self, client):
|
|
30
|
+
self._client = client
|
|
31
|
+
|
|
32
|
+
def create(self, requests: list[dict]) -> dict:
|
|
33
|
+
"""Submit a batch of requests."""
|
|
34
|
+
logger.debug("Entered into Batch.create")
|
|
35
|
+
return self._client._request("POST", "/v1/batch", json={"requests": requests})
|
|
36
|
+
|
|
37
|
+
def status(self, batch_id: str) -> dict:
|
|
38
|
+
"""Check batch status."""
|
|
39
|
+
logger.debug(f"Entered into Batch.status: {batch_id}")
|
|
40
|
+
return self._client._request("GET", f"/v1/batch/{batch_id}")
|
|
@@ -103,3 +103,32 @@ class Wallet:
|
|
|
103
103
|
body = {"model": model, "parameters": parameters or {}}
|
|
104
104
|
data = self._client._request("POST", "/v1/pricing/estimate", json=body)
|
|
105
105
|
return PricingEstimate(**data)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def set_alert_threshold(self, threshold_dt: int) -> dict:
|
|
109
|
+
"""Set low balance alert threshold in DT. Pass 0 to disable alerts."""
|
|
110
|
+
logger.debug("Entered into Wallet.set_alert_threshold")
|
|
111
|
+
return self._client._request("POST", "/v1/wallet/alert-threshold", json={"threshold_dt": threshold_dt})
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
class Billing:
|
|
115
|
+
"""Billing namespace for DT purchases."""
|
|
116
|
+
|
|
117
|
+
def __init__(self, client):
|
|
118
|
+
self._client = client
|
|
119
|
+
|
|
120
|
+
def list_packs(self) -> list[dict]:
|
|
121
|
+
"""List available DT packs."""
|
|
122
|
+
logger.debug("Entered into Billing.list_packs")
|
|
123
|
+
data = self._client._request("GET", "/v1/billing/packs")
|
|
124
|
+
return data.get("packs", data.get("data", []))
|
|
125
|
+
|
|
126
|
+
def checkout(self, pack_slug: str) -> dict:
|
|
127
|
+
"""Create a checkout session for a DT pack (e.g. "pack-20000")."""
|
|
128
|
+
logger.debug("Entered into Billing.checkout")
|
|
129
|
+
return self._client._request("POST", "/v1/billing/checkout", json={"pack_slug": pack_slug})
|
|
130
|
+
|
|
131
|
+
def get_invoice(self, transaction_id: str) -> bytes:
|
|
132
|
+
"""Download the PDF invoice for a billing transaction (raw bytes)."""
|
|
133
|
+
logger.debug("Entered into Billing.get_invoice")
|
|
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
|
+
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)
|
|
@@ -5,10 +5,11 @@ aiutils_sdk/chat.py
|
|
|
5
5
|
aiutils_sdk/client.py
|
|
6
6
|
aiutils_sdk/embeddings.py
|
|
7
7
|
aiutils_sdk/exceptions.py
|
|
8
|
+
aiutils_sdk/files.py
|
|
8
9
|
aiutils_sdk/generations.py
|
|
9
10
|
aiutils_sdk/images.py
|
|
10
11
|
aiutils_sdk/models.py
|
|
11
|
-
aiutils_sdk/
|
|
12
|
+
aiutils_sdk/tools_and_batch.py
|
|
12
13
|
aiutils_sdk/wallet.py
|
|
13
14
|
aiutils_sdk/webhooks.py
|
|
14
15
|
aiutils_sdk.egg-info/PKG-INFO
|
|
@@ -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
|