Repository navigation
Add Inferrail Hosted: shared per-run budgets with self-serve credits (experimental) - #148
Merged
Merged
Conversation
A hosted gateway workspace where per-run dollar budgets hold across every agent and machine using it. Provider keys are passed per request and never stored. Governed runs are metered (2,000/month free); prepaid credits can be bought by agents over x402 or by people through Stripe Checkout, from one credit ledger. Credits are granted only from settled x402 payments or signature-verified paid Checkout sessions, at most once per payment. The self-hosted gateway is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n reconciliation, refunds - A governed run holds one unit while its calls are in flight and is billed only when the provider answers; failed or budget-refused runs cost nothing. - An exclusive lock on the data directory enforces one instance; held runs left by a crash are released at startup. - Pending x402 purchases are reconciled from USDC authorizationState, so a payment that settled before a crash is still credited exactly once. - Stripe charge.refunded reverses credits proportionally and monotonically; a negative balance blocks paid runs. - Provider keys are scrubbed from error text; ledger reads share the writer lock; mainnet x402 refuses to start without an RPC. - Tests cover concurrency, restart, isolation, payment replay and interruption, and the full customer journey. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Founder review required: this PR adds product behavior, payments and public pricing. Do not merge without review. Merging does not deploy anything.
1. What a customer can now do
An agent or developer can:
GET /pricing,GET /llms.txt,docs/hosted/);POST /v1/workspaces, no account);X-Provider-Api-Key(sent per request, never stored);X-Inferrail-Attribute-Work-Id,X-Inferrail-Budget-Usd);GET /v1/work/{id});402 allowance_exhausted, listing how to buy, when the free allowance runs out;test_complete_customer_journeywalks this whole path.2. What the paid hosted offering adds
The open-source gateway already enforces per-run budgets on one machine, and this PR doesn't touch
src/inferrail(0 lines changed) or restrict it.The hosted service adds:
The underlying property is the one in the public per-run budget benchmark: a budget declared on the fly in a header holds under concurrent fan-out.
3. Implemented and tested
The service is
hosted/budget_gateway/, about 1,430 lines. It reuses the gateway's engines,BudgetEnforcer,ReceiptsStore, attribution, pricing and error codes, and the existing fake facilitator. It is not a fork of the trial service: the trial's in-memory tenants and key vault are the wrong lifecycle for paid workspaces.service.pyworkspaces.pystripe_checkout.pychain_check.pyauthorizationStateread for on-chain reconciliation39 tests, in
tests/unit/hosted/test_budget_gateway.py, plus a CI job that fails if any of them is skipped.Regression, on this branch's code:
tests/unit/hosted--ignore=tests/unit/hosted)ruff check .src/Security review (self-review; findings fixed in this PR):
BG_FORWARDED_ALLOW_IPS.BG_PER_WORK_MAX_USD.4. What remains experimental
"status": "experimental pricing".5. Exact guarantees and deployment constraints
flockon the data directory enforces this at startup.authorizationStateon chain.hosted/budget_gateway/README.md.6. Still needed before accepting real money
BG_FORWARDED_ALLOW_IPS, and DNS for the public URL.checkout.session.completedandcharge.refunded.BG_X402_PAY_TO,BG_X402_MAINNET_APPROVED=1,BG_BASE_RPC_URL, and the CDP API key for the facilitator.7. How a legitimate customer completes the first paid run
POST /v1/workspacesreturns a key.402 allowance_exhausted, listingPOST /v1/credits/checkout(card) andPOST /v1/credits/x402(USDC)./v1/credits/x402($1 USDC);8. Commercial evidence still missing
The plan is to publish the price, run it for 30 days, and read the result: