runware-sdk 1.9.0__tar.gz → 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/PKG-INFO +74 -18
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/README.md +72 -16
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/pyproject.toml +2 -2
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/pyproject.toml.orig +2 -2
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/runware/__init__.py +10 -0
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/runware/_schemas_version.py +1 -1
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/runware/client.py +652 -169
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/runware/errors.py +12 -1
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/runware/stream.py +7 -1
- runware_sdk-2.0.0/runware/sync.py +775 -0
- runware_sdk-2.0.0/runware/transport/resend.py +130 -0
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/runware/transport/rest.py +141 -30
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/runware/transport/websocket.py +84 -55
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/runware/types/sdk.py +19 -1
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/runware/types/task_map.py +7367 -6736
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/runware/utils/retry.py +4 -1
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/LICENSE +0 -0
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/runware/_docs_cache.py +0 -0
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/runware/config.py +0 -0
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/runware/constants.py +0 -0
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/runware/content.py +0 -0
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/runware/logger.py +0 -0
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/runware/py.typed +0 -0
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/runware/registry.py +0 -0
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/runware/serverless.py +0 -0
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/runware/transport/__init__.py +0 -0
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/runware/types/__init__.py +0 -0
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/runware/types/content.py +0 -0
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/runware/types/serverless.py +0 -0
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/runware/types/stream.py +0 -0
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/runware/types/transport.py +0 -0
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/runware/user_agent.py +0 -0
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/runware/utils/__init__.py +0 -0
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/runware/utils/file.py +0 -0
- {runware_sdk-1.9.0 → runware_sdk-2.0.0}/runware/validate.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: runware-sdk
|
|
3
|
-
Version:
|
|
3
|
+
Version: 2.0.0
|
|
4
4
|
Summary: Async Python SDK for the Runware platform — image, video, audio, text, and 3D generation, plus upscaling, background removal, and more, over REST or WebSocket with typed parameters and runtime validation.
|
|
5
5
|
Keywords: runware,ai,sdk,image-generation,video-generation,audio-generation,text-generation,inference,generative-ai,stable-diffusion,flux,websocket,async,asyncio,llm,streaming
|
|
6
6
|
Author: Runware
|
|
@@ -27,7 +27,7 @@ Classifier: Typing :: Typed
|
|
|
27
27
|
Requires-Dist: aiohttp>=3.10
|
|
28
28
|
Requires-Dist: websockets>=13
|
|
29
29
|
Requires-Dist: fastjsonschema>=2.20
|
|
30
|
-
Requires-Dist: typing-extensions>=4.
|
|
30
|
+
Requires-Dist: typing-extensions>=4.12
|
|
31
31
|
Requires-Python: >=3.11
|
|
32
32
|
Project-URL: Homepage, https://runware.ai
|
|
33
33
|
Project-URL: Documentation, https://runware.ai/docs
|
|
@@ -38,7 +38,7 @@ Description-Content-Type: text/markdown
|
|
|
38
38
|
|
|
39
39
|
# Runware Python SDK
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
Python SDK for the Runware platform. A unified API for image, video, audio, text, and 3D generation — powered by the [Runware inference platform](https://runware.ai).
|
|
42
42
|
|
|
43
43
|
[Documentation](https://runware.ai/docs) · [Report a bug](https://github.com/runware/runware-python/issues)
|
|
44
44
|
|
|
@@ -47,7 +47,7 @@ Async Python SDK for the Runware platform. A unified API for image, video, audio
|
|
|
47
47
|
- **WebSocket and REST transports** — persistent connections or stateless HTTP
|
|
48
48
|
- **LLM streaming via SSE** — token-by-token text generation with `.stream()`
|
|
49
49
|
- **Automatic model resolution** — the SDK resolves task types from AIR identifiers
|
|
50
|
-
- **Python 3.11+,
|
|
50
|
+
- **Python 3.11+, async or blocking** — `Runware` for asyncio, `SyncRunware` for scripts and notebooks
|
|
51
51
|
|
|
52
52
|
|
|
53
53
|
## Installation
|
|
@@ -60,6 +60,21 @@ pip install runware-sdk
|
|
|
60
60
|
|
|
61
61
|
Generate an image in five lines:
|
|
62
62
|
|
|
63
|
+
```python
|
|
64
|
+
from runware import SyncRunware
|
|
65
|
+
|
|
66
|
+
with SyncRunware() as client:
|
|
67
|
+
results = client.run({
|
|
68
|
+
"model": "runware:400@1",
|
|
69
|
+
"positivePrompt": "A serene mountain landscape at sunset",
|
|
70
|
+
"width": 1024,
|
|
71
|
+
"height": 1024,
|
|
72
|
+
})
|
|
73
|
+
print(results[0]["imageURL"])
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
In async code, use `Runware` and `await` the same methods:
|
|
77
|
+
|
|
63
78
|
```python
|
|
64
79
|
import asyncio
|
|
65
80
|
import os
|
|
@@ -82,11 +97,27 @@ The SDK resolves `runware:400@1` to the right task type automatically. `RUNWARE_
|
|
|
82
97
|
|
|
83
98
|
More runnable patterns in [`examples/`](./examples/) — curated models, community fine-tunes, streaming, the WebSocket transport.
|
|
84
99
|
|
|
100
|
+
### Blocking client
|
|
101
|
+
|
|
102
|
+
`SyncRunware` takes the same arguments as `Runware` and has the same methods and types, without `await`. A stream reads with a plain `for`:
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
with SyncRunware() as client:
|
|
106
|
+
stream = client.stream({
|
|
107
|
+
"model": "openai:gpt@5.5",
|
|
108
|
+
"messages": [{"role": "user", "content": "Tell me a story about a robot"}],
|
|
109
|
+
})
|
|
110
|
+
for word in stream.text_stream:
|
|
111
|
+
print(word, end="", flush=True)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
It runs the async client on an event loop of its own in a background thread, so it also works in a notebook or inside async code, where it blocks the calling loop while it waits, and the WebSocket stays open between calls. Calls from several threads share that loop. `on_result` and `on_progress` run on the client's thread, and calling the client from them raises an error. To stop a call, give it a `timeout` or press Ctrl-C, which cancels it, a stream included. `cancel_event` and a session passed in `dependencies` are bound to an event loop, so `SyncRunware` refuses them. Close the client with `with` or `close()`, from any thread: calls still running then fail with a `RunwareError`. One left open is closed when it is garbage collected or the program exits. A client works only in the process that created it, so a forked worker creates its own.
|
|
115
|
+
|
|
85
116
|
## Core Concepts
|
|
86
117
|
|
|
87
118
|
### One method for everything
|
|
88
119
|
|
|
89
|
-
Every inference task goes through `.run()`. The SDK determines the task type from the model's AIR identifier:
|
|
120
|
+
Every inference task goes through `.run()`, or through `.submit()` and `.result()` when you [collect it later](#submit-now-collect-later). The SDK determines the task type from the model's AIR identifier:
|
|
90
121
|
|
|
91
122
|
```python
|
|
92
123
|
# Image generation
|
|
@@ -107,7 +138,7 @@ videos = await client.run({
|
|
|
107
138
|
|
|
108
139
|
# Text inference (LLM)
|
|
109
140
|
responses = await client.run({
|
|
110
|
-
"model": "
|
|
141
|
+
"model": "openai:gpt@5.5",
|
|
111
142
|
"messages": [{"role": "user", "content": "Explain quantum computing"}],
|
|
112
143
|
})
|
|
113
144
|
|
|
@@ -179,7 +210,7 @@ For text models, `.stream()` delivers tokens as they're generated:
|
|
|
179
210
|
|
|
180
211
|
```python
|
|
181
212
|
stream = await client.stream({
|
|
182
|
-
"model": "
|
|
213
|
+
"model": "openai:gpt@5.5",
|
|
183
214
|
"messages": [{"role": "user", "content": "Tell me a story about a robot"}],
|
|
184
215
|
})
|
|
185
216
|
|
|
@@ -191,7 +222,7 @@ async for word in stream.text_stream:
|
|
|
191
222
|
|
|
192
223
|
```python
|
|
193
224
|
stream = await client.stream({
|
|
194
|
-
"model": "
|
|
225
|
+
"model": "openai:gpt@5.5",
|
|
195
226
|
"messages": [{"role": "user", "content": "Explain gravity"}],
|
|
196
227
|
})
|
|
197
228
|
|
|
@@ -228,7 +259,7 @@ async with Runware(transport="websocket") as client:
|
|
|
228
259
|
videos = await client.run({"model": "google:3@3", "positivePrompt": "...", "width": 1280, "height": 720})
|
|
229
260
|
```
|
|
230
261
|
|
|
231
|
-
WebSocket connections are automatically recovered on network interruptions. Requests made while the connection is down wait for it to come back. After a reconnect, the SDK sends again any read
|
|
262
|
+
WebSocket connections are automatically recovered on network interruptions. Requests made while the connection is down wait for it to come back. After a reconnect, the SDK sends again any read, and any async request the API refuses to run twice, that had no reply yet. A request that may already have run is never sent twice. A sync inference task with one result is read back with `getTaskDetails` until its timeout. Anything else that may have run (uploads, async text and audio, a sync task with several results) fails with a `connection` error and `retryable=False`.
|
|
232
263
|
|
|
233
264
|
### REST
|
|
234
265
|
|
|
@@ -270,11 +301,36 @@ async with Runware() as client:
|
|
|
270
301
|
)
|
|
271
302
|
```
|
|
272
303
|
|
|
304
|
+
## Submit now, collect later
|
|
305
|
+
|
|
306
|
+
`run()` waits for the results. To send a task and collect it later, from the same process or another, split it in two. `submit()` returns once the API has accepted the task, so a refused request fails there, and `result()` waits for its results as `run()` does:
|
|
307
|
+
|
|
308
|
+
```python
|
|
309
|
+
task = await client.submit({
|
|
310
|
+
"model": "google:3@3",
|
|
311
|
+
"positivePrompt": "Ocean waves at sunset",
|
|
312
|
+
"width": 1280,
|
|
313
|
+
"height": 720,
|
|
314
|
+
"duration": 8,
|
|
315
|
+
})
|
|
316
|
+
print(task.task_uuid) # keep it to collect the task later
|
|
317
|
+
|
|
318
|
+
videos = await client.result(task)
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
`task` is a `SubmittedTask` (`task_uuid`, `task_type`, `number_results`), and its type carries the result type. Another process waits for the same task with the taskUUID alone, and gets every result even without `number_results`:
|
|
322
|
+
|
|
323
|
+
```python
|
|
324
|
+
videos = await client.result(task_uuid)
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
A `cancel_event` or `timeout` on `result()` stops the wait, not the task, so a later `result()` picks it up again. A taskUUID the API has no record of fails with a `notFound` error after 30 seconds. To be told when the task finishes instead of waiting, put a `webhookURL` in the params. The task runs, and is billed, whether or not anything waits for it. `SyncRunware` has both methods without `await`.
|
|
328
|
+
|
|
273
329
|
## Cancellation
|
|
274
330
|
|
|
275
331
|
Pass an `asyncio.Event` and `.set()` it to cancel mid-flight. Works for `run()` and `stream()`, on both transports.
|
|
276
332
|
|
|
277
|
-
> **Heads-up:** cancel is client-side only. The server keeps processing the task and **you will be billed for it**. Cancelling just stops the SDK from waiting for the result.
|
|
333
|
+
> **Heads-up:** cancel is client-side only. The server keeps processing the task and **you will be billed for it**. Cancelling just stops the SDK from waiting for the result. The error carries the task's `task_uuid`, so `client.result(error.task_uuid)` can still collect it (see [Submit now, collect later](#submit-now-collect-later)).
|
|
278
334
|
|
|
279
335
|
```python
|
|
280
336
|
import asyncio
|
|
@@ -306,7 +362,7 @@ For streams, set the cancel event to end iteration:
|
|
|
306
362
|
from runware import StreamOptions
|
|
307
363
|
|
|
308
364
|
stream = await client.stream(
|
|
309
|
-
{"model": "
|
|
365
|
+
{"model": "openai:gpt@5.5", "messages": [{"role": "user", "content": "..."}]},
|
|
310
366
|
StreamOptions(cancel_event=cancel),
|
|
311
367
|
)
|
|
312
368
|
async for word in stream.text_stream:
|
|
@@ -357,7 +413,7 @@ async with Runware() as client:
|
|
|
357
413
|
})
|
|
358
414
|
except RunwareError as exc:
|
|
359
415
|
print(exc.code) # 'validation' | 'auth' | 'quota' | ...
|
|
360
|
-
print(exc.retryable) # True for provider/timeout/connection/rateLimit/serverError
|
|
416
|
+
print(exc.retryable) # True for provider/timeout/connection/rateLimit/serverError, unless the task may already have run
|
|
361
417
|
print(exc.message) # Human-readable description
|
|
362
418
|
print(exc.parameter) # Which param caused the error, if any
|
|
363
419
|
print(exc.documentation) # Link to model / utility / errors docs
|
|
@@ -419,7 +475,7 @@ The constructor derives `code` and `documentation` URL from the raw code + model
|
|
|
419
475
|
| `timeout` | `1_200_000` (ms) | per-HTTP-call (one POST, one `getResponse` poll) |
|
|
420
476
|
| `poll_timeout` | `1_200_000` (ms) | end-to-end polling budget on either transport |
|
|
421
477
|
| `auth_timeout` | `15_000` (ms) | WebSocket auth handshake |
|
|
422
|
-
| `max_retries` | `3` | REST retries. A sync
|
|
478
|
+
| `max_retries` | `3` | REST retries after a timeout, a network error, a 5xx, a 408 or a 429. A request that could run twice (sync tasks, uploads, async text and audio) is resent only when it never reached the API (408, 429, or a connection that never opened). When its outcome is unknown, a sync inference task with one result is read back with `getTaskDetails`, and anything else fails with `retryable=False` and the `task_uuid` to read its result |
|
|
423
479
|
| `retry_delay` | `1_000` (ms) | base backoff |
|
|
424
480
|
| `retry_strategy` | `"exponential"` | or `"linear"` |
|
|
425
481
|
| `max_reconnect_attempts` | `inf` | WebSocket reconnect cap |
|
|
@@ -481,7 +537,7 @@ For fast tasks (text inference, fast image gen, captioning) you can skip the pol
|
|
|
481
537
|
|
|
482
538
|
```python
|
|
483
539
|
responses = await client.run({
|
|
484
|
-
"model": "
|
|
540
|
+
"model": "openai:gpt@5.5",
|
|
485
541
|
"messages": [{"role": "user", "content": "Hello"}],
|
|
486
542
|
"deliveryMethod": "sync",
|
|
487
543
|
})
|
|
@@ -502,7 +558,7 @@ from runware import RunOptions
|
|
|
502
558
|
await client.run(
|
|
503
559
|
{"model": "runware:400@1", "positivePrompt": "A landscape"},
|
|
504
560
|
RunOptions(
|
|
505
|
-
timeout=600_000, # ms — override config.poll_timeout for this call
|
|
561
|
+
timeout=600_000, # ms — override config.poll_timeout, and config.timeout for each REST request, for this call
|
|
506
562
|
cancel_event=cancel, # asyncio.Event — cancel this call
|
|
507
563
|
on_result=watch, # fires per item as it completes
|
|
508
564
|
on_progress=progress, # fires when an item's progress % changes
|
|
@@ -583,8 +639,8 @@ account = await client.account_management({"operation": "getDetails"})
|
|
|
583
639
|
# Retrieve a previously executed task
|
|
584
640
|
archived = await client.get_task_details({"taskUUID": "abc-123"})
|
|
585
641
|
|
|
586
|
-
#
|
|
587
|
-
|
|
642
|
+
# Read where an async task stands right now: one row per result, with its status
|
|
643
|
+
rows = await client.get_response({"taskUUID": "abc-123"})
|
|
588
644
|
|
|
589
645
|
# Upload a custom model
|
|
590
646
|
await client.model_upload({
|
|
@@ -595,7 +651,7 @@ await client.model_upload({
|
|
|
595
651
|
})
|
|
596
652
|
```
|
|
597
653
|
|
|
598
|
-
`get_task_details` vs `get_response`: use `get_task_details` for "look up something I ran before" — it queries the task archive. `get_response`
|
|
654
|
+
`get_task_details` vs `get_response`: use `get_task_details` for "look up something I ran before" — it queries the task archive. `get_response` reads where an async task stands right now, one row per result with its `status`. To wait for the results, use `result()` (see [Submit now, collect later](#submit-now-collect-later)).
|
|
599
655
|
|
|
600
656
|
## Serverless apps
|
|
601
657
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Runware Python SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Python SDK for the Runware platform. A unified API for image, video, audio, text, and 3D generation — powered by the [Runware inference platform](https://runware.ai).
|
|
4
4
|
|
|
5
5
|
[Documentation](https://runware.ai/docs) · [Report a bug](https://github.com/runware/runware-python/issues)
|
|
6
6
|
|
|
@@ -9,7 +9,7 @@ Async Python SDK for the Runware platform. A unified API for image, video, audio
|
|
|
9
9
|
- **WebSocket and REST transports** — persistent connections or stateless HTTP
|
|
10
10
|
- **LLM streaming via SSE** — token-by-token text generation with `.stream()`
|
|
11
11
|
- **Automatic model resolution** — the SDK resolves task types from AIR identifiers
|
|
12
|
-
- **Python 3.11+,
|
|
12
|
+
- **Python 3.11+, async or blocking** — `Runware` for asyncio, `SyncRunware` for scripts and notebooks
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
## Installation
|
|
@@ -22,6 +22,21 @@ pip install runware-sdk
|
|
|
22
22
|
|
|
23
23
|
Generate an image in five lines:
|
|
24
24
|
|
|
25
|
+
```python
|
|
26
|
+
from runware import SyncRunware
|
|
27
|
+
|
|
28
|
+
with SyncRunware() as client:
|
|
29
|
+
results = client.run({
|
|
30
|
+
"model": "runware:400@1",
|
|
31
|
+
"positivePrompt": "A serene mountain landscape at sunset",
|
|
32
|
+
"width": 1024,
|
|
33
|
+
"height": 1024,
|
|
34
|
+
})
|
|
35
|
+
print(results[0]["imageURL"])
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
In async code, use `Runware` and `await` the same methods:
|
|
39
|
+
|
|
25
40
|
```python
|
|
26
41
|
import asyncio
|
|
27
42
|
import os
|
|
@@ -44,11 +59,27 @@ The SDK resolves `runware:400@1` to the right task type automatically. `RUNWARE_
|
|
|
44
59
|
|
|
45
60
|
More runnable patterns in [`examples/`](./examples/) — curated models, community fine-tunes, streaming, the WebSocket transport.
|
|
46
61
|
|
|
62
|
+
### Blocking client
|
|
63
|
+
|
|
64
|
+
`SyncRunware` takes the same arguments as `Runware` and has the same methods and types, without `await`. A stream reads with a plain `for`:
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
with SyncRunware() as client:
|
|
68
|
+
stream = client.stream({
|
|
69
|
+
"model": "openai:gpt@5.5",
|
|
70
|
+
"messages": [{"role": "user", "content": "Tell me a story about a robot"}],
|
|
71
|
+
})
|
|
72
|
+
for word in stream.text_stream:
|
|
73
|
+
print(word, end="", flush=True)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
It runs the async client on an event loop of its own in a background thread, so it also works in a notebook or inside async code, where it blocks the calling loop while it waits, and the WebSocket stays open between calls. Calls from several threads share that loop. `on_result` and `on_progress` run on the client's thread, and calling the client from them raises an error. To stop a call, give it a `timeout` or press Ctrl-C, which cancels it, a stream included. `cancel_event` and a session passed in `dependencies` are bound to an event loop, so `SyncRunware` refuses them. Close the client with `with` or `close()`, from any thread: calls still running then fail with a `RunwareError`. One left open is closed when it is garbage collected or the program exits. A client works only in the process that created it, so a forked worker creates its own.
|
|
77
|
+
|
|
47
78
|
## Core Concepts
|
|
48
79
|
|
|
49
80
|
### One method for everything
|
|
50
81
|
|
|
51
|
-
Every inference task goes through `.run()`. The SDK determines the task type from the model's AIR identifier:
|
|
82
|
+
Every inference task goes through `.run()`, or through `.submit()` and `.result()` when you [collect it later](#submit-now-collect-later). The SDK determines the task type from the model's AIR identifier:
|
|
52
83
|
|
|
53
84
|
```python
|
|
54
85
|
# Image generation
|
|
@@ -69,7 +100,7 @@ videos = await client.run({
|
|
|
69
100
|
|
|
70
101
|
# Text inference (LLM)
|
|
71
102
|
responses = await client.run({
|
|
72
|
-
"model": "
|
|
103
|
+
"model": "openai:gpt@5.5",
|
|
73
104
|
"messages": [{"role": "user", "content": "Explain quantum computing"}],
|
|
74
105
|
})
|
|
75
106
|
|
|
@@ -141,7 +172,7 @@ For text models, `.stream()` delivers tokens as they're generated:
|
|
|
141
172
|
|
|
142
173
|
```python
|
|
143
174
|
stream = await client.stream({
|
|
144
|
-
"model": "
|
|
175
|
+
"model": "openai:gpt@5.5",
|
|
145
176
|
"messages": [{"role": "user", "content": "Tell me a story about a robot"}],
|
|
146
177
|
})
|
|
147
178
|
|
|
@@ -153,7 +184,7 @@ async for word in stream.text_stream:
|
|
|
153
184
|
|
|
154
185
|
```python
|
|
155
186
|
stream = await client.stream({
|
|
156
|
-
"model": "
|
|
187
|
+
"model": "openai:gpt@5.5",
|
|
157
188
|
"messages": [{"role": "user", "content": "Explain gravity"}],
|
|
158
189
|
})
|
|
159
190
|
|
|
@@ -190,7 +221,7 @@ async with Runware(transport="websocket") as client:
|
|
|
190
221
|
videos = await client.run({"model": "google:3@3", "positivePrompt": "...", "width": 1280, "height": 720})
|
|
191
222
|
```
|
|
192
223
|
|
|
193
|
-
WebSocket connections are automatically recovered on network interruptions. Requests made while the connection is down wait for it to come back. After a reconnect, the SDK sends again any read
|
|
224
|
+
WebSocket connections are automatically recovered on network interruptions. Requests made while the connection is down wait for it to come back. After a reconnect, the SDK sends again any read, and any async request the API refuses to run twice, that had no reply yet. A request that may already have run is never sent twice. A sync inference task with one result is read back with `getTaskDetails` until its timeout. Anything else that may have run (uploads, async text and audio, a sync task with several results) fails with a `connection` error and `retryable=False`.
|
|
194
225
|
|
|
195
226
|
### REST
|
|
196
227
|
|
|
@@ -232,11 +263,36 @@ async with Runware() as client:
|
|
|
232
263
|
)
|
|
233
264
|
```
|
|
234
265
|
|
|
266
|
+
## Submit now, collect later
|
|
267
|
+
|
|
268
|
+
`run()` waits for the results. To send a task and collect it later, from the same process or another, split it in two. `submit()` returns once the API has accepted the task, so a refused request fails there, and `result()` waits for its results as `run()` does:
|
|
269
|
+
|
|
270
|
+
```python
|
|
271
|
+
task = await client.submit({
|
|
272
|
+
"model": "google:3@3",
|
|
273
|
+
"positivePrompt": "Ocean waves at sunset",
|
|
274
|
+
"width": 1280,
|
|
275
|
+
"height": 720,
|
|
276
|
+
"duration": 8,
|
|
277
|
+
})
|
|
278
|
+
print(task.task_uuid) # keep it to collect the task later
|
|
279
|
+
|
|
280
|
+
videos = await client.result(task)
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
`task` is a `SubmittedTask` (`task_uuid`, `task_type`, `number_results`), and its type carries the result type. Another process waits for the same task with the taskUUID alone, and gets every result even without `number_results`:
|
|
284
|
+
|
|
285
|
+
```python
|
|
286
|
+
videos = await client.result(task_uuid)
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
A `cancel_event` or `timeout` on `result()` stops the wait, not the task, so a later `result()` picks it up again. A taskUUID the API has no record of fails with a `notFound` error after 30 seconds. To be told when the task finishes instead of waiting, put a `webhookURL` in the params. The task runs, and is billed, whether or not anything waits for it. `SyncRunware` has both methods without `await`.
|
|
290
|
+
|
|
235
291
|
## Cancellation
|
|
236
292
|
|
|
237
293
|
Pass an `asyncio.Event` and `.set()` it to cancel mid-flight. Works for `run()` and `stream()`, on both transports.
|
|
238
294
|
|
|
239
|
-
> **Heads-up:** cancel is client-side only. The server keeps processing the task and **you will be billed for it**. Cancelling just stops the SDK from waiting for the result.
|
|
295
|
+
> **Heads-up:** cancel is client-side only. The server keeps processing the task and **you will be billed for it**. Cancelling just stops the SDK from waiting for the result. The error carries the task's `task_uuid`, so `client.result(error.task_uuid)` can still collect it (see [Submit now, collect later](#submit-now-collect-later)).
|
|
240
296
|
|
|
241
297
|
```python
|
|
242
298
|
import asyncio
|
|
@@ -268,7 +324,7 @@ For streams, set the cancel event to end iteration:
|
|
|
268
324
|
from runware import StreamOptions
|
|
269
325
|
|
|
270
326
|
stream = await client.stream(
|
|
271
|
-
{"model": "
|
|
327
|
+
{"model": "openai:gpt@5.5", "messages": [{"role": "user", "content": "..."}]},
|
|
272
328
|
StreamOptions(cancel_event=cancel),
|
|
273
329
|
)
|
|
274
330
|
async for word in stream.text_stream:
|
|
@@ -319,7 +375,7 @@ async with Runware() as client:
|
|
|
319
375
|
})
|
|
320
376
|
except RunwareError as exc:
|
|
321
377
|
print(exc.code) # 'validation' | 'auth' | 'quota' | ...
|
|
322
|
-
print(exc.retryable) # True for provider/timeout/connection/rateLimit/serverError
|
|
378
|
+
print(exc.retryable) # True for provider/timeout/connection/rateLimit/serverError, unless the task may already have run
|
|
323
379
|
print(exc.message) # Human-readable description
|
|
324
380
|
print(exc.parameter) # Which param caused the error, if any
|
|
325
381
|
print(exc.documentation) # Link to model / utility / errors docs
|
|
@@ -381,7 +437,7 @@ The constructor derives `code` and `documentation` URL from the raw code + model
|
|
|
381
437
|
| `timeout` | `1_200_000` (ms) | per-HTTP-call (one POST, one `getResponse` poll) |
|
|
382
438
|
| `poll_timeout` | `1_200_000` (ms) | end-to-end polling budget on either transport |
|
|
383
439
|
| `auth_timeout` | `15_000` (ms) | WebSocket auth handshake |
|
|
384
|
-
| `max_retries` | `3` | REST retries. A sync
|
|
440
|
+
| `max_retries` | `3` | REST retries after a timeout, a network error, a 5xx, a 408 or a 429. A request that could run twice (sync tasks, uploads, async text and audio) is resent only when it never reached the API (408, 429, or a connection that never opened). When its outcome is unknown, a sync inference task with one result is read back with `getTaskDetails`, and anything else fails with `retryable=False` and the `task_uuid` to read its result |
|
|
385
441
|
| `retry_delay` | `1_000` (ms) | base backoff |
|
|
386
442
|
| `retry_strategy` | `"exponential"` | or `"linear"` |
|
|
387
443
|
| `max_reconnect_attempts` | `inf` | WebSocket reconnect cap |
|
|
@@ -443,7 +499,7 @@ For fast tasks (text inference, fast image gen, captioning) you can skip the pol
|
|
|
443
499
|
|
|
444
500
|
```python
|
|
445
501
|
responses = await client.run({
|
|
446
|
-
"model": "
|
|
502
|
+
"model": "openai:gpt@5.5",
|
|
447
503
|
"messages": [{"role": "user", "content": "Hello"}],
|
|
448
504
|
"deliveryMethod": "sync",
|
|
449
505
|
})
|
|
@@ -464,7 +520,7 @@ from runware import RunOptions
|
|
|
464
520
|
await client.run(
|
|
465
521
|
{"model": "runware:400@1", "positivePrompt": "A landscape"},
|
|
466
522
|
RunOptions(
|
|
467
|
-
timeout=600_000, # ms — override config.poll_timeout for this call
|
|
523
|
+
timeout=600_000, # ms — override config.poll_timeout, and config.timeout for each REST request, for this call
|
|
468
524
|
cancel_event=cancel, # asyncio.Event — cancel this call
|
|
469
525
|
on_result=watch, # fires per item as it completes
|
|
470
526
|
on_progress=progress, # fires when an item's progress % changes
|
|
@@ -545,8 +601,8 @@ account = await client.account_management({"operation": "getDetails"})
|
|
|
545
601
|
# Retrieve a previously executed task
|
|
546
602
|
archived = await client.get_task_details({"taskUUID": "abc-123"})
|
|
547
603
|
|
|
548
|
-
#
|
|
549
|
-
|
|
604
|
+
# Read where an async task stands right now: one row per result, with its status
|
|
605
|
+
rows = await client.get_response({"taskUUID": "abc-123"})
|
|
550
606
|
|
|
551
607
|
# Upload a custom model
|
|
552
608
|
await client.model_upload({
|
|
@@ -557,7 +613,7 @@ await client.model_upload({
|
|
|
557
613
|
})
|
|
558
614
|
```
|
|
559
615
|
|
|
560
|
-
`get_task_details` vs `get_response`: use `get_task_details` for "look up something I ran before" — it queries the task archive. `get_response`
|
|
616
|
+
`get_task_details` vs `get_response`: use `get_task_details` for "look up something I ran before" — it queries the task archive. `get_response` reads where an async task stands right now, one row per result with its `status`. To wait for the results, use `result()` (see [Submit now, collect later](#submit-now-collect-later)).
|
|
561
617
|
|
|
562
618
|
## Serverless apps
|
|
563
619
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "runware-sdk"
|
|
3
|
-
version = "
|
|
3
|
+
version = "2.0.0"
|
|
4
4
|
description = "Async Python SDK for the Runware platform — image, video, audio, text, and 3D generation, plus upscaling, background removal, and more, over REST or WebSocket with typed parameters and runtime validation."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.11"
|
|
@@ -47,7 +47,7 @@ dependencies = [
|
|
|
47
47
|
"aiohttp>=3.10",
|
|
48
48
|
"websockets>=13",
|
|
49
49
|
"fastjsonschema>=2.20",
|
|
50
|
-
"typing-extensions>=4.
|
|
50
|
+
"typing-extensions>=4.12",
|
|
51
51
|
]
|
|
52
52
|
|
|
53
53
|
[[project.authors]]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "runware-sdk"
|
|
3
|
-
version = "
|
|
3
|
+
version = "2.0.0"
|
|
4
4
|
description = "Async Python SDK for the Runware platform — image, video, audio, text, and 3D generation, plus upscaling, background removal, and more, over REST or WebSocket with typed parameters and runtime validation."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.11"
|
|
@@ -49,7 +49,7 @@ dependencies = [
|
|
|
49
49
|
"aiohttp>=3.10",
|
|
50
50
|
"websockets>=13",
|
|
51
51
|
"fastjsonschema>=2.20",
|
|
52
|
-
"typing-extensions>=4.
|
|
52
|
+
"typing-extensions>=4.12",
|
|
53
53
|
]
|
|
54
54
|
|
|
55
55
|
[project.urls]
|
|
@@ -5,6 +5,9 @@ Public surface mirrors the TypeScript SDK's exports.
|
|
|
5
5
|
|
|
6
6
|
Client:
|
|
7
7
|
Runware — async client class
|
|
8
|
+
SyncRunware — blocking client class, the same methods without await
|
|
9
|
+
SyncTextStream — what SyncRunware.stream() returns
|
|
10
|
+
SyncContentClient — SyncRunware.content
|
|
8
11
|
|
|
9
12
|
Errors:
|
|
10
13
|
RunwareError — exception class for all SDK errors
|
|
@@ -18,6 +21,7 @@ Options & config:
|
|
|
18
21
|
TransportType — "websocket" or "rest"
|
|
19
22
|
RetryStrategy — "linear" or "exponential"
|
|
20
23
|
RunOptions — per-call options for client.run()
|
|
24
|
+
SubmittedTask — what client.submit() returns, for client.result()
|
|
21
25
|
StreamOptions — per-call options for client.stream()
|
|
22
26
|
RuntimeDependencies — inject custom aiohttp session / WS connect
|
|
23
27
|
WebSocketConnectFactory — type alias for the WS connect callable
|
|
@@ -77,6 +81,7 @@ from .errors import (
|
|
|
77
81
|
from .logger import LogCategory, LogEntry, Logger, LogSink, create_logger
|
|
78
82
|
from .registry import Registry, RegistryData, RegistryModelEntry, create_registry
|
|
79
83
|
from .stream import TextStream, parse_sse_line
|
|
84
|
+
from .sync import SyncContentClient, SyncRunware, SyncTextStream
|
|
80
85
|
from .types.content import (
|
|
81
86
|
ArchitectureMetadata,
|
|
82
87
|
Capability,
|
|
@@ -100,6 +105,7 @@ from .types.sdk import (
|
|
|
100
105
|
RuntimeDependencies,
|
|
101
106
|
SDKConfig,
|
|
102
107
|
StreamOptions,
|
|
108
|
+
SubmittedTask,
|
|
103
109
|
TransportType,
|
|
104
110
|
WebSocketConnectFactory,
|
|
105
111
|
)
|
|
@@ -267,6 +273,10 @@ __all__ = [
|
|
|
267
273
|
"SDKConfig",
|
|
268
274
|
"ServerlessTask",
|
|
269
275
|
"StreamOptions",
|
|
276
|
+
"SubmittedTask",
|
|
277
|
+
"SyncContentClient",
|
|
278
|
+
"SyncRunware",
|
|
279
|
+
"SyncTextStream",
|
|
270
280
|
"TaskStatus",
|
|
271
281
|
"TaskType",
|
|
272
282
|
"TextInferenceParams",
|