You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Test file:**`tests/test_streaming.py` (57 tests, all passing)
192
+
193
+
Added `StreamReservation` and `AsyncStreamReservation` context managers that automate the reserve → commit/release lifecycle for streaming use cases. This is a DX convenience layer — no protocol changes.
194
+
195
+
-**`StreamReservation`** — sync context manager: reserves on `__enter__`, auto-commits on successful `__exit__`, auto-releases on exception
196
+
-**`AsyncStreamReservation`** — async equivalent using `__aenter__`/`__aexit__`
197
+
-**`StreamUsage`** — mutable accumulator for token counts and cost during streaming
198
+
-**Client convenience methods:**`CyclesClient.stream_reservation()` and `AsyncCyclesClient.stream_reservation()` — thin factories that build Subject from config defaults
-**Context propagation:** sets/clears `CyclesContext` via `ContextVar`, accessible via `get_cycles_context()`
203
+
204
+
Protocol conformance: No new endpoints or protocol changes. All reservation, commit, release, and extend calls use the same client methods and body formats as the decorator path. Verified by 57 unit tests covering success, deny, error, retry, heartbeat, cost resolution, and context propagation.
For streaming LLM responses, use the `stream_reservation()` context manager. It reserves budget on enter, auto-commits on successful exit, and auto-releases on exception:
134
+
135
+
```python
136
+
from runcycles import CyclesClient, CyclesConfig, Action, Amount, Unit
# Committed automatically with actual cost from cost_fn
155
+
```
156
+
157
+
Also available as `async with client.stream_reservation(...)`for async clients. See [streaming_usage.py](examples/streaming_usage.py) for a complete example.
0 commit comments