relaygpu-client 0.1.3__tar.gz → 0.1.4__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.
Files changed (60) hide show
  1. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/CHANGELOG.md +27 -0
  2. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/PKG-INFO +61 -19
  3. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/README.md +60 -18
  4. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/pyproject.toml +1 -1
  5. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/__init__.py +1 -0
  6. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_async/account.py +25 -0
  7. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_async/client.py +41 -5
  8. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_async/keys.py +5 -2
  9. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_async/models.py +15 -9
  10. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_async/run.py +13 -8
  11. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_errors.py +6 -7
  12. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_exceptions.py +8 -0
  13. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_generated/models_map.py +16 -5
  14. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_generated/types.py +205 -4
  15. relaygpu_client-0.1.4/relaygpu/_responses.py +21 -0
  16. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_run_common.py +1 -0
  17. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_sync/account.py +25 -0
  18. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_sync/client.py +41 -5
  19. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_sync/keys.py +5 -2
  20. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_sync/models.py +15 -9
  21. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_sync/run.py +13 -8
  22. relaygpu_client-0.1.4/relaygpu/_version.py +1 -0
  23. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/types.py +5 -0
  24. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/webhooks.py +4 -0
  25. relaygpu_client-0.1.3/relaygpu/_version.py +0 -1
  26. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/.gitignore +0 -0
  27. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/LICENSE +0 -0
  28. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_async/__init__.py +0 -0
  29. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_async/_http.py +0 -0
  30. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_async/audio.py +0 -0
  31. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_async/estimate.py +0 -0
  32. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_async/files.py +0 -0
  33. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_async/image.py +0 -0
  34. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_async/tasks.py +0 -0
  35. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_async/video.py +0 -0
  36. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_async/webhooks.py +0 -0
  37. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_async/workflows.py +0 -0
  38. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_clock.py +0 -0
  39. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_core.py +0 -0
  40. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_estimate.py +0 -0
  41. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_generated/__init__.py +0 -0
  42. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_generated/error_codes.py +0 -0
  43. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_images.py +0 -0
  44. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_shapes.py +0 -0
  45. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_sync/__init__.py +0 -0
  46. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_sync/_http.py +0 -0
  47. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_sync/audio.py +0 -0
  48. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_sync/estimate.py +0 -0
  49. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_sync/files.py +0 -0
  50. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_sync/image.py +0 -0
  51. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_sync/tasks.py +0 -0
  52. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_sync/video.py +0 -0
  53. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_sync/webhooks.py +0 -0
  54. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_sync/workflows.py +0 -0
  55. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/_util.py +0 -0
  56. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/async_client.py +0 -0
  57. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/client.py +0 -0
  58. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/errors.py +0 -0
  59. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/inputs.py +0 -0
  60. {relaygpu_client-0.1.3 → relaygpu_client-0.1.4}/relaygpu/py.typed +0 -0
@@ -3,6 +3,33 @@
3
3
  `relaygpu-client` versions track the TypeScript client [`@relaygpu/client`](https://www.npmjs.com/package/@relaygpu/client)
4
4
  minor for minor: 0.1.x here is the port of 0.1.x there. The API may change before 1.0.
5
5
 
6
+ ## 0.1.4 (2026-11-30)
7
+
8
+ - **Connected apps and "log out everywhere"** (dashboard login, `jwt=`, only): `account.connected_apps()`
9
+ (`GET /v2/customer/oauth/grants`), `account.disconnect_app(grant_id)` (`DELETE …/oauth/grants/{grant_id}`),
10
+ `account.set_connected_apps_spend_cap(limit_usd)` (`PATCH …/oauth/spend-cap`, `None` removes the cap) and
11
+ `account.revoke_sessions()` (`POST /v2/customer/sessions/revoke`: ends every dashboard login of the account,
12
+ the client's own included; API keys, the superkey and connected apps keep working). Never retried.
13
+ - **`error_detail`** on every error: the body's `error.detail` (the structured detail), beside `detail` (the legacy
14
+ one, unchanged). `KEY_LIMIT_REACHED` carries `{"current_keys", "max_keys"}`, `UPSTREAM_ERROR` `{"upstream_code"}`.
15
+ - **`webhooks.deliveries.list(start_time=..., end_time=...)`**: a creation window in Unix seconds.
16
+ - **`endpoint`** for a model with more than one endpoint: `models.get(name, endpoint=...)` sends `?endpoint=` and
17
+ caches per endpoint; `run(model, input, endpoint=...)` submits to that endpoint's route through the same submit
18
+ path (retired refusal, `model_in_body`, uploads, idempotency key, async handling). `endpoint="responses"` returns the
19
+ Responses object as the server sends it, typed `OpenAIResponsesResponse`; `output_text(response)` joins its text
20
+ (the TS `outputText`). An endpoint the model does not list is the server's refusal, raised as its typed error.
21
+ `ModelEndpointName` (`"chat_completions" | "responses"`) in `relaygpu.types`. Without `endpoint` nothing changes.
22
+ - **Generated types** follow the prod public spec of 2026-11-29: `KlingTeam/v4` and `KlingTeam/v4-V2V`, seven
23
+ new chat models, the Smith library shapes, the connected-apps shapes (`ConnectedApps`, `SpendCap`, `SpendCapUpdate`), `SubscriptionPlanView`
24
+ (`GET /v2/customer/subscription/plans`, typed only, like the other subscription routes), the large storage rung in
25
+ `MediaStoragePricing` (`large`, `large_threshold_bytes`), per-key rate limits documented as at least 1, new
26
+ chat and Responses request fields; `IndexTeam/IndexTTS-2`, `decart/lucy-2.5` and `zai-org/glm-5.2` left the
27
+ model map (retired).
28
+ - **README**: examples on `black-forest-labs/FLUX-2-pro` (`Qwen/qwen-image` is retired), the image is saved with
29
+ the extension of its link, the Kling estimate passes `sound: False`, only image, video and audio uploads are
30
+ accepted (`415 FILE_TYPE_UNSUPPORTED`), lifetimes are "1 hour by default", the free `relay1h` upload needs an
31
+ account that has topped up or holds an active promo.
32
+
6
33
  ## 0.1.3 (2026-11-09)
7
34
 
8
35
  - **Generated types** follow the prod public spec of 2026-11-08 (Relay Roll 47): the OpenAI Responses route
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: relaygpu-client
3
- Version: 0.1.3
3
+ Version: 0.1.4
4
4
  Summary: Python client for the Relay API: image, video and audio generation, tasks, files, webhooks, workflows and typed errors.
5
5
  Project-URL: Homepage, https://relaygpu.com
6
6
  Project-URL: Repository, https://github.com/OpenGPU-Network/relaygpu-python
@@ -37,7 +37,7 @@ Description-Content-Type: text/markdown
37
37
  The Python client for [Relay](https://relaygpu.com): image, video and audio generation, async tasks, file
38
38
  uploads, webhook verification, workflows, account and keys, with typed errors. Request and response types are
39
39
  generated from Relay's public OpenAPI spec. Chat is not wrapped: point the OpenAI SDK at Relay
40
- ([quickstart 6](#6-chat-use-the-sdk-you-already-have)). A port of the TypeScript client
40
+ ([quickstart 6](#6-text-use-the-sdk-you-already-have)). A port of the TypeScript client
41
41
  [`@relaygpu/client`](https://www.npmjs.com/package/@relaygpu/client), version for version (0.1.x ↔ 0.1.x).
42
42
 
43
43
  ```bash
@@ -85,7 +85,7 @@ with Relay(os.environ["RELAY_API_KEY"]) as relay:
85
85
  from relaygpu import AsyncRelay
86
86
 
87
87
  async with AsyncRelay(os.environ["RELAY_API_KEY"]) as relay:
88
- result = await relay.image.generate("Qwen/qwen-image", {"prompt": "a lighthouse at dusk"})
88
+ result = await relay.image.generate("black-forest-labs/FLUX-2-pro", {"prompt": "a lighthouse at dusk"})
89
89
  ```
90
90
 
91
91
  ## Quickstarts
@@ -95,7 +95,7 @@ Each one is a runnable file in [`examples/`](examples/) (how to run them:
95
95
 
96
96
  ### 1. Image
97
97
 
98
- Generate an image with `Qwen/qwen-image`, print its link and save it.
98
+ Generate an image with `black-forest-labs/FLUX-2-pro`, print its link and save it.
99
99
  ([`examples/01_image.py`](examples/01_image.py))
100
100
 
101
101
  ```python
@@ -103,20 +103,22 @@ import os
103
103
  import sys
104
104
  import tempfile
105
105
  from pathlib import Path
106
+ from urllib.parse import urlsplit
106
107
 
107
108
  from relaygpu import ContentPolicyDeclinedError, InsufficientCreditsError, Relay
108
109
 
109
110
  with Relay(os.environ["RELAY_API_KEY"], base_url=os.environ.get("RELAY_BASE_URL")) as relay:
110
111
  try:
111
112
  result = relay.image.generate(
112
- "Qwen/qwen-image",
113
- {"prompt": "A red fox in an autumn forest", "size": "1024x1024"},
113
+ "black-forest-labs/FLUX-2-pro",
114
+ {"prompt": "A red fox in an autumn forest", "width": 1024, "height": 1024},
114
115
  )
115
116
  image = result.images[0]
116
- print("url:", image.url) # a link that lives 1 h; pass store_output="relay7d" to keep it longer
117
+ print("url:", image.url) # a link that lives 1 h by default; pass store_output="relay7d" to keep it longer
117
118
 
118
- ext = (image.mime_type or "image/bin").split("/")[1]
119
- path = Path(tempfile.gettempdir()) / f"relay-image.{ext}"
119
+ # A link result has no mime_type: take the extension from the link, else from the base64 result's type.
120
+ suffix = Path(urlsplit(image.url or "").path).suffix or "." + (image.mime_type or "image/png").split("/")[1]
121
+ path = Path(tempfile.gettempdir()) / f"relay-image{suffix}"
120
122
  image.save(path) # downloads the link (without your key) or decodes base64
121
123
  print("saved:", path)
122
124
  except InsufficientCreditsError as e:
@@ -151,7 +153,7 @@ with Relay(os.environ["RELAY_API_KEY"], base_url=os.environ.get("RELAY_BASE_URL"
151
153
  on_progress=lambda p: print(f"{p['status']} after {p['elapsed_seconds']}s"),
152
154
  )
153
155
  urls = (task.get("result") or {}).get("urls") or []
154
- print("video:", urls[0] if urls else None) # expires 1 h after completion unless you pass store_output
156
+ print("video:", urls[0] if urls else None) # expires 1 h after completion by default, unless you pass store_output
155
157
  except TaskFailedError as e:
156
158
  # The task ran and failed: e.code is the task's error_code (e.g. CONTENT_POLICY_DECLINED, UPSTREAM_TIMEOUT).
157
159
  sys.exit(f"task {e.task_id} failed: {e.code or 'unclassified'}: {e}")
@@ -176,7 +178,8 @@ video_path, image_url = Path(sys.argv[1]), sys.argv[2]
176
178
  with Relay(os.environ["RELAY_API_KEY"], base_url=os.environ.get("RELAY_BASE_URL")) as relay:
177
179
  try:
178
180
  # Form 1, explicit: host the file yourself and get a link any *_url field takes.
179
- # relay1h is free; relay1d / relay7d / relay30d are billed per file (relay.pricing.get()["media_storage"]).
181
+ # relay1h is free once your account has topped up (or holds an active promo); relay1d / relay7d /
182
+ # relay30d are billed per file (relay.pricing.get()["media_storage"]).
180
183
  file = relay.files.upload(video_path, retention="relay1d") # streamed from disk; media type sniffed
181
184
  print("uploaded:", file["file_id"], file["url"], "expires", file["expires_at"])
182
185
 
@@ -315,12 +318,24 @@ print(response.output_text)
315
318
 
316
319
  Responses on Relay is stateless: Relay sets `store: false`, and `previous_response_id` and `conversation` are refused. Resend the `input` each turn.
317
320
 
321
+ The Responses API also runs through `run()`, with this client's key, errors and retry policy:
322
+
323
+ ```python
324
+ from relaygpu import output_text
325
+
326
+ response = relay.run("openai/gpt-5.5", {"input": "Say hello in five words."}, endpoint="responses")
327
+ print(output_text(response)) # the text of the message items; response is the Responses object as sent
328
+ ```
329
+
330
+ `endpoint="responses"` resolves the model's Responses route (`relay.models.get(name, endpoint="responses")`). A
331
+ model that does not list that endpoint is refused by the server, and the call raises its typed error.
332
+
318
333
  ## Any model: `run()` and model resolution
319
334
 
320
335
  ```python
321
336
  from relaygpu import is_accepted
322
337
 
323
- out = relay.run("Qwen/qwen-image", {"prompt": "a lighthouse at dusk"}) # the output body
338
+ out = relay.run("black-forest-labs/FLUX-2-pro", {"prompt": "a lighthouse at dusk"}) # the output body
324
339
  sub = relay.run("KlingTeam/v3-T2V", {"prompt": "waves", "duration": 3}, wait=False)
325
340
  if is_accepted(sub):
326
341
  print(sub["task_id"]) # the 202 envelope
@@ -342,7 +357,8 @@ knows also get `Literal` hints for autocomplete.
342
357
  `wait=False` returns the `202` envelope instead (narrow it with `is_accepted`).
343
358
  - Request options are keyword arguments on every call: `timeout`, `on_progress`, `mode`, `store_output`,
344
359
  `webhook_url`, `idempotency_key`, `async_` (trailing underscore: `async` is a keyword), `upload`,
345
- `inline_images`.
360
+ `inline_images`. `run()` also takes `endpoint` (`"chat_completions"` or `"responses"`) for a model with more
361
+ than one endpoint; without it the model's default route is used.
346
362
 
347
363
  ## Async tasks and `tasks.wait`
348
364
 
@@ -361,7 +377,7 @@ task = relay.tasks.wait(
361
377
  second. `on_progress` fires on status transitions (`queued` → `running` → `completed`) with `elapsed_seconds`,
362
378
  and that is all there is: no queue position, no logs and no cancel, by design. A failed task raises
363
379
  `TaskFailedError` with `code` = the task's `error_code`. Task polls need no key: the task id is the access
364
- token. A task's result expires 1 hour after it finishes. `relay.tasks.get(task_id)` reads the status once.
380
+ token. A task's result expires 1 hour after it finishes, by default. `relay.tasks.get(task_id)` reads the status once.
365
381
 
366
382
  Workflow runs have no long-poll: `workflows.wait_run` polls the run every 1 s, backing off to 5 s (default
367
383
  budget 30 min).
@@ -396,6 +412,8 @@ relay.files.list(source="upload") # one page; files.list_all(...) iterates ever
396
412
  relay.files.delete(file["file_id"]) # the link goes down now; no refund
397
413
  ```
398
414
 
415
+ - Only image, video and audio files are accepted; any other type is refused with `415`
416
+ (`FILE_TYPE_UNSUPPORTED`).
399
417
  - `files.upload` takes `bytes`, a path (`pathlib.Path` or `str`), a binary file object (`open(p, "rb")`) or an
400
418
  iterator of bytes (`AsyncRelay` also takes an async iterator). Paths and file objects are streamed in
401
419
  chunks, never read whole into memory.
@@ -406,7 +424,9 @@ relay.files.delete(file["file_id"]) # the link goes down now; no refund
406
424
  ones are still uploaded.
407
425
  - One file is at most 100 MB (the server answers `413`, `FileTooLargeError`). The media type comes from
408
426
  `content_type=`, else from the file's first bytes.
409
- - `relay1h` is free within a daily quota; `relay1d`, `relay7d` and `relay30d` are billed per file at upload.
427
+ - `relay1h` is free within a daily quota, for accounts that have topped up at least once or hold an active
428
+ promo (otherwise the upload is refused with `402`); `relay1d`, `relay7d` and `relay30d` are billed per file
429
+ at upload.
410
430
 
411
431
  ## How long result links live
412
432
 
@@ -414,7 +434,7 @@ Result links (`urls`, `audio_url`, …) and uploaded files expire. By default a
414
434
  after the task finishes. To keep outputs longer, buy storage per request with `store_output`:
415
435
 
416
436
  ```python
417
- relay.image.generate("Qwen/qwen-image", {"prompt": "a lighthouse"}, store_output="relay7d")
437
+ relay.image.generate("black-forest-labs/FLUX-2-pro", {"prompt": "a lighthouse"}, store_output="relay7d")
418
438
  ```
419
439
 
420
440
  | `store_output` / `retention` | Lifetime | Fee |
@@ -444,6 +464,9 @@ checks the signature and the timestamp (±5 min, `tolerance=300`) and returns th
444
464
  - Delivery is at-least-once: dedupe on the `webhook-id` header.
445
465
  - `relay.webhooks.secret()`, `.rotate_secret()` and `.deliveries.list()` / `.deliveries.get(task_id_or_run_id)`
446
466
  need a JWT or a partner superkey.
467
+ - `deliveries.list(start_time=..., end_time=...)` narrows the list to tasks or runs created in that window (Unix
468
+ seconds; `start_time` inclusive, `end_time` exclusive and now by default). The window is on when the task was
469
+ created, not on when it was delivered.
447
470
 
448
471
  ## Errors
449
472
 
@@ -475,7 +498,7 @@ from `relaygpu`). A code this release does not know falls back to the status cla
475
498
  from relaygpu import KeyBudgetExhaustedError, RateLimitError, RelayAPIError
476
499
 
477
500
  try:
478
- relay.image.generate("Qwen/qwen-image", {"prompt": "a lighthouse"})
501
+ relay.image.generate("black-forest-labs/FLUX-2-pro", {"prompt": "a lighthouse"})
479
502
  except KeyBudgetExhaustedError:
480
503
  print("this key's budget is spent")
481
504
  except RateLimitError as e:
@@ -486,6 +509,9 @@ except RelayAPIError as e:
486
509
 
487
510
  - `e.request_id` is the id to quote to support; `e.retry_after` (seconds) is set from `Retry-After`;
488
511
  `e.detail` is the server's detail.
512
+ - `e.error_detail` is the structured detail when the server sends one (`error.detail` in the body), else
513
+ `None`. At the tier's key limit, `keys.create` raises `KeyLimitReachedError` with
514
+ `e.error_detail == {"current_keys": 2, "max_keys": 2}`; on `UPSTREAM_ERROR` it carries `upstream_code`.
489
515
  - `TaskFailedError`: an async task (or workflow run) ended `failed`; `e.code` is the task's `error_code`,
490
516
  `e.task_id` and `e.task` carry the rest.
491
517
  - `APIConnectionError` (no HTTP answer), `APITimeoutError` (a `timeout` ran out),
@@ -517,12 +543,28 @@ relay.keys.revoke(key_id)
517
543
  These routes take a dashboard JWT or a custom-tier superkey. A plain inference key gets the server's 403
518
544
  (`PermissionDeniedError`); the SDK does not guess the key class. `keys.create` returns the full secret in
519
545
  `key` once; every later response masks it, so store it then. Address keys by `key_id`. `key_budget` is for
520
- custom tiers only. Query parameters are keyword arguments with the API's names (`from` is spelled `from_`).
546
+ custom tiers only. A key's `restrictions.rate_limits` values are each at least 1 (a lower value is refused) and
547
+ narrow the tier's limit; they are checked against the account's shared per-minute count. Query parameters are
548
+ keyword arguments with the API's names (`from` is spelled `from_`).
549
+
550
+ These take a dashboard login (`Relay(jwt=...)`) only; an API key or a superkey is refused:
551
+
552
+ ```python
553
+ apps = relay.account.connected_apps() # {"grants": [...], "spend_cap": {"limit_usd", "remaining_usd"}}
554
+ relay.account.disconnect_app(apps["grants"][0]["grant_id"]) # its access ends within 5 minutes
555
+ relay.account.set_connected_apps_spend_cap(20) # None removes the cap
556
+ relay.account.revoke_sessions() # log out everywhere
557
+ ```
558
+
559
+ Connected apps are the apps you connected to your account through OAuth; they share one spend cap.
560
+ `revoke_sessions()` ends every dashboard login of the account, the client's own `jwt` included: its next call
561
+ raises `AuthenticationError`, and signing in again works at once. API keys, the superkey and connected apps keep
562
+ working; to stop one of those, revoke the key or disconnect the app.
521
563
 
522
564
  ## Cost estimates
523
565
 
524
566
  ```python
525
- est = relay.estimate_cost("KlingTeam/v3-T2V", {"duration_seconds": 3, "quality_mode": "std"})
567
+ est = relay.estimate_cost("KlingTeam/v3-T2V", {"duration_seconds": 3, "quality_mode": "std", "sound": False})
526
568
  print(est["usd"], est["basis"])
527
569
  ```
528
570
 
@@ -5,7 +5,7 @@
5
5
  The Python client for [Relay](https://relaygpu.com): image, video and audio generation, async tasks, file
6
6
  uploads, webhook verification, workflows, account and keys, with typed errors. Request and response types are
7
7
  generated from Relay's public OpenAPI spec. Chat is not wrapped: point the OpenAI SDK at Relay
8
- ([quickstart 6](#6-chat-use-the-sdk-you-already-have)). A port of the TypeScript client
8
+ ([quickstart 6](#6-text-use-the-sdk-you-already-have)). A port of the TypeScript client
9
9
  [`@relaygpu/client`](https://www.npmjs.com/package/@relaygpu/client), version for version (0.1.x ↔ 0.1.x).
10
10
 
11
11
  ```bash
@@ -53,7 +53,7 @@ with Relay(os.environ["RELAY_API_KEY"]) as relay:
53
53
  from relaygpu import AsyncRelay
54
54
 
55
55
  async with AsyncRelay(os.environ["RELAY_API_KEY"]) as relay:
56
- result = await relay.image.generate("Qwen/qwen-image", {"prompt": "a lighthouse at dusk"})
56
+ result = await relay.image.generate("black-forest-labs/FLUX-2-pro", {"prompt": "a lighthouse at dusk"})
57
57
  ```
58
58
 
59
59
  ## Quickstarts
@@ -63,7 +63,7 @@ Each one is a runnable file in [`examples/`](examples/) (how to run them:
63
63
 
64
64
  ### 1. Image
65
65
 
66
- Generate an image with `Qwen/qwen-image`, print its link and save it.
66
+ Generate an image with `black-forest-labs/FLUX-2-pro`, print its link and save it.
67
67
  ([`examples/01_image.py`](examples/01_image.py))
68
68
 
69
69
  ```python
@@ -71,20 +71,22 @@ import os
71
71
  import sys
72
72
  import tempfile
73
73
  from pathlib import Path
74
+ from urllib.parse import urlsplit
74
75
 
75
76
  from relaygpu import ContentPolicyDeclinedError, InsufficientCreditsError, Relay
76
77
 
77
78
  with Relay(os.environ["RELAY_API_KEY"], base_url=os.environ.get("RELAY_BASE_URL")) as relay:
78
79
  try:
79
80
  result = relay.image.generate(
80
- "Qwen/qwen-image",
81
- {"prompt": "A red fox in an autumn forest", "size": "1024x1024"},
81
+ "black-forest-labs/FLUX-2-pro",
82
+ {"prompt": "A red fox in an autumn forest", "width": 1024, "height": 1024},
82
83
  )
83
84
  image = result.images[0]
84
- print("url:", image.url) # a link that lives 1 h; pass store_output="relay7d" to keep it longer
85
+ print("url:", image.url) # a link that lives 1 h by default; pass store_output="relay7d" to keep it longer
85
86
 
86
- ext = (image.mime_type or "image/bin").split("/")[1]
87
- path = Path(tempfile.gettempdir()) / f"relay-image.{ext}"
87
+ # A link result has no mime_type: take the extension from the link, else from the base64 result's type.
88
+ suffix = Path(urlsplit(image.url or "").path).suffix or "." + (image.mime_type or "image/png").split("/")[1]
89
+ path = Path(tempfile.gettempdir()) / f"relay-image{suffix}"
88
90
  image.save(path) # downloads the link (without your key) or decodes base64
89
91
  print("saved:", path)
90
92
  except InsufficientCreditsError as e:
@@ -119,7 +121,7 @@ with Relay(os.environ["RELAY_API_KEY"], base_url=os.environ.get("RELAY_BASE_URL"
119
121
  on_progress=lambda p: print(f"{p['status']} after {p['elapsed_seconds']}s"),
120
122
  )
121
123
  urls = (task.get("result") or {}).get("urls") or []
122
- print("video:", urls[0] if urls else None) # expires 1 h after completion unless you pass store_output
124
+ print("video:", urls[0] if urls else None) # expires 1 h after completion by default, unless you pass store_output
123
125
  except TaskFailedError as e:
124
126
  # The task ran and failed: e.code is the task's error_code (e.g. CONTENT_POLICY_DECLINED, UPSTREAM_TIMEOUT).
125
127
  sys.exit(f"task {e.task_id} failed: {e.code or 'unclassified'}: {e}")
@@ -144,7 +146,8 @@ video_path, image_url = Path(sys.argv[1]), sys.argv[2]
144
146
  with Relay(os.environ["RELAY_API_KEY"], base_url=os.environ.get("RELAY_BASE_URL")) as relay:
145
147
  try:
146
148
  # Form 1, explicit: host the file yourself and get a link any *_url field takes.
147
- # relay1h is free; relay1d / relay7d / relay30d are billed per file (relay.pricing.get()["media_storage"]).
149
+ # relay1h is free once your account has topped up (or holds an active promo); relay1d / relay7d /
150
+ # relay30d are billed per file (relay.pricing.get()["media_storage"]).
148
151
  file = relay.files.upload(video_path, retention="relay1d") # streamed from disk; media type sniffed
149
152
  print("uploaded:", file["file_id"], file["url"], "expires", file["expires_at"])
150
153
 
@@ -283,12 +286,24 @@ print(response.output_text)
283
286
 
284
287
  Responses on Relay is stateless: Relay sets `store: false`, and `previous_response_id` and `conversation` are refused. Resend the `input` each turn.
285
288
 
289
+ The Responses API also runs through `run()`, with this client's key, errors and retry policy:
290
+
291
+ ```python
292
+ from relaygpu import output_text
293
+
294
+ response = relay.run("openai/gpt-5.5", {"input": "Say hello in five words."}, endpoint="responses")
295
+ print(output_text(response)) # the text of the message items; response is the Responses object as sent
296
+ ```
297
+
298
+ `endpoint="responses"` resolves the model's Responses route (`relay.models.get(name, endpoint="responses")`). A
299
+ model that does not list that endpoint is refused by the server, and the call raises its typed error.
300
+
286
301
  ## Any model: `run()` and model resolution
287
302
 
288
303
  ```python
289
304
  from relaygpu import is_accepted
290
305
 
291
- out = relay.run("Qwen/qwen-image", {"prompt": "a lighthouse at dusk"}) # the output body
306
+ out = relay.run("black-forest-labs/FLUX-2-pro", {"prompt": "a lighthouse at dusk"}) # the output body
292
307
  sub = relay.run("KlingTeam/v3-T2V", {"prompt": "waves", "duration": 3}, wait=False)
293
308
  if is_accepted(sub):
294
309
  print(sub["task_id"]) # the 202 envelope
@@ -310,7 +325,8 @@ knows also get `Literal` hints for autocomplete.
310
325
  `wait=False` returns the `202` envelope instead (narrow it with `is_accepted`).
311
326
  - Request options are keyword arguments on every call: `timeout`, `on_progress`, `mode`, `store_output`,
312
327
  `webhook_url`, `idempotency_key`, `async_` (trailing underscore: `async` is a keyword), `upload`,
313
- `inline_images`.
328
+ `inline_images`. `run()` also takes `endpoint` (`"chat_completions"` or `"responses"`) for a model with more
329
+ than one endpoint; without it the model's default route is used.
314
330
 
315
331
  ## Async tasks and `tasks.wait`
316
332
 
@@ -329,7 +345,7 @@ task = relay.tasks.wait(
329
345
  second. `on_progress` fires on status transitions (`queued` → `running` → `completed`) with `elapsed_seconds`,
330
346
  and that is all there is: no queue position, no logs and no cancel, by design. A failed task raises
331
347
  `TaskFailedError` with `code` = the task's `error_code`. Task polls need no key: the task id is the access
332
- token. A task's result expires 1 hour after it finishes. `relay.tasks.get(task_id)` reads the status once.
348
+ token. A task's result expires 1 hour after it finishes, by default. `relay.tasks.get(task_id)` reads the status once.
333
349
 
334
350
  Workflow runs have no long-poll: `workflows.wait_run` polls the run every 1 s, backing off to 5 s (default
335
351
  budget 30 min).
@@ -364,6 +380,8 @@ relay.files.list(source="upload") # one page; files.list_all(...) iterates ever
364
380
  relay.files.delete(file["file_id"]) # the link goes down now; no refund
365
381
  ```
366
382
 
383
+ - Only image, video and audio files are accepted; any other type is refused with `415`
384
+ (`FILE_TYPE_UNSUPPORTED`).
367
385
  - `files.upload` takes `bytes`, a path (`pathlib.Path` or `str`), a binary file object (`open(p, "rb")`) or an
368
386
  iterator of bytes (`AsyncRelay` also takes an async iterator). Paths and file objects are streamed in
369
387
  chunks, never read whole into memory.
@@ -374,7 +392,9 @@ relay.files.delete(file["file_id"]) # the link goes down now; no refund
374
392
  ones are still uploaded.
375
393
  - One file is at most 100 MB (the server answers `413`, `FileTooLargeError`). The media type comes from
376
394
  `content_type=`, else from the file's first bytes.
377
- - `relay1h` is free within a daily quota; `relay1d`, `relay7d` and `relay30d` are billed per file at upload.
395
+ - `relay1h` is free within a daily quota, for accounts that have topped up at least once or hold an active
396
+ promo (otherwise the upload is refused with `402`); `relay1d`, `relay7d` and `relay30d` are billed per file
397
+ at upload.
378
398
 
379
399
  ## How long result links live
380
400
 
@@ -382,7 +402,7 @@ Result links (`urls`, `audio_url`, …) and uploaded files expire. By default a
382
402
  after the task finishes. To keep outputs longer, buy storage per request with `store_output`:
383
403
 
384
404
  ```python
385
- relay.image.generate("Qwen/qwen-image", {"prompt": "a lighthouse"}, store_output="relay7d")
405
+ relay.image.generate("black-forest-labs/FLUX-2-pro", {"prompt": "a lighthouse"}, store_output="relay7d")
386
406
  ```
387
407
 
388
408
  | `store_output` / `retention` | Lifetime | Fee |
@@ -412,6 +432,9 @@ checks the signature and the timestamp (±5 min, `tolerance=300`) and returns th
412
432
  - Delivery is at-least-once: dedupe on the `webhook-id` header.
413
433
  - `relay.webhooks.secret()`, `.rotate_secret()` and `.deliveries.list()` / `.deliveries.get(task_id_or_run_id)`
414
434
  need a JWT or a partner superkey.
435
+ - `deliveries.list(start_time=..., end_time=...)` narrows the list to tasks or runs created in that window (Unix
436
+ seconds; `start_time` inclusive, `end_time` exclusive and now by default). The window is on when the task was
437
+ created, not on when it was delivered.
415
438
 
416
439
  ## Errors
417
440
 
@@ -443,7 +466,7 @@ from `relaygpu`). A code this release does not know falls back to the status cla
443
466
  from relaygpu import KeyBudgetExhaustedError, RateLimitError, RelayAPIError
444
467
 
445
468
  try:
446
- relay.image.generate("Qwen/qwen-image", {"prompt": "a lighthouse"})
469
+ relay.image.generate("black-forest-labs/FLUX-2-pro", {"prompt": "a lighthouse"})
447
470
  except KeyBudgetExhaustedError:
448
471
  print("this key's budget is spent")
449
472
  except RateLimitError as e:
@@ -454,6 +477,9 @@ except RelayAPIError as e:
454
477
 
455
478
  - `e.request_id` is the id to quote to support; `e.retry_after` (seconds) is set from `Retry-After`;
456
479
  `e.detail` is the server's detail.
480
+ - `e.error_detail` is the structured detail when the server sends one (`error.detail` in the body), else
481
+ `None`. At the tier's key limit, `keys.create` raises `KeyLimitReachedError` with
482
+ `e.error_detail == {"current_keys": 2, "max_keys": 2}`; on `UPSTREAM_ERROR` it carries `upstream_code`.
457
483
  - `TaskFailedError`: an async task (or workflow run) ended `failed`; `e.code` is the task's `error_code`,
458
484
  `e.task_id` and `e.task` carry the rest.
459
485
  - `APIConnectionError` (no HTTP answer), `APITimeoutError` (a `timeout` ran out),
@@ -485,12 +511,28 @@ relay.keys.revoke(key_id)
485
511
  These routes take a dashboard JWT or a custom-tier superkey. A plain inference key gets the server's 403
486
512
  (`PermissionDeniedError`); the SDK does not guess the key class. `keys.create` returns the full secret in
487
513
  `key` once; every later response masks it, so store it then. Address keys by `key_id`. `key_budget` is for
488
- custom tiers only. Query parameters are keyword arguments with the API's names (`from` is spelled `from_`).
514
+ custom tiers only. A key's `restrictions.rate_limits` values are each at least 1 (a lower value is refused) and
515
+ narrow the tier's limit; they are checked against the account's shared per-minute count. Query parameters are
516
+ keyword arguments with the API's names (`from` is spelled `from_`).
517
+
518
+ These take a dashboard login (`Relay(jwt=...)`) only; an API key or a superkey is refused:
519
+
520
+ ```python
521
+ apps = relay.account.connected_apps() # {"grants": [...], "spend_cap": {"limit_usd", "remaining_usd"}}
522
+ relay.account.disconnect_app(apps["grants"][0]["grant_id"]) # its access ends within 5 minutes
523
+ relay.account.set_connected_apps_spend_cap(20) # None removes the cap
524
+ relay.account.revoke_sessions() # log out everywhere
525
+ ```
526
+
527
+ Connected apps are the apps you connected to your account through OAuth; they share one spend cap.
528
+ `revoke_sessions()` ends every dashboard login of the account, the client's own `jwt` included: its next call
529
+ raises `AuthenticationError`, and signing in again works at once. API keys, the superkey and connected apps keep
530
+ working; to stop one of those, revoke the key or disconnect the app.
489
531
 
490
532
  ## Cost estimates
491
533
 
492
534
  ```python
493
- est = relay.estimate_cost("KlingTeam/v3-T2V", {"duration_seconds": 3, "quality_mode": "std"})
535
+ est = relay.estimate_cost("KlingTeam/v3-T2V", {"duration_seconds": 3, "quality_mode": "std", "sound": False})
494
536
  print(est["usd"], est["basis"])
495
537
  ```
496
538
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "relaygpu-client"
7
- version = "0.1.3"
7
+ version = "0.1.4"
8
8
  description = "Python client for the Relay API: image, video and audio generation, tasks, files, webhooks, workflows and typed errors."
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -7,6 +7,7 @@ from ._core import DEFAULT_BASE_URL as DEFAULT_BASE_URL
7
7
  from ._core import DEFAULT_TIMEOUT as DEFAULT_TIMEOUT
8
8
  from ._core import APIResponse as APIResponse
9
9
  from ._core import RetryOptions as RetryOptions
10
+ from ._responses import output_text as output_text
10
11
  from ._run_common import is_accepted as is_accepted
11
12
  from ._sync.image import ImageResult as ImageResult
12
13
  from ._sync.image import RelayImage as RelayImage
@@ -6,6 +6,7 @@ from collections.abc import Mapping, Sequence
6
6
  from typing import TYPE_CHECKING, Any, cast
7
7
 
8
8
  from .._generated.types import (
9
+ ConnectedApps,
9
10
  CreditHistoryResponse,
10
11
  CreditsResponse,
11
12
  CustomerPricingResponse,
@@ -15,6 +16,7 @@ from .._generated.types import (
15
16
  ModelAllowlistResponse,
16
17
  ModelAllowlistView,
17
18
  ProfileResponse,
19
+ SpendCap,
18
20
  UsageTimeseriesPage,
19
21
  )
20
22
  from .._shapes import CreditHistoryParams, KeyUsageParams, MetricsParams, UsageParams, UsageTimeseriesParams
@@ -81,3 +83,26 @@ class AsyncAccount:
81
83
  body = {"model_allowlist": None if model_allowlist is None else [*model_allowlist]}
82
84
  res = await self._relay._http.request("PATCH", "/v2/customer/model-allowlist", json=body)
83
85
  return cast(ModelAllowlistResponse, res.data)
86
+
87
+ async def connected_apps(self) -> ConnectedApps:
88
+ """``GET /v2/customer/oauth/grants``: the apps connected through OAuth (``grants``) and the one ``spend_cap`` they
89
+ share. **JWT only** (a dashboard login)."""
90
+ return cast(ConnectedApps, await self._get("/v2/customer/oauth/grants"))
91
+
92
+ async def disconnect_app(self, grant_id: str) -> None:
93
+ """``DELETE /v2/customer/oauth/grants/{grant_id}``: the app gets no new credential, and the one it holds expires
94
+ within 5 minutes. **JWT only**."""
95
+ await self._relay._http.request("DELETE", f"/v2/customer/oauth/grants/{path_id(grant_id)}")
96
+
97
+ async def set_connected_apps_spend_cap(self, limit_usd: float | None) -> SpendCap:
98
+ """``PATCH /v2/customer/oauth/spend-cap``: caps what connected apps may spend (``None`` removes the cap); setting it
99
+ restarts ``remaining_usd`` at the new limit. **JWT only**."""
100
+ res = await self._relay._http.request("PATCH", "/v2/customer/oauth/spend-cap", json={"limit_usd": limit_usd})
101
+ return cast(SpendCap, res.data)
102
+
103
+ async def revoke_sessions(self) -> None:
104
+ """``POST /v2/customer/sessions/revoke`` ("Log out everywhere"): ends every dashboard login of the account,
105
+ including the ``jwt`` this client holds (its next call raises ``AuthenticationError``). API keys, the superkey and
106
+ connected apps keep working. **JWT only**: an API key or superkey gets ``AuthenticationError``, a connected app's
107
+ credential ``CredentialNotPermittedError``. Never retried."""
108
+ await self._relay._http.request("POST", "/v2/customer/sessions/revoke")
@@ -9,7 +9,17 @@ from typing import Any, Literal, overload
9
9
  import httpx
10
10
 
11
11
  from .._core import _UNSET, Query, RawBody, RetryOptions
12
- from ..types import AsyncAccepted, CostEstimate, HealthResponse, Mode, TaskProgress, UploadOptions, UsageInput
12
+ from ..types import (
13
+ AsyncAccepted,
14
+ CostEstimate,
15
+ HealthResponse,
16
+ Mode,
17
+ ModelEndpointName,
18
+ OpenAIResponsesResponse,
19
+ TaskProgress,
20
+ UploadOptions,
21
+ UsageInput,
22
+ )
13
23
  from ._http import AsyncHttpClient
14
24
  from .account import AsyncAccount
15
25
  from .audio import AsyncAudio
@@ -94,6 +104,26 @@ class AsyncRelay:
94
104
  async_: bool | None = None,
95
105
  upload: UploadOptions | None = None,
96
106
  inline_images: bool = False,
107
+ endpoint: Literal["responses"],
108
+ ) -> OpenAIResponsesResponse: ...
109
+
110
+ @overload
111
+ async def run(
112
+ self,
113
+ model: str,
114
+ input: Mapping[str, Any],
115
+ *,
116
+ wait: Literal[True] = True,
117
+ on_progress: Callable[[TaskProgress], None] | None = None,
118
+ timeout: float | None = None,
119
+ mode: Mode | None = None,
120
+ store_output: str | None = None,
121
+ webhook_url: str | None = None,
122
+ idempotency_key: str | None = None,
123
+ async_: bool | None = None,
124
+ upload: UploadOptions | None = None,
125
+ inline_images: bool = False,
126
+ endpoint: Literal["chat_completions"] | None = None,
97
127
  ) -> dict[str, Any]: ...
98
128
 
99
129
  @overload
@@ -112,7 +142,8 @@ class AsyncRelay:
112
142
  async_: bool | None = None,
113
143
  upload: UploadOptions | None = None,
114
144
  inline_images: bool = False,
115
- ) -> dict[str, Any] | AsyncAccepted: ...
145
+ endpoint: ModelEndpointName | None = None,
146
+ ) -> dict[str, Any] | AsyncAccepted | OpenAIResponsesResponse: ...
116
147
 
117
148
  @overload
118
149
  async def run(
@@ -130,7 +161,8 @@ class AsyncRelay:
130
161
  async_: bool | None = None,
131
162
  upload: UploadOptions | None = None,
132
163
  inline_images: bool = False,
133
- ) -> dict[str, Any] | AsyncAccepted: ...
164
+ endpoint: ModelEndpointName | None = None,
165
+ ) -> dict[str, Any] | AsyncAccepted | OpenAIResponsesResponse: ...
134
166
 
135
167
  async def run(
136
168
  self,
@@ -147,11 +179,14 @@ class AsyncRelay:
147
179
  async_: bool | None = None,
148
180
  upload: UploadOptions | None = None,
149
181
  inline_images: bool = False,
150
- ) -> dict[str, Any] | AsyncAccepted:
182
+ endpoint: ModelEndpointName | None = None,
183
+ ) -> dict[str, Any] | AsyncAccepted | OpenAIResponsesResponse:
151
184
  """Runs any model: resolves its route through ``models.get``, submits, and (by default) waits for the result.
152
185
 
153
186
  A sync route returns its body; an async route (or ``async_=True``) waits and returns the task's ``result``;
154
- ``wait=False`` returns the ``202`` envelope instead (narrow with ``is_accepted``).
187
+ ``wait=False`` returns the ``202`` envelope instead (narrow with ``is_accepted``). ``endpoint`` picks one of the
188
+ model's endpoints: ``endpoint="responses"`` returns the Responses object as the server sends it
189
+ (``relaygpu.output_text(response)`` joins its text).
155
190
  """
156
191
  return await run(
157
192
  self,
@@ -167,6 +202,7 @@ class AsyncRelay:
167
202
  async_=async_,
168
203
  upload=upload,
169
204
  inline_images=inline_images,
205
+ endpoint=endpoint,
170
206
  )
171
207
 
172
208
  async def estimate_cost(self, model: str, usage: UsageInput) -> CostEstimate:
@@ -63,7 +63,9 @@ class AsyncKeys:
63
63
  async def create(self, **fields: Unpack[CreateKeyRequest]) -> CreateKeyResponse:
64
64
  """``POST /v2/customer/keys``. The response's ``key`` is the full secret and is returned **only here**, once; store it
65
65
  now (every later response masks it). The first key on a custom tier becomes the superkey (``is_superkey: True``).
66
- ``key_budget`` is custom-tier only (403 otherwise). Never retried (a retry could mint twice)."""
66
+ ``key_budget`` is custom-tier only (403 otherwise). Each ``restrictions.rate_limits`` value is at least 1 and at most
67
+ the tier's (refused otherwise). At the tier's key limit the server answers ``KeyLimitReachedError``, whose
68
+ ``error_detail`` is ``{"current_keys", "max_keys"}``. Never retried (a retry could mint twice)."""
67
69
  return cast(CreateKeyResponse, await self._call("POST", "/v2/customer/keys", dict(fields)))
68
70
 
69
71
  async def get(self, key_id: str) -> KeyResponse:
@@ -75,7 +77,8 @@ class AsyncKeys:
75
77
  raise KeyNotFoundError(f"Key not found: {key_id}", code="KEY_NOT_FOUND")
76
78
 
77
79
  async def update(self, key_id: str, **patch: Unpack[UpdateKeyRequest]) -> KeyMutationResult:
78
- """``PATCH /v2/customer/keys/{key_id}``: send only what changes; ``restrictions`` is replaced, not merged."""
80
+ """``PATCH /v2/customer/keys/{key_id}``: send only what changes; ``restrictions`` is replaced, not merged (the
81
+ ``rate_limits`` rule is in :meth:`create`)."""
79
82
  return cast(KeyMutationResult, await self._call("PATCH", _key_path(key_id), dict(patch)))
80
83
 
81
84
  async def rename(self, key_id: str, name: str) -> KeyMutationResult: