Cost control
Know the most a session can cost before you allocate it, and know when it has stopped billing, even after the process that owned it crashed.
At the rate Reactor’s pricing API stated for H3 on 2026-09-30, $0.035 a second, a session bills
$2.10 a minute and $126 an hour from ready until it is terminated, idle or not. See
Going live for the rate and Reactor’s account limits.
What the SDK does for you
Section titled “What the SDK does for you”- A creating token states its session’s cap.
coordinator.tokensandmintTokenrefuse a token that may create sessions unless it namesmaxSessionDuration: one second to a day, or"unlimited"written out. Reactor terminates a capped session at its cap, after its token expires too. A grant Reactor echoes wider than asked is refused (Protocol), and a narrower one caps the session at what it grants. - Termination is confirmed, not assumed.
session.closesends theDELETE, then reads the session independently, since aDELETEresponse alone proves nothing: a read that finds itCLOSEDconfirms it, and so do two reads in a row that find it gone, since a coordinator can lose a running session for one read. Any other answer leavesconfirmedfalse andSession.mayStillBilltrue. TheCloseReport’sremotesays what happened:attempted,responseReceived,confirmed, theevidence("absent"or"terminal"), theDELETEstatus and the state read. OnlyCLOSEDis terminal: a session that readsINACTIVEis still live and billed. Session.mayStillBill(report)is true when this process owned the session and no read confirmed its end, or when it asked for an allocation whose answer, and so whose id, never came. AnAcquisitionFailurecarries the same report incleanup, and a playout’scleanupkeeps every report that may still bill.- A ledger records every paid session before it connects. A
Ledgerkeeps an entry for each session this application owns, in a store the application provides: a JSON file (Ledger.layerFile), memory (Ledger.layerMemory) or aLedger.Storeof its own.ledger.source(H3Source.opener({ tokens }))is a playout’sopen. It records each session after allocation and before it connects, so a session it cannot record is closed unconnected, and it forgets the entry only once Reactor confirms the session’s end. An end Reactor does not confirm is markedendingand asked again, 5 s after the first and doubling to at most 5 minutes apart, for as long as the session runs. - What a crashed process left is ended or taken back. Before it allocates anything,
ledger.sourcesettles every session recorded for its coordinator that the ledger does not hold: it resumes the one that ends last, while a minute of its cap remains, ends the rest, and waits until Reactor confirms each end. Only the API key ends a session whose owner died, so the ledger’sCoordinatorClientcarries it. For a session found any other way,CoordinatorClient.terminateUntilConfirmed(sessionId)asks until Reactor confirms its end;H3Source.resume({ allocation, tokens })adopts one with tokens bound to it, andreactor.attach({ sessionId, tokens, adopt: true })takes over a raw session’s lifetime. - No pool of sessions. The SDK keeps nothing warm. If you pool sessions, Effect’s
Pool.makeWithTTLoverreactor.create, withmin: 0and a shorttimeToLive, closes a session left idle;Pool.makekeeps every session, and its bill, until the pool’s scope closes.
On hosted Reactor, all 27 paid sessions of the 21 runs from 2026-09-24 to 09-29 ended with their
termination confirmed. Where the runs timed it, CLOSED read 0.63–0.86 s after the DELETE
(hosted evidence).
A budgeted, recorded session
Section titled “A budgeted, recorded session”-
Price the cap before anything is allocated:
import { Effect, Layer, Ref } from "effect";import {CoordinatorClient,H3,H3Source,Ledger,Playout,Reactor,ReactorError,} from "reactor-effect-client";const mostItCanCost = Effect.fn("mostItCanCost")(function* (capSeconds: number) {const coordinator = yield* CoordinatorClient.CoordinatorClient;const rate = yield* CoordinatorClient.modelRate(yield* coordinator.pricing, H3.modelName);return (capSeconds * rate.creditsPerSecond) / rate.creditsPerDollar;});On 2026-09-30,
mostItCanCost(120)is $4.20. -
Record every session before it connects, in a ledger. Provide the ledger once, over a
CoordinatorClientthat holds the API key, and open each session through it:// REACTOR_API_KEY gives the key, which ends any session of the account.const LedgerLive = Ledger.layerFile("evidence/ledger.json").pipe(Layer.provideMerge(CoordinatorClient.layerConfig),);const open = Effect.gen(function* () {const coordinator = yield* CoordinatorClient.CoordinatorClient;const ledger = yield* Ledger.Ledger;return yield* ledger.source(H3Source.opener({tokens: coordinator.tokens({ modelName: H3.modelName, maxSessionDuration: "30 minutes" }),}),);});The file holds the entries as a JSON list, such as
[{"sessionId":"…","model":"reactor/h3-reference-to-video-turbo-realtime","apiUrl":"https://api.reactor.inc","endsAt":1790815443.619,"state":"live"}]. One store belongs to one process and one Reactor account: two processes on one store would end each other’s sessions as leftovers. -
Budget the sessions. A playout calls
openfor its first session and every replacement. Count them, and refuse past a limit with a failure that allocated nothing:const withSessionBudget = <R>(limit: number,openOne: Effect.Effect<Playout.Source, ReactorError.ReactorFailure, R>,) =>Effect.map(Ref.make(0), (opened) =>Ref.getAndUpdate(opened, (count) => count + 1).pipe(Effect.flatMap((count) =>count < limit? openOne: Effect.fail(ReactorError.AcquisitionFailure.from(ReactorError.ReactorError.fromCode("InvalidState","the session budget is spent",),Reactor.noAcquisition,),),),),);const budgeted = yield* withSessionBudget(4, open)gives anopenforPlayout.make. Past the budget, the playout airs its last session until that session’s cap ends, then stops. With 30-minute sessions, a budget of 4 bounds the channel at two hours of sessions, $252. -
Let closing end each session. Closing a source the ledger opened, as the playout does at each renewal and when its scope closes, ends the session and forgets its entry once Reactor confirms the end. An end Reactor does not confirm leaves the entry
ending, asked again until it is confirmed, and the close report the playout keeps says the session may still bill.ledger.entrieslists what is still recorded:const stillEnding = Effect.gen(function* () {const ledger = yield* Ledger.Ledger;const entries = yield* ledger.entries;return entries.filter((entry) => entry.state === "ending");}); -
After a crash, open as before. The next process’s first
openends or resumes what the dead one recorded before it allocates anything, and waits while an end is unconfirmed, since that session may still bill; a playout’srenewal.openTimeoutbounds the wait. To end everything the ledger does not hold, at shutdown or by hand, runledger.release. It answers the ends Reactor confirmed, and those it still asks for:const endLeftovers = Effect.gen(function* () {const ledger = yield* Ledger.Ledger;const { ended, ending } = yield* ledger.release;yield* Effect.logInfo(`${ended.length} ended, ${ending.length} still ending`);});A session found any other way, such as in the dashboard, ends with
CoordinatorClient.terminateUntilConfirmed(sessionId)and a key-holdingCoordinatorClient.
On the simulated Reactor this ran as described: the price came to $4.20, a budget of two refused a
third session, and a second process’s ledger, on the file a first had left, ended both sessions
that first had open, each reading CLOSED, and kept no entry.
Practice
Section titled “Practice”- Cap everything, short where people wander off. A page’s session ends with the page only if the page gets to close it; the cap bounds the rest. The browser guide’s token server caps sessions at five minutes.
- A dropped connection keeps billing. Reactor’s
session docs say it ends 30 seconds after its last
connection drops. In a paid probe on 2026-09-30, a connected session whose owner was killed still
read
INACTIVE60 seconds later. The API key ended it, and the dashboard billed 1m 3s, including the disconnected time (0.8.0-dropped).Reactor.layer({ reconnect: false })leaves a drop down untilsession.reconnect; the session may keep billing until terminated or capped. End owned sessions withsession.close, let the ledger end what a crash left, and cap them. - A session nothing connects to bills to its cap. In a paid probe on 2026-09-29, a session
allocated and never connected read
ACTIVEfor its whole minute and was ended by Reactor at its 60-second cap, 60.09 s after allocation; the dashboard listed it at 1m 0s. A creator that crashes between allocation and connection leaves exactly this, which is why the ledger records a session before it connects. - A spent token creates nothing more. In the same probe, a second create on a single-session
token whose session already existed was refused with
403. The tokenscoordinator.tokensmints each create one session, so a retried create cannot allocate a second. - Only a termination stops the meter. A viewer leaving a shared session does not stop it. In
the paid runs, the API key and an adopting process each ended a session they had not created.
reactor.attachwithoutadoptnever terminates the session it joined, and closing it leaves the session running. - Renewals overlap. A playout opens each replacement before the retiring session ends, so two
sessions bill together for a few seconds at each renewal: 6 to 9 seconds in the paid
showruns. Very short caps multiply that. - Rehearse the bill.
ReactorTest’sbillingcounts simulated seconds and dollars; passcreditsPerSecond: 350for the rate published on 2026-09-30 and assert a budget in a test, as Test offline does. - Watch the dashboard. The Reactor dashboard lists each session’s duration to the second. Reactor publishes no usage endpoint yet, and the paid runs’ balance readings matched neither the published rate nor whole minutes, so read your balance there.