Account model
- Ledger — one per wallet. Holds unallocated funds.
- Sub-accounts — one per (user, provider) pair. Created automatically on the first
transfer_fundoracknowledge_provider_signer. - Service types — each sub-account is scoped to a service type (
"inference"or"fine-tuning"). The same provider can hold two independent sub-accounts.
og_to_wei() / wei_to_og() helpers:
Create or top up your ledger
Deposit on behalf of another wallet
deposit_fund_for lets you fund a different address’s ledger:
Query balances
Simple balance
get_ledger() returns a LedgerAccount with balance, locked, and total_balance — all in wei:
account.available is an alias for account.balance. If no ledger exists yet, get_ledger() raises ContractError.
Detailed balance with provider breakdown
get_ledger_with_detail() includes per-provider balances for both inference and fine-tuning sub-accounts:
List providers with active balances
"fine-tuning" for fine-tuning providers.
Transfer funds to a provider
Before a provider will accept requests, you must move a portion of your ledger into their sub-account. The recommended minimum is 1 OG — anything smaller will succeed on-chain but may be rejected by the provider’s broker.service_type must be one of "inference" or "fine-tuning" — the SDK resolves these to the on-chain registered service name automatically. If you’re working against a custom deployment you can pass the exact registered name instead.
Passing
amount=0 creates the sub-account without moving any funds. This is useful if the provider supports pay-after-use, or if you want to pre-create the account before the first real transfer.Reclaim unused funds
Transfers aren’t final. You can pull funds from provider sub-accounts back into your ledger, or from your ledger back to your wallet.Refund from all providers
Refund from a specific provider
Withdraw from the ledger to your wallet
Close an account
When you’re completely done with 0G Compute, you can delete your ledger entirely:Auto-funding
For long-running processes (e.g. a production inference server), the SDK can keep a provider sub-account topped up automatically. A daemon thread checks the balance everyinterval_ms and transfers more funds when it falls below a threshold.
- Runs immediately on start, then every
interval_msthereafter - Computes
required = buffer_multiplier × MIN_LOCKED_BALANCE(500 wei minimum) - Calls
transfer_fundto addrequired - availablewhenever the sub-account drops below the threshold - Thread is a daemon — it exits with your process and won’t block shutdown
- Silently ignores transient failures so the loop never crashes
Check auto-funding status
Full lifecycle example
API at a glance
LedgerManager
| Method | Returns |
|---|---|
add_ledger(amount: str) | receipt dict — creates ledger, min 3 OG |
deposit_fund(amount: str) | receipt dict — top up existing ledger |
deposit_fund_for(recipient, amount) | receipt dict — fund another address |
get_ledger() | LedgerAccount(balance, locked, total_balance) |
get_ledger_with_detail(inference_contract=None, fine_tuning_contract=None) | LedgerDetail |
transfer_fund(provider, service_type, amount: int = 0) | receipt dict — service_type is "inference" or "fine-tuning" |
retrieve_fund(service_type) | receipt dict — reclaim from all providers |
retrieve_fund_from_provider(provider, service_type) | receipt dict |
refund(amount: str) | receipt dict — withdraw from ledger |
delete_ledger() | receipt dict — destructive |
get_providers_with_balance(service_type) | list[str] |
InferenceManager auto-funding
| Method | Returns |
|---|---|
start_auto_funding(provider, config=None) | None |
stop_auto_funding(provider=None) | None |
has_auto_funding(provider) | bool |
Next steps
Service discovery
Find providers and inspect their service metadata.
Inference
Make authenticated AI requests using funded provider sub-accounts.