Skip to content

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.

  • A creating token states its session’s cap. coordinator.tokens and mintToken refuse a token that may create sessions unless it names maxSessionDuration: 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.close sends the DELETE, then reads the session independently, since a DELETE response alone proves nothing: a read that finds it CLOSED confirms 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 leaves confirmed false and Session.mayStillBill true. The CloseReport’s remote says what happened: attempted, responseReceived, confirmed, the evidence ("absent" or "terminal"), the DELETE status and the state read. Only CLOSED is terminal: a session that reads INACTIVE is 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. An AcquisitionFailure carries the same report in cleanup, and a playout’s cleanup keeps every report that may still bill.
  • A ledger records every paid session before it connects. A Ledger keeps an entry for each session this application owns, in a store the application provides: a JSON file (Ledger.layerFile), memory (Ledger.layerMemory) or a Ledger.Store of its own. ledger.source(H3Source.opener({ tokens })) is a playout’s open. 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 marked ending and 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.source settles 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’s CoordinatorClient carries 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, and reactor.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.makeWithTTL over reactor.create, with min: 0 and a short timeToLive, closes a session left idle; Pool.make keeps 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).

  1. 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.

  2. Record every session before it connects, in a ledger. Provide the ledger once, over a CoordinatorClient that 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.

  3. Budget the sessions. A playout calls open for 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 an open for Playout.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.

  4. 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.entries lists 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");
    });
  5. After a crash, open as before. The next process’s first open ends 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’s renewal.openTimeout bounds the wait. To end everything the ledger does not hold, at shutdown or by hand, run ledger.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-holding CoordinatorClient.

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.

  • 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 INACTIVE 60 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 until session.reconnect; the session may keep billing until terminated or capped. End owned sessions with session.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 ACTIVE for 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 tokens coordinator.tokens mints 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.attach without adopt never 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 show runs. Very short caps multiply that.
  • Rehearse the bill. ReactorTest’s billing counts simulated seconds and dollars; pass creditsPerSecond: 350 for 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.