aiutils-sdk 0.1.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.
- aiutils_sdk/__init__.py +13 -0
- aiutils_sdk/chat.py +76 -0
- aiutils_sdk/client.py +106 -0
- aiutils_sdk/embeddings.py +60 -0
- aiutils_sdk/exceptions.py +30 -0
- aiutils_sdk/generations.py +74 -0
- aiutils_sdk/images.py +47 -0
- aiutils_sdk/models.py +86 -0
- aiutils_sdk-0.1.0.dist-info/METADATA +121 -0
- aiutils_sdk-0.1.0.dist-info/RECORD +12 -0
- aiutils_sdk-0.1.0.dist-info/WHEEL +5 -0
- aiutils_sdk-0.1.0.dist-info/top_level.txt +1 -0
aiutils_sdk/__init__.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""AiUtils Python SDK — 100+ AI models, one unified API."""
|
|
2
|
+
from aiutils_sdk.client import AiUtils
|
|
3
|
+
from aiutils_sdk.exceptions import (
|
|
4
|
+
AiUtilsError, AuthenticationError, InsufficientDTError,
|
|
5
|
+
RateLimitError, APIError, ProviderError,
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
__version__ = "0.1.0"
|
|
9
|
+
__all__ = [
|
|
10
|
+
"AiUtils",
|
|
11
|
+
"AiUtilsError", "AuthenticationError", "InsufficientDTError",
|
|
12
|
+
"RateLimitError", "APIError", "ProviderError",
|
|
13
|
+
]
|
aiutils_sdk/chat.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""Chat completions resource — OpenAI-compatible."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import logging
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
from pydantic import BaseModel
|
|
8
|
+
|
|
9
|
+
logger = logging.getLogger(__name__)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ChatMessage(BaseModel):
|
|
13
|
+
role: str
|
|
14
|
+
content: str
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Choice(BaseModel):
|
|
18
|
+
index: int
|
|
19
|
+
message: ChatMessage
|
|
20
|
+
finish_reason: Optional[str] = "stop"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class Usage(BaseModel):
|
|
24
|
+
prompt_tokens: int
|
|
25
|
+
completion_tokens: int
|
|
26
|
+
total_tokens: int
|
|
27
|
+
dt_consumed: int = 0
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class ChatResponse(BaseModel):
|
|
31
|
+
id: str
|
|
32
|
+
object: str
|
|
33
|
+
created: int
|
|
34
|
+
model: str
|
|
35
|
+
provider: str = "unknown"
|
|
36
|
+
usage: Usage
|
|
37
|
+
choices: list[Choice]
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class Chat:
|
|
41
|
+
"""Chat completions namespace."""
|
|
42
|
+
|
|
43
|
+
def __init__(self, client):
|
|
44
|
+
self._client = client
|
|
45
|
+
self.completions = ChatCompletions(client)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class ChatCompletions:
|
|
49
|
+
"""OpenAI-compatible chat completions."""
|
|
50
|
+
|
|
51
|
+
def __init__(self, client):
|
|
52
|
+
self._client = client
|
|
53
|
+
|
|
54
|
+
def create(
|
|
55
|
+
self,
|
|
56
|
+
model: str,
|
|
57
|
+
messages: list[dict],
|
|
58
|
+
temperature: float = 0.7,
|
|
59
|
+
max_tokens: int = 500,
|
|
60
|
+
stream: bool = False,
|
|
61
|
+
top_p: float = 1.0,
|
|
62
|
+
**kwargs,
|
|
63
|
+
) -> ChatResponse:
|
|
64
|
+
"""Create a chat completion."""
|
|
65
|
+
logger.debug(f"Entered into ChatCompletions.create: model={model}")
|
|
66
|
+
body = {
|
|
67
|
+
"model": model,
|
|
68
|
+
"messages": messages,
|
|
69
|
+
"temperature": temperature,
|
|
70
|
+
"max_tokens": max_tokens,
|
|
71
|
+
"stream": stream,
|
|
72
|
+
"top_p": top_p,
|
|
73
|
+
**kwargs,
|
|
74
|
+
}
|
|
75
|
+
data = self._client._request("POST", "/v1/chat/completions", json=body)
|
|
76
|
+
return ChatResponse(**data)
|
aiutils_sdk/client.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""AiUtils client — top-level entry point for the SDK."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import logging
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
import httpx
|
|
8
|
+
|
|
9
|
+
from aiutils_sdk.chat import Chat
|
|
10
|
+
from aiutils_sdk.images import Images
|
|
11
|
+
from aiutils_sdk.embeddings import Embeddings
|
|
12
|
+
from aiutils_sdk.generations import Generations
|
|
13
|
+
from aiutils_sdk.models import Models
|
|
14
|
+
from aiutils_sdk.exceptions import AuthenticationError, APIError
|
|
15
|
+
|
|
16
|
+
logger = logging.getLogger(__name__)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class AiUtils:
|
|
20
|
+
"""Main client for the AiUtils Developer API.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
api_key: Your API key (ak-dev-...).
|
|
24
|
+
base_url: Base URL for the API (default: https://developer-api.aiutils.io).
|
|
25
|
+
timeout: HTTP request timeout in seconds.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
def __init__(
|
|
29
|
+
self,
|
|
30
|
+
api_key: str,
|
|
31
|
+
base_url: str = "https://developer-api.aiutils.io",
|
|
32
|
+
timeout: float = 60.0,
|
|
33
|
+
):
|
|
34
|
+
logger.debug("Entered into AiUtils.__init__")
|
|
35
|
+
if not api_key:
|
|
36
|
+
raise AuthenticationError("api_key is required")
|
|
37
|
+
self.api_key = api_key
|
|
38
|
+
self.base_url = base_url.rstrip("/")
|
|
39
|
+
self._headers = {
|
|
40
|
+
"Authorization": f"Bearer {api_key}",
|
|
41
|
+
"Content-Type": "application/json",
|
|
42
|
+
"API-Version": "2026-07-01",
|
|
43
|
+
}
|
|
44
|
+
self._client = httpx.Client(timeout=timeout)
|
|
45
|
+
self._async_client: Optional[httpx.AsyncClient] = None
|
|
46
|
+
|
|
47
|
+
self.chat = Chat(self)
|
|
48
|
+
self.images = Images(self)
|
|
49
|
+
self.embeddings = Embeddings(self)
|
|
50
|
+
self.generations = Generations(self)
|
|
51
|
+
self.models = Models(self)
|
|
52
|
+
|
|
53
|
+
def _request(self, method: str, path: str, **kwargs) -> dict:
|
|
54
|
+
"""Make a synchronous HTTP request."""
|
|
55
|
+
url = f"{self.base_url}{path}"
|
|
56
|
+
logger.debug(f"Entered into _request: {method} {path}")
|
|
57
|
+
response = self._client.request(method, url, headers=self._headers, **kwargs)
|
|
58
|
+
return self._handle_response(response)
|
|
59
|
+
|
|
60
|
+
async def _request_async(self, method: str, path: str, **kwargs) -> dict:
|
|
61
|
+
"""Make an async HTTP request."""
|
|
62
|
+
url = f"{self.base_url}{path}"
|
|
63
|
+
logger.debug(f"Entered into _request_async: {method} {path}")
|
|
64
|
+
if self._async_client is None:
|
|
65
|
+
self._async_client = httpx.AsyncClient(timeout=self._client.timeout)
|
|
66
|
+
response = await self._async_client.request(method, url, headers=self._headers, **kwargs)
|
|
67
|
+
return self._handle_response(response)
|
|
68
|
+
|
|
69
|
+
def _handle_response(self, response: httpx.Response) -> dict:
|
|
70
|
+
"""Parse response and raise appropriate errors."""
|
|
71
|
+
if response.status_code == 401:
|
|
72
|
+
raise AuthenticationError("Invalid or expired API key")
|
|
73
|
+
if response.status_code == 429:
|
|
74
|
+
from aiutils_sdk.exceptions import RateLimitError
|
|
75
|
+
retry_after = response.headers.get("X-RateLimit-Reset", "60")
|
|
76
|
+
raise RateLimitError(f"Rate limit exceeded. Retry after {retry_after}s")
|
|
77
|
+
if response.status_code == 402:
|
|
78
|
+
from aiutils_sdk.exceptions import InsufficientDTError
|
|
79
|
+
detail = response.json().get("detail", "Insufficient DT balance")
|
|
80
|
+
raise InsufficientDTError(detail)
|
|
81
|
+
if response.status_code >= 400:
|
|
82
|
+
raise APIError(
|
|
83
|
+
response.text[:500],
|
|
84
|
+
status_code=response.status_code,
|
|
85
|
+
)
|
|
86
|
+
return response.json()
|
|
87
|
+
|
|
88
|
+
def close(self):
|
|
89
|
+
"""Clean up HTTP resources."""
|
|
90
|
+
self._client.close()
|
|
91
|
+
if self._async_client:
|
|
92
|
+
import asyncio
|
|
93
|
+
try:
|
|
94
|
+
loop = asyncio.get_event_loop()
|
|
95
|
+
if loop.is_running():
|
|
96
|
+
loop.create_task(self._async_client.aclose())
|
|
97
|
+
else:
|
|
98
|
+
loop.run_until_complete(self._async_client.aclose())
|
|
99
|
+
except RuntimeError:
|
|
100
|
+
pass
|
|
101
|
+
|
|
102
|
+
def __enter__(self):
|
|
103
|
+
return self
|
|
104
|
+
|
|
105
|
+
def __exit__(self, *args):
|
|
106
|
+
self.close()
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""Embeddings resource."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import logging
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
from pydantic import BaseModel
|
|
8
|
+
|
|
9
|
+
logger = logging.getLogger(__name__)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class EmbeddingData(BaseModel):
|
|
13
|
+
object: str = "embedding"
|
|
14
|
+
index: int
|
|
15
|
+
embedding: list[float]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class EmbeddingUsage(BaseModel):
|
|
19
|
+
prompt_tokens: int
|
|
20
|
+
total_tokens: int
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class EmbeddingResponse(BaseModel):
|
|
24
|
+
object: str = "list"
|
|
25
|
+
data: list[EmbeddingData]
|
|
26
|
+
model: str
|
|
27
|
+
usage: EmbeddingUsage
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class Embeddings:
|
|
31
|
+
"""Embeddings namespace."""
|
|
32
|
+
|
|
33
|
+
def __init__(self, client):
|
|
34
|
+
self._client = client
|
|
35
|
+
self.create = EmbeddingCreate(client)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class EmbeddingCreate:
|
|
39
|
+
"""Create embeddings from text."""
|
|
40
|
+
|
|
41
|
+
def __init__(self, client):
|
|
42
|
+
self._client = client
|
|
43
|
+
|
|
44
|
+
def create(
|
|
45
|
+
self,
|
|
46
|
+
model: str = "text-embedding-3-small",
|
|
47
|
+
input: str | list[str] = "",
|
|
48
|
+
encoding_format: str = "float",
|
|
49
|
+
**kwargs,
|
|
50
|
+
) -> EmbeddingResponse:
|
|
51
|
+
"""Create an embedding vector for the given input."""
|
|
52
|
+
logger.debug(f"Entered into EmbeddingCreate.create: model={model}")
|
|
53
|
+
body = {
|
|
54
|
+
"model": model,
|
|
55
|
+
"input": input,
|
|
56
|
+
"encoding_format": encoding_format,
|
|
57
|
+
**kwargs,
|
|
58
|
+
}
|
|
59
|
+
data = self._client._request("POST", "/v1/embeddings", json=body)
|
|
60
|
+
return EmbeddingResponse(**data)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""AiUtils SDK exceptions."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class AiUtilsError(Exception):
|
|
6
|
+
"""Base exception for all SDK errors."""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class AuthenticationError(AiUtilsError):
|
|
10
|
+
"""Invalid or expired API key."""
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class InsufficientDTError(AiUtilsError):
|
|
14
|
+
"""Not enough DT balance for the request."""
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class RateLimitError(AiUtilsError):
|
|
18
|
+
"""Too many requests — retry after the indicated delay."""
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class APIError(AiUtilsError):
|
|
22
|
+
"""Generic API error with HTTP status code."""
|
|
23
|
+
|
|
24
|
+
def __init__(self, message: str, status_code: int = 500):
|
|
25
|
+
super().__init__(message)
|
|
26
|
+
self.status_code = status_code
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class ProviderError(AiUtilsError):
|
|
30
|
+
"""The underlying AI provider returned an error."""
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""Universal generation resource — image, video, audio, 3D models."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import logging
|
|
5
|
+
import time
|
|
6
|
+
from typing import Optional
|
|
7
|
+
|
|
8
|
+
from pydantic import BaseModel
|
|
9
|
+
|
|
10
|
+
logger = logging.getLogger(__name__)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class GenerationResponse(BaseModel):
|
|
14
|
+
id: str
|
|
15
|
+
status: str
|
|
16
|
+
model: str
|
|
17
|
+
output: Optional[dict] = None
|
|
18
|
+
download_urls: list[str] = []
|
|
19
|
+
dt_consumed: Optional[int] = None
|
|
20
|
+
dt_reserved: Optional[int] = None
|
|
21
|
+
error: Optional[str] = None
|
|
22
|
+
created_at: float
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class Generations:
|
|
26
|
+
"""Generations namespace for media models."""
|
|
27
|
+
|
|
28
|
+
def __init__(self, client):
|
|
29
|
+
self._client = client
|
|
30
|
+
|
|
31
|
+
def create(
|
|
32
|
+
self,
|
|
33
|
+
model: str,
|
|
34
|
+
parameters: dict,
|
|
35
|
+
wait_for_completion: bool = True,
|
|
36
|
+
timeout: int = 300,
|
|
37
|
+
) -> GenerationResponse:
|
|
38
|
+
"""Submit a generation request.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
model: Model ID from catalog, e.g. 'fal:fal-ai/flux/dev'.
|
|
42
|
+
parameters: Model-specific input parameters.
|
|
43
|
+
wait_for_completion: If True, blocks until done (up to timeout).
|
|
44
|
+
timeout: Max seconds to wait for async generation.
|
|
45
|
+
"""
|
|
46
|
+
logger.debug(f"Entered into Generations.create: model={model}")
|
|
47
|
+
body = {
|
|
48
|
+
"model": model,
|
|
49
|
+
"parameters": parameters,
|
|
50
|
+
"wait_for_completion": wait_for_completion,
|
|
51
|
+
"timeout": timeout,
|
|
52
|
+
}
|
|
53
|
+
data = self._client._request("POST", "/v1/generations", json=body)
|
|
54
|
+
resp = GenerationResponse(**data)
|
|
55
|
+
|
|
56
|
+
if not wait_for_completion and resp.status == "processing":
|
|
57
|
+
return resp
|
|
58
|
+
|
|
59
|
+
if resp.status == "processing":
|
|
60
|
+
start = time.time()
|
|
61
|
+
while time.time() - start < timeout:
|
|
62
|
+
time.sleep(3)
|
|
63
|
+
poll_data = self._client._request("GET", f"/v1/generations/{resp.id}")
|
|
64
|
+
resp = GenerationResponse(**poll_data)
|
|
65
|
+
if resp.status in ("completed", "failed", "timeout"):
|
|
66
|
+
break
|
|
67
|
+
|
|
68
|
+
return resp
|
|
69
|
+
|
|
70
|
+
def get(self, generation_id: str) -> GenerationResponse:
|
|
71
|
+
"""Poll an existing generation by ID."""
|
|
72
|
+
logger.debug(f"Entered into Generations.get: id={generation_id}")
|
|
73
|
+
data = self._client._request("GET", f"/v1/generations/{generation_id}")
|
|
74
|
+
return GenerationResponse(**data)
|
aiutils_sdk/images.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""Image generation resource."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import logging
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
from pydantic import BaseModel
|
|
8
|
+
|
|
9
|
+
logger = logging.getLogger(__name__)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ImageData(BaseModel):
|
|
13
|
+
url: str
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class ImageResponse(BaseModel):
|
|
17
|
+
created: int
|
|
18
|
+
data: list[ImageData]
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class Images:
|
|
22
|
+
"""Images namespace."""
|
|
23
|
+
|
|
24
|
+
def __init__(self, client):
|
|
25
|
+
self._client = client
|
|
26
|
+
self.generate = ImageGenerate(client)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class ImageGenerate:
|
|
30
|
+
"""Image generation endpoint."""
|
|
31
|
+
|
|
32
|
+
def __init__(self, client):
|
|
33
|
+
self._client = client
|
|
34
|
+
|
|
35
|
+
def generate(
|
|
36
|
+
self,
|
|
37
|
+
model: str,
|
|
38
|
+
prompt: str,
|
|
39
|
+
n: int = 1,
|
|
40
|
+
size: str = "1024x1024",
|
|
41
|
+
**kwargs,
|
|
42
|
+
) -> ImageResponse:
|
|
43
|
+
"""Generate images from a prompt."""
|
|
44
|
+
logger.debug(f"Entered into ImageGenerate.generate: model={model}")
|
|
45
|
+
body = {"model": model, "prompt": prompt, "n": n, "size": size, **kwargs}
|
|
46
|
+
data = self._client._request("POST", "/v1/images/generations", json=body)
|
|
47
|
+
return ImageResponse(**data)
|
aiutils_sdk/models.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"""Model catalog resource."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import logging
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
from pydantic import BaseModel
|
|
8
|
+
|
|
9
|
+
logger = logging.getLogger(__name__)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ModelPricing(BaseModel):
|
|
13
|
+
credits: Optional[int] = None
|
|
14
|
+
dt_cost: Optional[int] = None
|
|
15
|
+
unit: str = ""
|
|
16
|
+
detail: Optional[str] = None
|
|
17
|
+
free: bool = False
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class ModelCapabilities(BaseModel):
|
|
21
|
+
vision: bool = False
|
|
22
|
+
streaming: bool = False
|
|
23
|
+
free: bool = False
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class ModelInfo(BaseModel):
|
|
27
|
+
id: str
|
|
28
|
+
source: str = ""
|
|
29
|
+
vendor: str = ""
|
|
30
|
+
name: str = ""
|
|
31
|
+
label: str = ""
|
|
32
|
+
modality: str = ""
|
|
33
|
+
category: str = ""
|
|
34
|
+
description: Optional[str] = None
|
|
35
|
+
thumbnail_url: Optional[str] = None
|
|
36
|
+
pricing: ModelPricing = ModelPricing()
|
|
37
|
+
capabilities: ModelCapabilities = ModelCapabilities()
|
|
38
|
+
is_async: bool = False
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class ModelListResponse(BaseModel):
|
|
42
|
+
object: str = "list"
|
|
43
|
+
data: list[ModelInfo] = []
|
|
44
|
+
total: int = 0
|
|
45
|
+
page: int = 1
|
|
46
|
+
page_size: int = 50
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class Models:
|
|
50
|
+
"""Model catalog namespace."""
|
|
51
|
+
|
|
52
|
+
def __init__(self, client):
|
|
53
|
+
self._client = client
|
|
54
|
+
|
|
55
|
+
def list(
|
|
56
|
+
self,
|
|
57
|
+
category: Optional[str] = None,
|
|
58
|
+
vendor: Optional[str] = None,
|
|
59
|
+
search: Optional[str] = None,
|
|
60
|
+
page: int = 1,
|
|
61
|
+
page_size: int = 50,
|
|
62
|
+
) -> ModelListResponse:
|
|
63
|
+
"""List available models with optional filtering."""
|
|
64
|
+
logger.debug(
|
|
65
|
+
f"Entered into Models.list: category={category}, vendor={vendor}"
|
|
66
|
+
)
|
|
67
|
+
params = {"page": page, "page_size": page_size}
|
|
68
|
+
if category:
|
|
69
|
+
params["category"] = category
|
|
70
|
+
if vendor:
|
|
71
|
+
params["vendor"] = vendor
|
|
72
|
+
if search:
|
|
73
|
+
params["search"] = search
|
|
74
|
+
data = self._client._request("GET", "/v1/models", params=params)
|
|
75
|
+
models_list = data.get("models", [])
|
|
76
|
+
return ModelListResponse(
|
|
77
|
+
data=[ModelInfo(**m) for m in models_list],
|
|
78
|
+
total=data.get("total", len(models_list)),
|
|
79
|
+
page=data.get("page", page),
|
|
80
|
+
page_size=data.get("page_size", page_size),
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
def get(self, model_id: str) -> dict:
|
|
84
|
+
"""Get detailed information about a specific model."""
|
|
85
|
+
logger.debug(f"Entered into Models.get: id={model_id}")
|
|
86
|
+
return self._client._request("GET", f"/v1/models/{model_id}")
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: aiutils-sdk
|
|
3
|
+
Version: 0.1.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: 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
|
+
# AiUtils Python SDK
|
|
19
|
+
|
|
20
|
+
Official Python SDK for the [AiUtils Developer API](https://developer.aiutils.io) — access 100+ AI models (LLM, image, video, audio, 3D) through one unified API.
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install aiutils-sdk
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick Start
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from aiutils_sdk import AiUtils
|
|
32
|
+
|
|
33
|
+
client = AiUtils(api_key="ak-dev-YOUR_KEY")
|
|
34
|
+
|
|
35
|
+
# Chat completion (OpenAI-compatible)
|
|
36
|
+
response = client.chat.completions.create(
|
|
37
|
+
model="gpt-4o",
|
|
38
|
+
messages=[{"role": "user", "content": "Explain quantum computing in one sentence."}],
|
|
39
|
+
)
|
|
40
|
+
print(response.choices[0].message.content)
|
|
41
|
+
|
|
42
|
+
# Image generation
|
|
43
|
+
image = client.images.generate.generate(
|
|
44
|
+
model="fal:fal-ai/flux/dev",
|
|
45
|
+
prompt="A futuristic city at sunset, cyberpunk style",
|
|
46
|
+
)
|
|
47
|
+
print(image.data[0].url)
|
|
48
|
+
|
|
49
|
+
# Video generation (async with auto-polling)
|
|
50
|
+
video = client.generations.create(
|
|
51
|
+
model="fal:fal-ai/kling-video/v1.6/pro/image-to-video",
|
|
52
|
+
parameters={"prompt": "Camera orbits a mountain lake", "image_url": "..."},
|
|
53
|
+
wait_for_completion=True,
|
|
54
|
+
timeout=300,
|
|
55
|
+
)
|
|
56
|
+
print(video.download_urls)
|
|
57
|
+
|
|
58
|
+
# Embeddings
|
|
59
|
+
embeddings = client.embeddings.create.create(
|
|
60
|
+
model="text-embedding-3-small",
|
|
61
|
+
input="Hello world",
|
|
62
|
+
)
|
|
63
|
+
print(len(embeddings.data[0].embedding))
|
|
64
|
+
|
|
65
|
+
# Browse model catalog
|
|
66
|
+
models = client.models.list(category="image", vendor="fal")
|
|
67
|
+
for m in models.data:
|
|
68
|
+
print(f"{m.id} — {m.label}")
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## API Reference
|
|
72
|
+
|
|
73
|
+
### `AiUtils(api_key, base_url=..., timeout=60.0)`
|
|
74
|
+
|
|
75
|
+
| Param | Type | Default | Description |
|
|
76
|
+
|-------|------|---------|-------------|
|
|
77
|
+
| `api_key` | `str` | required | Your developer API key (`ak-dev-...`) |
|
|
78
|
+
| `base_url` | `str` | `https://developer-api.aiutils.io` | API base URL |
|
|
79
|
+
| `timeout` | `float` | `60.0` | Request timeout in seconds |
|
|
80
|
+
|
|
81
|
+
### Resources
|
|
82
|
+
|
|
83
|
+
- `client.chat.completions.create(...)` — OpenAI-compatible chat completions
|
|
84
|
+
- `client.images.generate.generate(...)` — Image generation
|
|
85
|
+
- `client.embeddings.create.create(...)` — Text embeddings
|
|
86
|
+
- `client.generations.create(...)` — Universal generation (image/video/audio/3D)
|
|
87
|
+
- `client.generations.get(id)` — Poll generation status
|
|
88
|
+
- `client.models.list(...)` — Browse model catalog
|
|
89
|
+
- `client.models.get(id)` — Get model details + schemas
|
|
90
|
+
|
|
91
|
+
### Error Handling
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from aiutils_sdk import AiUtils, AuthenticationError, InsufficientDTError, RateLimitError
|
|
95
|
+
|
|
96
|
+
try:
|
|
97
|
+
response = client.chat.completions.create(...)
|
|
98
|
+
except AuthenticationError:
|
|
99
|
+
print("Bad API key")
|
|
100
|
+
except InsufficientDTError:
|
|
101
|
+
print("Top up your DT balance")
|
|
102
|
+
except RateLimitError:
|
|
103
|
+
print("Slow down")
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Context Manager
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
with AiUtils(api_key="ak-dev-YOUR_KEY") as client:
|
|
110
|
+
response = client.chat.completions.create(...)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Billing
|
|
114
|
+
|
|
115
|
+
All usage is billed in DT (Developer Tokens). `1 DT = $0.001 USD`. Cost = provider cost + 8% platform fee.
|
|
116
|
+
|
|
117
|
+
## Links
|
|
118
|
+
|
|
119
|
+
- [Developer Console](https://developer.aiutils.io)
|
|
120
|
+
- [API Documentation](https://developer.aiutils.io/docs)
|
|
121
|
+
- [Get API Key](https://developer.aiutils.io/api-keys)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
aiutils_sdk/__init__.py,sha256=2XIRC8c2kwt_I5z6eTaoFmbAIxOMmdhpOe__QgTHuGc,414
|
|
2
|
+
aiutils_sdk/chat.py,sha256=O_yjc15s9f_djrYOiROtLdZ21F2t8y3NkWkEVfXJ8DY,1689
|
|
3
|
+
aiutils_sdk/client.py,sha256=nfUC7iwJ3ObgiLovzQRnn4Ym-VeOTN-lTF8LDrN1vqg,3910
|
|
4
|
+
aiutils_sdk/embeddings.py,sha256=MDw8FQe8_xQ-Fzz7mZN6wtmPyU6AprqPihrzSrAaKY0,1391
|
|
5
|
+
aiutils_sdk/exceptions.py,sha256=cvFIon-uXU3z7z4-gWXF0JkTKgqL4AIO05RRgt6toc0,731
|
|
6
|
+
aiutils_sdk/generations.py,sha256=a795ErdPzb1AkCj3-b9ygMwsQJpS0WGBDFBLXw-Bq7s,2338
|
|
7
|
+
aiutils_sdk/images.py,sha256=HEm54pnOWHgr2FgQXjmmYBOT3N0h0H0YhkZWmzLhD0s,1069
|
|
8
|
+
aiutils_sdk/models.py,sha256=55lCUeNc02twEkABtRIys8_hMLLjxABxBy1QG0yD2Qs,2352
|
|
9
|
+
aiutils_sdk-0.1.0.dist-info/METADATA,sha256=u81MJ3EzgGpsrxjPhfgsmlGyUkaeeqTKe730Cpcl3Gs,3581
|
|
10
|
+
aiutils_sdk-0.1.0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
11
|
+
aiutils_sdk-0.1.0.dist-info/top_level.txt,sha256=rs6-JGUPxHgpjp4SecdPFeB8c9ttX8AalJCpvc6C3aM,12
|
|
12
|
+
aiutils_sdk-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
aiutils_sdk
|