usemo 0.1.1__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.
- usemo/__init__.py +6 -0
- usemo/cli.py +115 -0
- usemo/client.py +368 -0
- usemo-0.1.1.dist-info/METADATA +102 -0
- usemo-0.1.1.dist-info/RECORD +8 -0
- usemo-0.1.1.dist-info/WHEEL +4 -0
- usemo-0.1.1.dist-info/entry_points.txt +2 -0
- usemo-0.1.1.dist-info/licenses/LICENSE +21 -0
usemo/__init__.py
ADDED
usemo/cli.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""Minimal CLI entrypoint for the UseMo Python client."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import sys
|
|
8
|
+
from typing import List, Optional
|
|
9
|
+
|
|
10
|
+
from . import __version__
|
|
11
|
+
from .client import UseMoClient, UseMoError
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _build_parser() -> argparse.ArgumentParser:
|
|
15
|
+
parser = argparse.ArgumentParser(
|
|
16
|
+
prog="usemo",
|
|
17
|
+
description="UseMo Python CLI for https://api.usemo.com/api/v1 (set USEMO_API_KEY).",
|
|
18
|
+
)
|
|
19
|
+
parser.add_argument("--version", action="version", version=f"usemo {__version__}")
|
|
20
|
+
parser.add_argument("--base-url", default=None, help="Override API base URL.")
|
|
21
|
+
parser.add_argument("--workspace-id", default=None, help="Optional workspace ID header.")
|
|
22
|
+
|
|
23
|
+
sub = parser.add_subparsers(dest="command")
|
|
24
|
+
|
|
25
|
+
sub.add_parser("whoami", help="Verify workspace identity and remaining credits.")
|
|
26
|
+
|
|
27
|
+
est = sub.add_parser("estimate-cost", help="Estimate credits before rendering.")
|
|
28
|
+
est.add_argument("--data", default=None, help="JSON object payload.")
|
|
29
|
+
est.add_argument("--line", action="append", dest="lines", help="Talking-head line (repeatable).")
|
|
30
|
+
est.add_argument("--tier", default="standard", help="Scene-video tier (draft, standard, premium).")
|
|
31
|
+
|
|
32
|
+
img = sub.add_parser("generate-image", help="Generate an image via POST /generate.")
|
|
33
|
+
img.add_argument("prompt", help="Image prompt.")
|
|
34
|
+
img.add_argument("--model", default="flux-dev", help="Base model (default: flux-dev).")
|
|
35
|
+
img.add_argument("--aspect-ratio", default=None, help="Aspect ratio (e.g. 1:1, 16:9, 9:16).")
|
|
36
|
+
img.add_argument("--num-images", type=int, default=1, help="Number of images (1-4).")
|
|
37
|
+
img.add_argument("--idempotency-key", default=None, help="Idempotency key.")
|
|
38
|
+
|
|
39
|
+
vid = sub.add_parser("create-video", help="Create a brand-grounded video via POST /video/create.")
|
|
40
|
+
vid.add_argument("ask", help="Video brief or ask.")
|
|
41
|
+
vid.add_argument("--twin-id", default=None, help="Optional registered digital twin ID.")
|
|
42
|
+
vid.add_argument("--idempotency-key", default=None, help="Idempotency key.")
|
|
43
|
+
|
|
44
|
+
th = sub.add_parser("talking-head", help="Render a talking-head video via POST /video/talking-head.")
|
|
45
|
+
th.add_argument("--face-image-url", required=True, help="Portrait URL.")
|
|
46
|
+
th.add_argument("--line", action="append", required=True, dest="lines", help="Spoken line (repeatable).")
|
|
47
|
+
th.add_argument("--voice-id", default=None, help="Voice ID.")
|
|
48
|
+
th.add_argument("--aspect-ratio", default="16:9", help="Aspect ratio (default: 16:9).")
|
|
49
|
+
th.add_argument("--idempotency-key", default=None, help="Idempotency key.")
|
|
50
|
+
|
|
51
|
+
job = sub.add_parser("get-job", help="Inspect asynchronous job status via GET /jobs/{job_id}.")
|
|
52
|
+
job.add_argument("job_id", help="Job ID.")
|
|
53
|
+
|
|
54
|
+
return parser
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def main(argv: Optional[List[str]] = None) -> int:
|
|
58
|
+
parser = _build_parser()
|
|
59
|
+
args = parser.parse_args(argv)
|
|
60
|
+
if not args.command:
|
|
61
|
+
parser.print_help()
|
|
62
|
+
return 0
|
|
63
|
+
|
|
64
|
+
client = UseMoClient(base_url=args.base_url, workspace_id=args.workspace_id)
|
|
65
|
+
try:
|
|
66
|
+
if args.command == "whoami":
|
|
67
|
+
result = client.whoami()
|
|
68
|
+
elif args.command == "estimate-cost":
|
|
69
|
+
payload = json.loads(args.data) if args.data else None
|
|
70
|
+
result = client.estimate_cost(payload=payload, lines=args.lines, tier=args.tier)
|
|
71
|
+
elif args.command == "generate-image":
|
|
72
|
+
result = client.generate_image(
|
|
73
|
+
args.prompt,
|
|
74
|
+
model=args.model,
|
|
75
|
+
aspect_ratio=args.aspect_ratio,
|
|
76
|
+
num_images=args.num_images,
|
|
77
|
+
idempotency_key=args.idempotency_key,
|
|
78
|
+
)
|
|
79
|
+
elif args.command == "create-video":
|
|
80
|
+
result = client.create_video(
|
|
81
|
+
args.ask,
|
|
82
|
+
twin_id=args.twin_id,
|
|
83
|
+
idempotency_key=args.idempotency_key,
|
|
84
|
+
)
|
|
85
|
+
elif args.command == "talking-head":
|
|
86
|
+
result = client.talking_head(
|
|
87
|
+
args.face_image_url,
|
|
88
|
+
args.lines,
|
|
89
|
+
voice_id=args.voice_id,
|
|
90
|
+
aspect_ratio=args.aspect_ratio,
|
|
91
|
+
idempotency_key=args.idempotency_key,
|
|
92
|
+
)
|
|
93
|
+
elif args.command == "get-job":
|
|
94
|
+
result = client.get_job(args.job_id)
|
|
95
|
+
else:
|
|
96
|
+
parser.print_help()
|
|
97
|
+
return 2
|
|
98
|
+
except UseMoError as exc:
|
|
99
|
+
err = {
|
|
100
|
+
"error": {
|
|
101
|
+
"code": exc.code,
|
|
102
|
+
"message": str(exc),
|
|
103
|
+
"status_code": exc.status_code,
|
|
104
|
+
"detail": exc.detail,
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
sys.stderr.write(json.dumps(err) + "\n")
|
|
108
|
+
return 2 if exc.code == "invalid_input" else 1
|
|
109
|
+
|
|
110
|
+
sys.stdout.write(json.dumps(result, indent=2) + "\n")
|
|
111
|
+
return 0
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
if __name__ == "__main__":
|
|
115
|
+
raise SystemExit(main())
|
usemo/client.py
ADDED
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
"""Zero-dependency HTTP client for the UseMo REST API (/api/v1)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
import time
|
|
8
|
+
import urllib.error
|
|
9
|
+
import urllib.parse
|
|
10
|
+
import urllib.request
|
|
11
|
+
import uuid
|
|
12
|
+
from typing import Any, Callable, Dict, Iterable, Mapping, Optional, Tuple
|
|
13
|
+
|
|
14
|
+
DEFAULT_BASE_URL = "https://api.usemo.com/api/v1"
|
|
15
|
+
TERMINAL_STATUSES = frozenset({"completed", "failed", "cancelled", "canceled"})
|
|
16
|
+
|
|
17
|
+
TransportCallable = Callable[
|
|
18
|
+
[str, str, Dict[str, str], Optional[bytes], float],
|
|
19
|
+
Tuple[int, bytes],
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class UseMoError(RuntimeError):
|
|
24
|
+
"""Raised when a UseMo API or client validation error occurs."""
|
|
25
|
+
|
|
26
|
+
def __init__(
|
|
27
|
+
self,
|
|
28
|
+
message: str,
|
|
29
|
+
*,
|
|
30
|
+
code: str = "api_error",
|
|
31
|
+
status_code: Optional[int] = None,
|
|
32
|
+
detail: Any = None,
|
|
33
|
+
idempotency_key: Optional[str] = None,
|
|
34
|
+
) -> None:
|
|
35
|
+
super().__init__(message)
|
|
36
|
+
self.code = code
|
|
37
|
+
self.status_code = status_code
|
|
38
|
+
self.detail = detail
|
|
39
|
+
self.idempotency_key = idempotency_key
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _normalize_base_url(base_url: Optional[str]) -> str:
|
|
43
|
+
raw = (base_url or os.environ.get("USEMO_API_BASE") or DEFAULT_BASE_URL).strip()
|
|
44
|
+
if not raw:
|
|
45
|
+
raw = DEFAULT_BASE_URL
|
|
46
|
+
parsed = urllib.parse.urlparse(raw)
|
|
47
|
+
if parsed.scheme not in ("https", "http"):
|
|
48
|
+
raise UseMoError("base_url must use https:// (or http:// for localhost).", code="invalid_input")
|
|
49
|
+
if parsed.scheme == "http" and parsed.hostname not in ("localhost", "127.0.0.1", "::1"):
|
|
50
|
+
raise UseMoError("Non-local base_url must use https://.", code="invalid_input")
|
|
51
|
+
normalized = raw.rstrip("/")
|
|
52
|
+
if not normalized.endswith("/api/v1"):
|
|
53
|
+
if parsed.path in ("", "/"):
|
|
54
|
+
normalized = f"{normalized}/api/v1"
|
|
55
|
+
return normalized
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _default_transport(
|
|
59
|
+
method: str,
|
|
60
|
+
url: str,
|
|
61
|
+
headers: Dict[str, str],
|
|
62
|
+
body: Optional[bytes],
|
|
63
|
+
timeout: float,
|
|
64
|
+
) -> Tuple[int, bytes]:
|
|
65
|
+
req = urllib.request.Request(url=url, data=body, headers=headers, method=method)
|
|
66
|
+
try:
|
|
67
|
+
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
|
68
|
+
return int(resp.status), resp.read()
|
|
69
|
+
except urllib.error.HTTPError as exc:
|
|
70
|
+
payload = exc.read() if exc.fp is not None else b""
|
|
71
|
+
return int(exc.code), payload
|
|
72
|
+
except urllib.error.URLError as exc:
|
|
73
|
+
raise UseMoError(
|
|
74
|
+
f"Network error contacting UseMo API: {exc.reason}",
|
|
75
|
+
code="network_error",
|
|
76
|
+
) from exc
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class UseMoClient:
|
|
80
|
+
"""Thin, zero-dependency client for https://api.usemo.com/api/v1."""
|
|
81
|
+
|
|
82
|
+
def __init__(
|
|
83
|
+
self,
|
|
84
|
+
api_key: Optional[str] = None,
|
|
85
|
+
*,
|
|
86
|
+
base_url: Optional[str] = None,
|
|
87
|
+
workspace_id: Optional[str] = None,
|
|
88
|
+
timeout: float = 60.0,
|
|
89
|
+
transport: Optional[TransportCallable] = None,
|
|
90
|
+
) -> None:
|
|
91
|
+
resolved_key = api_key if api_key is not None else os.environ.get("USEMO_API_KEY")
|
|
92
|
+
self.api_key = resolved_key.strip() if isinstance(resolved_key, str) else None
|
|
93
|
+
self.base_url = _normalize_base_url(base_url)
|
|
94
|
+
self.workspace_id = workspace_id
|
|
95
|
+
if timeout <= 0:
|
|
96
|
+
raise UseMoError("timeout must be a positive number.", code="invalid_input")
|
|
97
|
+
self.timeout = float(timeout)
|
|
98
|
+
self._transport = transport or _default_transport
|
|
99
|
+
|
|
100
|
+
def __enter__(self) -> "UseMoClient":
|
|
101
|
+
return self
|
|
102
|
+
|
|
103
|
+
def __exit__(self, exc_type: Any, exc: Any, tb: Any) -> None:
|
|
104
|
+
return None
|
|
105
|
+
|
|
106
|
+
def _redact(self, text: str) -> str:
|
|
107
|
+
if self.api_key:
|
|
108
|
+
return text.replace(self.api_key, "[redacted]")
|
|
109
|
+
return text
|
|
110
|
+
|
|
111
|
+
def request(
|
|
112
|
+
self,
|
|
113
|
+
method: str,
|
|
114
|
+
path: str,
|
|
115
|
+
*,
|
|
116
|
+
body: Optional[Mapping[str, Any]] = None,
|
|
117
|
+
query: Optional[Mapping[str, Any]] = None,
|
|
118
|
+
idempotency_key: Optional[str] = None,
|
|
119
|
+
timeout: Optional[float] = None,
|
|
120
|
+
) -> Dict[str, Any]:
|
|
121
|
+
if not self.api_key:
|
|
122
|
+
raise UseMoError(
|
|
123
|
+
"Missing API key. Pass api_key='usm_...' or set USEMO_API_KEY.",
|
|
124
|
+
code="authentication_required",
|
|
125
|
+
)
|
|
126
|
+
verb = method.upper()
|
|
127
|
+
if verb not in ("GET", "POST", "PUT", "PATCH", "DELETE"):
|
|
128
|
+
raise UseMoError(f"Unsupported HTTP method: {method}", code="invalid_input")
|
|
129
|
+
clean_path = "/" + path.lstrip("/")
|
|
130
|
+
if ".." in clean_path.split("/"):
|
|
131
|
+
raise UseMoError("Invalid API path.", code="invalid_input")
|
|
132
|
+
|
|
133
|
+
url = f"{self.base_url}{clean_path}"
|
|
134
|
+
if query:
|
|
135
|
+
filtered = {k: str(v) for k, v in query.items() if v is not None}
|
|
136
|
+
if filtered:
|
|
137
|
+
url = f"{url}?{urllib.parse.urlencode(filtered)}"
|
|
138
|
+
|
|
139
|
+
headers: Dict[str, str] = {
|
|
140
|
+
"Accept": "application/json",
|
|
141
|
+
"X-API-Key": self.api_key,
|
|
142
|
+
"User-Agent": "usemo-python/0.1.1",
|
|
143
|
+
}
|
|
144
|
+
if self.workspace_id:
|
|
145
|
+
headers["X-Workspace-Id"] = self.workspace_id
|
|
146
|
+
if idempotency_key:
|
|
147
|
+
headers["X-Idempotency-Key"] = idempotency_key
|
|
148
|
+
|
|
149
|
+
payload_bytes: Optional[bytes] = None
|
|
150
|
+
if body is not None:
|
|
151
|
+
headers["Content-Type"] = "application/json"
|
|
152
|
+
payload_bytes = json.dumps(body).encode("utf-8")
|
|
153
|
+
|
|
154
|
+
status, raw = self._transport(
|
|
155
|
+
verb,
|
|
156
|
+
url,
|
|
157
|
+
headers,
|
|
158
|
+
payload_bytes,
|
|
159
|
+
self.timeout if timeout is None else float(timeout),
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
parsed: Any = None
|
|
163
|
+
if raw:
|
|
164
|
+
try:
|
|
165
|
+
parsed = json.loads(raw.decode("utf-8"))
|
|
166
|
+
except (UnicodeDecodeError, json.JSONDecodeError):
|
|
167
|
+
parsed = None
|
|
168
|
+
|
|
169
|
+
if status < 200 or status >= 300:
|
|
170
|
+
hints = {
|
|
171
|
+
401: "Invalid or expired UseMo API key.",
|
|
172
|
+
402: "Insufficient workspace credits.",
|
|
173
|
+
403: "Workspace, scope, or plan does not permit this action.",
|
|
174
|
+
422: "Request validation or consent policy check failed.",
|
|
175
|
+
429: "Rate limit exceeded; retry later.",
|
|
176
|
+
}
|
|
177
|
+
detail_raw = (
|
|
178
|
+
parsed.get("detail") if isinstance(parsed, dict) and "detail" in parsed
|
|
179
|
+
else parsed.get("error") if isinstance(parsed, dict) and "error" in parsed
|
|
180
|
+
else raw.decode("utf-8", errors="replace")[:500]
|
|
181
|
+
)
|
|
182
|
+
detail = self._redact(
|
|
183
|
+
detail_raw if isinstance(detail_raw, str) else json.dumps(detail_raw)
|
|
184
|
+
)
|
|
185
|
+
raise UseMoError(
|
|
186
|
+
hints.get(status, f"UseMo API returned HTTP {status}."),
|
|
187
|
+
code="api_error",
|
|
188
|
+
status_code=status,
|
|
189
|
+
detail=detail,
|
|
190
|
+
idempotency_key=idempotency_key,
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
if parsed is None:
|
|
194
|
+
if not raw:
|
|
195
|
+
return {}
|
|
196
|
+
raise UseMoError("UseMo API returned a non-JSON response.", code="invalid_response")
|
|
197
|
+
if isinstance(parsed, dict):
|
|
198
|
+
return parsed
|
|
199
|
+
return {"data": parsed}
|
|
200
|
+
|
|
201
|
+
def whoami(self) -> Dict[str, Any]:
|
|
202
|
+
"""Return workspace identity, plan, and remaining credit balance."""
|
|
203
|
+
return self.request("GET", "/whoami")
|
|
204
|
+
|
|
205
|
+
def estimate_cost(
|
|
206
|
+
self,
|
|
207
|
+
payload: Optional[Mapping[str, Any]] = None,
|
|
208
|
+
*,
|
|
209
|
+
storyboard: Optional[Mapping[str, Any]] = None,
|
|
210
|
+
shots: Optional[Iterable[Mapping[str, Any]]] = None,
|
|
211
|
+
lines: Optional[Iterable[str]] = None,
|
|
212
|
+
tier: str = "standard",
|
|
213
|
+
**extra: Any,
|
|
214
|
+
) -> Dict[str, Any]:
|
|
215
|
+
"""Quote credit/USD cost before rendering.
|
|
216
|
+
|
|
217
|
+
Pass ``lines`` for a talking-head quote (``POST /video/talking-head/quote``),
|
|
218
|
+
or ``storyboard`` / ``shots`` for a scene-video quote
|
|
219
|
+
(``POST /video/scene-video/quote``).
|
|
220
|
+
"""
|
|
221
|
+
body: Dict[str, Any] = dict(payload) if payload else {}
|
|
222
|
+
body.update(extra)
|
|
223
|
+
if lines is not None:
|
|
224
|
+
body["lines"] = list(lines)
|
|
225
|
+
if "lines" in body:
|
|
226
|
+
return self.request("POST", "/video/talking-head/quote", body=body)
|
|
227
|
+
if storyboard is not None:
|
|
228
|
+
body["storyboard"] = dict(storyboard)
|
|
229
|
+
if shots is not None:
|
|
230
|
+
body["shots"] = [dict(s) for s in shots]
|
|
231
|
+
body.setdefault("tier", tier)
|
|
232
|
+
return self.request("POST", "/video/scene-video/quote", body=body)
|
|
233
|
+
|
|
234
|
+
def generate_image(
|
|
235
|
+
self,
|
|
236
|
+
prompt: str,
|
|
237
|
+
*,
|
|
238
|
+
model: str = "flux-dev",
|
|
239
|
+
aspect_ratio: Optional[str] = None,
|
|
240
|
+
num_images: int = 1,
|
|
241
|
+
negative_prompt: Optional[str] = None,
|
|
242
|
+
twin_id: Optional[str] = None,
|
|
243
|
+
project_id: Optional[str] = None,
|
|
244
|
+
idempotency_key: Optional[str] = None,
|
|
245
|
+
**extra: Any,
|
|
246
|
+
) -> Dict[str, Any]:
|
|
247
|
+
"""Submit an idempotent image generation job (``POST /generate``)."""
|
|
248
|
+
if not prompt or not prompt.strip():
|
|
249
|
+
raise UseMoError("prompt must be a non-empty string.", code="invalid_input")
|
|
250
|
+
body: Dict[str, Any] = {
|
|
251
|
+
"prompt": prompt,
|
|
252
|
+
"model": model,
|
|
253
|
+
"num_images": num_images,
|
|
254
|
+
}
|
|
255
|
+
if aspect_ratio is not None:
|
|
256
|
+
body["aspect_ratio"] = aspect_ratio
|
|
257
|
+
if negative_prompt is not None:
|
|
258
|
+
body["negative_prompt"] = negative_prompt
|
|
259
|
+
if twin_id is not None:
|
|
260
|
+
body["twin_id"] = twin_id
|
|
261
|
+
if project_id is not None:
|
|
262
|
+
body["project_id"] = project_id
|
|
263
|
+
body.update(extra)
|
|
264
|
+
key = idempotency_key or str(uuid.uuid4())
|
|
265
|
+
result = self.request("POST", "/generate", body=body, idempotency_key=key)
|
|
266
|
+
return {**result, "idempotency_key": key}
|
|
267
|
+
|
|
268
|
+
def create_video(
|
|
269
|
+
self,
|
|
270
|
+
ask: str,
|
|
271
|
+
*,
|
|
272
|
+
async_plan: bool = True,
|
|
273
|
+
brand_voice: Optional[str] = None,
|
|
274
|
+
persona_prompt: Optional[str] = None,
|
|
275
|
+
iterate: bool = False,
|
|
276
|
+
twin_id: Optional[str] = None,
|
|
277
|
+
context: Optional[Mapping[str, Any]] = None,
|
|
278
|
+
idempotency_key: Optional[str] = None,
|
|
279
|
+
**extra: Any,
|
|
280
|
+
) -> Dict[str, Any]:
|
|
281
|
+
"""Submit an end-to-end brand-grounded video job (``POST /video/create``)."""
|
|
282
|
+
if not ask or len(ask.strip()) < 3:
|
|
283
|
+
raise UseMoError("ask must be at least 3 characters.", code="invalid_input")
|
|
284
|
+
body: Dict[str, Any] = {
|
|
285
|
+
"ask": ask,
|
|
286
|
+
"async_plan": async_plan,
|
|
287
|
+
"iterate": iterate,
|
|
288
|
+
}
|
|
289
|
+
if brand_voice is not None:
|
|
290
|
+
body["brand_voice"] = brand_voice
|
|
291
|
+
if persona_prompt is not None:
|
|
292
|
+
body["persona_prompt"] = persona_prompt
|
|
293
|
+
if twin_id is not None:
|
|
294
|
+
body["twin_id"] = twin_id
|
|
295
|
+
if context is not None:
|
|
296
|
+
body["context"] = dict(context)
|
|
297
|
+
body.update(extra)
|
|
298
|
+
key = idempotency_key or str(uuid.uuid4())
|
|
299
|
+
result = self.request("POST", "/video/create", body=body, idempotency_key=key)
|
|
300
|
+
return {**result, "idempotency_key": key}
|
|
301
|
+
|
|
302
|
+
def talking_head(
|
|
303
|
+
self,
|
|
304
|
+
face_image_url: str,
|
|
305
|
+
lines: Iterable[str],
|
|
306
|
+
*,
|
|
307
|
+
voice_id: Optional[str] = None,
|
|
308
|
+
aspect_ratio: str = "16:9",
|
|
309
|
+
idempotency_key: Optional[str] = None,
|
|
310
|
+
**extra: Any,
|
|
311
|
+
) -> Dict[str, Any]:
|
|
312
|
+
"""Submit a gated multi-shot talking-head job (``POST /video/talking-head``)."""
|
|
313
|
+
line_list = [str(line) for line in lines if str(line).strip()]
|
|
314
|
+
if not face_image_url or not face_image_url.strip():
|
|
315
|
+
raise UseMoError("face_image_url is required.", code="invalid_input")
|
|
316
|
+
if not line_list:
|
|
317
|
+
raise UseMoError("lines must contain at least one spoken line.", code="invalid_input")
|
|
318
|
+
body: Dict[str, Any] = {
|
|
319
|
+
"face_image_url": face_image_url,
|
|
320
|
+
"lines": line_list,
|
|
321
|
+
"aspect_ratio": aspect_ratio,
|
|
322
|
+
}
|
|
323
|
+
if voice_id is not None:
|
|
324
|
+
body["voice_id"] = voice_id
|
|
325
|
+
body.update(extra)
|
|
326
|
+
key = idempotency_key or str(uuid.uuid4())
|
|
327
|
+
result = self.request("POST", "/video/talking-head", body=body, idempotency_key=key)
|
|
328
|
+
return {**result, "idempotency_key": key}
|
|
329
|
+
|
|
330
|
+
def get_job(self, job_id: str) -> Dict[str, Any]:
|
|
331
|
+
"""Fetch status and outputs for an asynchronous job (``GET /jobs/{job_id}``)."""
|
|
332
|
+
if not job_id or not job_id.strip() or "/" in job_id or job_id in (".", ".."):
|
|
333
|
+
raise UseMoError("job_id must be a valid identifier.", code="invalid_input")
|
|
334
|
+
encoded = urllib.parse.quote(job_id.strip(), safe="")
|
|
335
|
+
return self.request("GET", f"/jobs/{encoded}")
|
|
336
|
+
|
|
337
|
+
def wait_for_job(
|
|
338
|
+
self,
|
|
339
|
+
job_id: str,
|
|
340
|
+
*,
|
|
341
|
+
timeout: float = 180.0,
|
|
342
|
+
poll_interval: float = 5.0,
|
|
343
|
+
) -> Dict[str, Any]:
|
|
344
|
+
"""Poll ``get_job`` until completion. Timeout never cancels the remote job."""
|
|
345
|
+
if timeout <= 0 or poll_interval <= 0:
|
|
346
|
+
raise UseMoError("timeout and poll_interval must be positive.", code="invalid_input")
|
|
347
|
+
deadline = time.monotonic() + timeout
|
|
348
|
+
last: Optional[Dict[str, Any]] = None
|
|
349
|
+
while time.monotonic() < deadline:
|
|
350
|
+
last = self.get_job(job_id)
|
|
351
|
+
status = str(last.get("status", "")).lower()
|
|
352
|
+
if status in TERMINAL_STATUSES:
|
|
353
|
+
if status != "completed":
|
|
354
|
+
raise UseMoError(
|
|
355
|
+
f"Job {job_id} ended with status '{status}'.",
|
|
356
|
+
code="job_failed",
|
|
357
|
+
detail=last,
|
|
358
|
+
)
|
|
359
|
+
return last
|
|
360
|
+
remaining = deadline - time.monotonic()
|
|
361
|
+
if remaining <= 0:
|
|
362
|
+
break
|
|
363
|
+
time.sleep(min(poll_interval, remaining))
|
|
364
|
+
raise UseMoError(
|
|
365
|
+
"Timed out waiting for job; remote job was not cancelled. Call get_job() to resume.",
|
|
366
|
+
code="wait_timeout",
|
|
367
|
+
detail=last,
|
|
368
|
+
)
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: usemo
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Minimal zero-dependency Python client and CLI for the UseMo AI creative API.
|
|
5
|
+
Project-URL: Homepage, https://usemo.com/agents
|
|
6
|
+
Project-URL: Documentation, https://usemo.com/agents/start.md
|
|
7
|
+
Project-URL: Repository, https://github.com/gaufire/usemo-mcp
|
|
8
|
+
Project-URL: Issues, https://github.com/gaufire/usemo-mcp/issues
|
|
9
|
+
Author-email: UseMo <support@usemo.com>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: ad-creative,ai-video,digital-twin,image-generation,mcp,talking-head,usemo
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Requires-Python: >=3.9
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# usemo
|
|
27
|
+
|
|
28
|
+
Minimal, zero-dependency Python client and CLI for the UseMo AI creative API (`https://api.usemo.com/api/v1`).
|
|
29
|
+
|
|
30
|
+
UseMo runs open-source and third-party base models (FLUX, SDXL, Wan, Qwen, Seedance, Seedream) inside a workspace-scoped pipeline with Brand Hub context and automated quality gates. Failed renders are refunded automatically.
|
|
31
|
+
|
|
32
|
+
- **Job Router (start here):** [https://usemo.com/agents/start.md](https://usemo.com/agents/start.md)
|
|
33
|
+
- **Agent & API Hub:** [https://usemo.com/agents](https://usemo.com/agents)
|
|
34
|
+
- **Hosted Streamable HTTP MCP (OAuth 2.1):** `https://api.usemo.com/mcp`
|
|
35
|
+
- **Universal Host Configs & Skills:** [https://github.com/gaufire/usemo-mcp](https://github.com/gaufire/usemo-mcp)
|
|
36
|
+
|
|
37
|
+
## Install
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install usemo
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Quickstart
|
|
44
|
+
|
|
45
|
+
Create a workspace API key (`usm_...`) in `https://app.usemo.com/settings` and set `USEMO_API_KEY`:
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
import os
|
|
49
|
+
from usemo import UseMoClient
|
|
50
|
+
|
|
51
|
+
client = UseMoClient(api_key=os.environ["USEMO_API_KEY"])
|
|
52
|
+
|
|
53
|
+
# 1. Verify workspace & credits (read-only)
|
|
54
|
+
me = client.whoami()
|
|
55
|
+
|
|
56
|
+
# 2. Estimate cost before rendering
|
|
57
|
+
quote = client.estimate_cost(lines=["Morning. Here is our Q4 update."])
|
|
58
|
+
|
|
59
|
+
# 3. Submit an idempotent image or video job
|
|
60
|
+
job = client.generate_image(
|
|
61
|
+
"studio product photo of a ceramic coffee mug on warm oak",
|
|
62
|
+
aspect_ratio="1:1",
|
|
63
|
+
idempotency_key="mug-hero-001",
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
# 4. Poll job status
|
|
67
|
+
status = client.get_job(job["job_id"])
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Video & Talking-Head Methods
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
video = client.create_video(
|
|
74
|
+
"15-second product launch video for our API platform",
|
|
75
|
+
idempotency_key="launch-001",
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
th = client.talking_head(
|
|
79
|
+
face_image_url="https://example.com/presenter.jpg",
|
|
80
|
+
lines=["Thanks, that works for me."],
|
|
81
|
+
voice_id="onyx",
|
|
82
|
+
idempotency_key="th-001",
|
|
83
|
+
)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### CLI Usage
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
export USEMO_API_KEY="usm_..."
|
|
90
|
+
usemo whoami
|
|
91
|
+
usemo estimate-cost --line "Hello from UseMo."
|
|
92
|
+
usemo generate-image "matte bottle on warm oak" --aspect-ratio 1:1
|
|
93
|
+
usemo get-job <job_id>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Identity, Voice & Likeness Authorization
|
|
97
|
+
|
|
98
|
+
Digital twins, voice cloning, and portrait or face swaps require explicit documented authorization (`consent_confirmed: true` for adult face swaps and verified durable consent records for twins) and return HTTP `422` when authorization is missing or out of policy.
|
|
99
|
+
|
|
100
|
+
## License
|
|
101
|
+
|
|
102
|
+
MIT
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
usemo/__init__.py,sha256=p0KFXR8GsGX-7B50ogPZtLhvzP1QK1iD6ZZt5IW8LHI,228
|
|
2
|
+
usemo/cli.py,sha256=BKc95OdWrePBmyP-jUpeYctmfuzeRFdosI7M05j1v90,4791
|
|
3
|
+
usemo/client.py,sha256=L9CCp4xlO_GEYb12hmB2fnYzpNWRiKoHZpyapz-giYc,13813
|
|
4
|
+
usemo-0.1.1.dist-info/METADATA,sha256=PlTApfToZHv8TLg--OAFi_AFajQTRcxdPpGS0vbRP2E,3432
|
|
5
|
+
usemo-0.1.1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
6
|
+
usemo-0.1.1.dist-info/entry_points.txt,sha256=PfN1zL85-G_n2gBwTSelqRj-D4p6nXiT5ga957U12_Y,41
|
|
7
|
+
usemo-0.1.1.dist-info/licenses/LICENSE,sha256=FsKj0Igwx-3ijspdkY8m8lxVM_4_IGoc1dTa8aLXK3s,1062
|
|
8
|
+
usemo-0.1.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 UseMo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|