relaygpu-client 0.1.2__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.2 → relaygpu_client-0.1.4}/CHANGELOG.md +37 -1
  2. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/PKG-INFO +75 -25
  3. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/README.md +74 -24
  4. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/pyproject.toml +1 -1
  5. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/__init__.py +1 -0
  6. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_async/account.py +25 -0
  7. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_async/client.py +41 -5
  8. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_async/keys.py +5 -2
  9. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_async/models.py +15 -9
  10. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_async/run.py +13 -8
  11. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_errors.py +6 -7
  12. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_exceptions.py +8 -0
  13. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_generated/error_codes.py +84 -0
  14. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_generated/models_map.py +38 -7
  15. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_generated/types.py +657 -8
  16. relaygpu_client-0.1.4/relaygpu/_responses.py +21 -0
  17. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_run_common.py +1 -0
  18. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_sync/account.py +25 -0
  19. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_sync/client.py +41 -5
  20. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_sync/keys.py +5 -2
  21. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_sync/models.py +15 -9
  22. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_sync/run.py +13 -8
  23. relaygpu_client-0.1.4/relaygpu/_version.py +1 -0
  24. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/types.py +5 -0
  25. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/webhooks.py +4 -0
  26. relaygpu_client-0.1.2/relaygpu/_version.py +0 -1
  27. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/.gitignore +0 -0
  28. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/LICENSE +0 -0
  29. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_async/__init__.py +0 -0
  30. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_async/_http.py +0 -0
  31. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_async/audio.py +0 -0
  32. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_async/estimate.py +0 -0
  33. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_async/files.py +0 -0
  34. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_async/image.py +0 -0
  35. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_async/tasks.py +0 -0
  36. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_async/video.py +0 -0
  37. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_async/webhooks.py +0 -0
  38. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_async/workflows.py +0 -0
  39. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_clock.py +0 -0
  40. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_core.py +0 -0
  41. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_estimate.py +0 -0
  42. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_generated/__init__.py +0 -0
  43. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_images.py +0 -0
  44. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_shapes.py +0 -0
  45. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_sync/__init__.py +0 -0
  46. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_sync/_http.py +0 -0
  47. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_sync/audio.py +0 -0
  48. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_sync/estimate.py +0 -0
  49. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_sync/files.py +0 -0
  50. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_sync/image.py +0 -0
  51. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_sync/tasks.py +0 -0
  52. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_sync/video.py +0 -0
  53. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_sync/webhooks.py +0 -0
  54. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_sync/workflows.py +0 -0
  55. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/_util.py +0 -0
  56. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/async_client.py +0 -0
  57. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/client.py +0 -0
  58. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/errors.py +0 -0
  59. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/inputs.py +0 -0
  60. {relaygpu_client-0.1.2 → relaygpu_client-0.1.4}/relaygpu/py.typed +0 -0
@@ -3,7 +3,43 @@
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.2 (unreleased)
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
+
33
+ ## 0.1.3 (2026-11-09)
34
+
35
+ - **Generated types** follow the prod public spec of 2026-11-08 (Relay Roll 47): the OpenAI Responses route
36
+ (`POST /v2/openai/v1/responses`; a base-URL swap on the OpenAI SDK, stateless), the ClarityAI upscalers
37
+ (`/v2/image/clarity/upscale`), MiniMax H3 V2V, `moonshotai/kimi-k3.1-pro`, `GET /v2/customer/keys/{key}`,
38
+ `result_field` on the model detail, `cancel_requested` on workflow runs, numeric pricing cells, the Smith and
39
+ subscription routes with their fourteen error codes as typed errors. `openai/whisper-1` left the public model map
40
+ (retired 2026-11-02; use `relay/stt-1`).
41
+
42
+ ## 0.1.2 (2026-10-24)
7
43
 
8
44
  - **Catalog reads are account-aware.** `models.list`, `models.get`, `pricing.get` and `tiers.list` now send the
9
45
  client's credential (`api_key` or `jwt`), so with one they return your account's view: the models your tier and
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: relaygpu-client
3
- Version: 0.1.2
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
@@ -36,8 +36,8 @@ Description-Content-Type: text/markdown
36
36
 
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
- generated from Relay's public OpenAPI spec. Chat is not wrapped: point the OpenAI or Anthropic SDK at Relay
40
- ([quickstart 6](#6-chat-use-the-sdk-you-already-have)). A port of the TypeScript client
39
+ generated from Relay's public OpenAPI spec. Chat is not wrapped: point the OpenAI SDK at Relay
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
 
@@ -284,9 +287,9 @@ with Relay(os.environ["RELAY_API_KEY"], base_url=os.environ.get("RELAY_BASE_URL"
284
287
  sys.exit(f"run {e.task_id} did not complete: {e}")
285
288
  ```
286
289
 
287
- ### 6. Chat: use the SDK you already have
290
+ ### 6. Text: use the SDK you already have
288
291
 
289
- Chat and completions run on the official OpenAI and Anthropic SDKs: point them at Relay. This SDK does not wrap
292
+ Chat and completions run on the official OpenAI SDK: point it at Relay. This SDK does not wrap
290
293
  chat. `openai` is an example dependency only (`pip install openai`); `relaygpu-client` does not need it.
291
294
  ([`examples/06_chat_base_url.py`](examples/06_chat_base_url.py))
292
295
 
@@ -306,12 +309,33 @@ completion = client.chat.completions.create(
306
309
  print(completion.choices[0].message.content)
307
310
  ```
308
311
 
312
+ The Responses API is the same swap, on the same base URL, for the `openai` models that list it (`GET /v2/models`):
313
+
314
+ ```python
315
+ response = client.responses.create(model="openai/gpt-5.5", input="Say hello in five words.")
316
+ print(response.output_text)
317
+ ```
318
+
319
+ Responses on Relay is stateless: Relay sets `store: false`, and `previous_response_id` and `conversation` are refused. Resend the `input` each turn.
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
+
309
333
  ## Any model: `run()` and model resolution
310
334
 
311
335
  ```python
312
336
  from relaygpu import is_accepted
313
337
 
314
- 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
315
339
  sub = relay.run("KlingTeam/v3-T2V", {"prompt": "waves", "duration": 3}, wait=False)
316
340
  if is_accepted(sub):
317
341
  print(sub["task_id"]) # the 202 envelope
@@ -333,7 +357,8 @@ knows also get `Literal` hints for autocomplete.
333
357
  `wait=False` returns the `202` envelope instead (narrow it with `is_accepted`).
334
358
  - Request options are keyword arguments on every call: `timeout`, `on_progress`, `mode`, `store_output`,
335
359
  `webhook_url`, `idempotency_key`, `async_` (trailing underscore: `async` is a keyword), `upload`,
336
- `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.
337
362
 
338
363
  ## Async tasks and `tasks.wait`
339
364
 
@@ -352,7 +377,7 @@ task = relay.tasks.wait(
352
377
  second. `on_progress` fires on status transitions (`queued` → `running` → `completed`) with `elapsed_seconds`,
353
378
  and that is all there is: no queue position, no logs and no cancel, by design. A failed task raises
354
379
  `TaskFailedError` with `code` = the task's `error_code`. Task polls need no key: the task id is the access
355
- 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.
356
381
 
357
382
  Workflow runs have no long-poll: `workflows.wait_run` polls the run every 1 s, backing off to 5 s (default
358
383
  budget 30 min).
@@ -387,6 +412,8 @@ relay.files.list(source="upload") # one page; files.list_all(...) iterates ever
387
412
  relay.files.delete(file["file_id"]) # the link goes down now; no refund
388
413
  ```
389
414
 
415
+ - Only image, video and audio files are accepted; any other type is refused with `415`
416
+ (`FILE_TYPE_UNSUPPORTED`).
390
417
  - `files.upload` takes `bytes`, a path (`pathlib.Path` or `str`), a binary file object (`open(p, "rb")`) or an
391
418
  iterator of bytes (`AsyncRelay` also takes an async iterator). Paths and file objects are streamed in
392
419
  chunks, never read whole into memory.
@@ -397,7 +424,9 @@ relay.files.delete(file["file_id"]) # the link goes down now; no refund
397
424
  ones are still uploaded.
398
425
  - One file is at most 100 MB (the server answers `413`, `FileTooLargeError`). The media type comes from
399
426
  `content_type=`, else from the file's first bytes.
400
- - `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.
401
430
 
402
431
  ## How long result links live
403
432
 
@@ -405,7 +434,7 @@ Result links (`urls`, `audio_url`, …) and uploaded files expire. By default a
405
434
  after the task finishes. To keep outputs longer, buy storage per request with `store_output`:
406
435
 
407
436
  ```python
408
- 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")
409
438
  ```
410
439
 
411
440
  | `store_output` / `retention` | Lifetime | Fee |
@@ -435,6 +464,9 @@ checks the signature and the timestamp (±5 min, `tolerance=300`) and returns th
435
464
  - Delivery is at-least-once: dedupe on the `webhook-id` header.
436
465
  - `relay.webhooks.secret()`, `.rotate_secret()` and `.deliveries.list()` / `.deliveries.get(task_id_or_run_id)`
437
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.
438
470
 
439
471
  ## Errors
440
472
 
@@ -466,7 +498,7 @@ from `relaygpu`). A code this release does not know falls back to the status cla
466
498
  from relaygpu import KeyBudgetExhaustedError, RateLimitError, RelayAPIError
467
499
 
468
500
  try:
469
- relay.image.generate("Qwen/qwen-image", {"prompt": "a lighthouse"})
501
+ relay.image.generate("black-forest-labs/FLUX-2-pro", {"prompt": "a lighthouse"})
470
502
  except KeyBudgetExhaustedError:
471
503
  print("this key's budget is spent")
472
504
  except RateLimitError as e:
@@ -477,6 +509,9 @@ except RelayAPIError as e:
477
509
 
478
510
  - `e.request_id` is the id to quote to support; `e.retry_after` (seconds) is set from `Retry-After`;
479
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`.
480
515
  - `TaskFailedError`: an async task (or workflow run) ended `failed`; `e.code` is the task's `error_code`,
481
516
  `e.task_id` and `e.task` carry the rest.
482
517
  - `APIConnectionError` (no HTTP answer), `APITimeoutError` (a `timeout` ran out),
@@ -508,12 +543,28 @@ relay.keys.revoke(key_id)
508
543
  These routes take a dashboard JWT or a custom-tier superkey. A plain inference key gets the server's 403
509
544
  (`PermissionDeniedError`); the SDK does not guess the key class. `keys.create` returns the full secret in
510
545
  `key` once; every later response masks it, so store it then. Address keys by `key_id`. `key_budget` is for
511
- 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.
512
563
 
513
564
  ## Cost estimates
514
565
 
515
566
  ```python
516
- 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})
517
568
  print(est["usd"], est["basis"])
518
569
  ```
519
570
 
@@ -555,14 +606,13 @@ CPython 3.10, 3.11, 3.12 and 3.13, tested in CI on each. One runtime dependency,
555
606
  (`AsyncRelay` runs on `asyncio`). `relay.request(method, path, json=...)` reaches any route
556
607
  with the same errors and retry policy.
557
608
 
558
- ## Chat
609
+ ## Text
559
610
 
560
- Chat is a base-URL swap on the official SDKs, in any language:
611
+ Chat is a base-URL swap on the official SDK, in any language:
561
612
 
562
613
  | SDK | Base URL |
563
614
  |---|---|
564
615
  | OpenAI | `https://relaygpu.com/v2/openai/v1` |
565
- | Anthropic | `https://relaygpu.com/v2/anthropic` |
566
616
 
567
617
  ## License
568
618
 
@@ -4,8 +4,8 @@
4
4
 
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
- generated from Relay's public OpenAPI spec. Chat is not wrapped: point the OpenAI or Anthropic SDK at Relay
8
- ([quickstart 6](#6-chat-use-the-sdk-you-already-have)). A port of the TypeScript client
7
+ generated from Relay's public OpenAPI spec. Chat is not wrapped: point the OpenAI SDK at Relay
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
 
@@ -252,9 +255,9 @@ with Relay(os.environ["RELAY_API_KEY"], base_url=os.environ.get("RELAY_BASE_URL"
252
255
  sys.exit(f"run {e.task_id} did not complete: {e}")
253
256
  ```
254
257
 
255
- ### 6. Chat: use the SDK you already have
258
+ ### 6. Text: use the SDK you already have
256
259
 
257
- Chat and completions run on the official OpenAI and Anthropic SDKs: point them at Relay. This SDK does not wrap
260
+ Chat and completions run on the official OpenAI SDK: point it at Relay. This SDK does not wrap
258
261
  chat. `openai` is an example dependency only (`pip install openai`); `relaygpu-client` does not need it.
259
262
  ([`examples/06_chat_base_url.py`](examples/06_chat_base_url.py))
260
263
 
@@ -274,12 +277,33 @@ completion = client.chat.completions.create(
274
277
  print(completion.choices[0].message.content)
275
278
  ```
276
279
 
280
+ The Responses API is the same swap, on the same base URL, for the `openai` models that list it (`GET /v2/models`):
281
+
282
+ ```python
283
+ response = client.responses.create(model="openai/gpt-5.5", input="Say hello in five words.")
284
+ print(response.output_text)
285
+ ```
286
+
287
+ Responses on Relay is stateless: Relay sets `store: false`, and `previous_response_id` and `conversation` are refused. Resend the `input` each turn.
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
+
277
301
  ## Any model: `run()` and model resolution
278
302
 
279
303
  ```python
280
304
  from relaygpu import is_accepted
281
305
 
282
- 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
283
307
  sub = relay.run("KlingTeam/v3-T2V", {"prompt": "waves", "duration": 3}, wait=False)
284
308
  if is_accepted(sub):
285
309
  print(sub["task_id"]) # the 202 envelope
@@ -301,7 +325,8 @@ knows also get `Literal` hints for autocomplete.
301
325
  `wait=False` returns the `202` envelope instead (narrow it with `is_accepted`).
302
326
  - Request options are keyword arguments on every call: `timeout`, `on_progress`, `mode`, `store_output`,
303
327
  `webhook_url`, `idempotency_key`, `async_` (trailing underscore: `async` is a keyword), `upload`,
304
- `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.
305
330
 
306
331
  ## Async tasks and `tasks.wait`
307
332
 
@@ -320,7 +345,7 @@ task = relay.tasks.wait(
320
345
  second. `on_progress` fires on status transitions (`queued` → `running` → `completed`) with `elapsed_seconds`,
321
346
  and that is all there is: no queue position, no logs and no cancel, by design. A failed task raises
322
347
  `TaskFailedError` with `code` = the task's `error_code`. Task polls need no key: the task id is the access
323
- 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.
324
349
 
325
350
  Workflow runs have no long-poll: `workflows.wait_run` polls the run every 1 s, backing off to 5 s (default
326
351
  budget 30 min).
@@ -355,6 +380,8 @@ relay.files.list(source="upload") # one page; files.list_all(...) iterates ever
355
380
  relay.files.delete(file["file_id"]) # the link goes down now; no refund
356
381
  ```
357
382
 
383
+ - Only image, video and audio files are accepted; any other type is refused with `415`
384
+ (`FILE_TYPE_UNSUPPORTED`).
358
385
  - `files.upload` takes `bytes`, a path (`pathlib.Path` or `str`), a binary file object (`open(p, "rb")`) or an
359
386
  iterator of bytes (`AsyncRelay` also takes an async iterator). Paths and file objects are streamed in
360
387
  chunks, never read whole into memory.
@@ -365,7 +392,9 @@ relay.files.delete(file["file_id"]) # the link goes down now; no refund
365
392
  ones are still uploaded.
366
393
  - One file is at most 100 MB (the server answers `413`, `FileTooLargeError`). The media type comes from
367
394
  `content_type=`, else from the file's first bytes.
368
- - `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.
369
398
 
370
399
  ## How long result links live
371
400
 
@@ -373,7 +402,7 @@ Result links (`urls`, `audio_url`, …) and uploaded files expire. By default a
373
402
  after the task finishes. To keep outputs longer, buy storage per request with `store_output`:
374
403
 
375
404
  ```python
376
- 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")
377
406
  ```
378
407
 
379
408
  | `store_output` / `retention` | Lifetime | Fee |
@@ -403,6 +432,9 @@ checks the signature and the timestamp (±5 min, `tolerance=300`) and returns th
403
432
  - Delivery is at-least-once: dedupe on the `webhook-id` header.
404
433
  - `relay.webhooks.secret()`, `.rotate_secret()` and `.deliveries.list()` / `.deliveries.get(task_id_or_run_id)`
405
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.
406
438
 
407
439
  ## Errors
408
440
 
@@ -434,7 +466,7 @@ from `relaygpu`). A code this release does not know falls back to the status cla
434
466
  from relaygpu import KeyBudgetExhaustedError, RateLimitError, RelayAPIError
435
467
 
436
468
  try:
437
- relay.image.generate("Qwen/qwen-image", {"prompt": "a lighthouse"})
469
+ relay.image.generate("black-forest-labs/FLUX-2-pro", {"prompt": "a lighthouse"})
438
470
  except KeyBudgetExhaustedError:
439
471
  print("this key's budget is spent")
440
472
  except RateLimitError as e:
@@ -445,6 +477,9 @@ except RelayAPIError as e:
445
477
 
446
478
  - `e.request_id` is the id to quote to support; `e.retry_after` (seconds) is set from `Retry-After`;
447
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`.
448
483
  - `TaskFailedError`: an async task (or workflow run) ended `failed`; `e.code` is the task's `error_code`,
449
484
  `e.task_id` and `e.task` carry the rest.
450
485
  - `APIConnectionError` (no HTTP answer), `APITimeoutError` (a `timeout` ran out),
@@ -476,12 +511,28 @@ relay.keys.revoke(key_id)
476
511
  These routes take a dashboard JWT or a custom-tier superkey. A plain inference key gets the server's 403
477
512
  (`PermissionDeniedError`); the SDK does not guess the key class. `keys.create` returns the full secret in
478
513
  `key` once; every later response masks it, so store it then. Address keys by `key_id`. `key_budget` is for
479
- 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.
480
531
 
481
532
  ## Cost estimates
482
533
 
483
534
  ```python
484
- 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})
485
536
  print(est["usd"], est["basis"])
486
537
  ```
487
538
 
@@ -523,14 +574,13 @@ CPython 3.10, 3.11, 3.12 and 3.13, tested in CI on each. One runtime dependency,
523
574
  (`AsyncRelay` runs on `asyncio`). `relay.request(method, path, json=...)` reaches any route
524
575
  with the same errors and retry policy.
525
576
 
526
- ## Chat
577
+ ## Text
527
578
 
528
- Chat is a base-URL swap on the official SDKs, in any language:
579
+ Chat is a base-URL swap on the official SDK, in any language:
529
580
 
530
581
  | SDK | Base URL |
531
582
  |---|---|
532
583
  | OpenAI | `https://relaygpu.com/v2/openai/v1` |
533
- | Anthropic | `https://relaygpu.com/v2/anthropic` |
534
584
 
535
585
  ## License
536
586
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "relaygpu-client"
7
- version = "0.1.2"
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")