I’d structure it as one grants system with two fulfillment modes:
Current System
Right now a grant approval becomes a SOL payout. The path is:
- Forum grant post creates a
grant_applications row.
- LLM/admin approval stores
gpu_type, recommended_hours, gpu_rate_usd, total_cost_usd.
- User replies with Solana wallet.
- Bot verifies wallet with a test payment.
- Bot queues final SOL payment via
payment_requests.
- Grant is marked
paid.
Relevant code:
src/features/grants/grants_cog.py approves grants and asks for a wallet.
src/features/grants/grants_cog.py starts the wallet/payment flow.
src/common/db_handler.py handles grant_applications.
The RunPod lifecycle package already has the primitives we need:
runpod-lifecycle/lifecycle.py launches pods with GPU/template/RAM/storage config.
runpod-lifecycle/pod.py waits for readiness.
runpod-lifecycle/pod.py checks idle GPU usage.
runpod-lifecycle/pod.py terminates pods.
Core Product Shape
I’d make grant approval produce either:
crypto_payout: current SOL flow.
gpu_allocation: internal compute balance, spent by launching RunPod machines.
Don’t overload grant_applications too much. Add a separate ledger:
-
gpu_allocations
allocation_id
guild_id
discord_user_id
source_type: grant, admin, unlimited
source_ref: grant thread id or admin action id
status: active, expired, revoked, depleted
budget_usd_cents
remaining_usd_cents
granted_gpu_type
granted_hours
expires_at
unlimited boolean
created_by
-
gpu_sessions
session_id
allocation_id
discord_user_id
runpod_id
status: provisioning, ready, terminating, terminated, failed
gpu_type, template_id, image, disk_gb, container_disk_gb, volume_name
cost_per_hr
started_at, ready_at, terminated_at
last_activity_at
idle_warning_sent_at
termination_reason
-
gpu_usage_events
- immutable ledger rows: launch, ready, hourly debit, idle warning, terminate, admin adjustment.
I’d store the canonical balance in USD cents, even if the UI says “20 H100 hours”. GPU-hours are not fungible across B200/H100/4090. On approval, convert the grant into a dollar budget using the same pricing logic. When the user launches a machine, debit by actual or configured RunPod hourly cost.
Grant Flow
On approval, the bot should ask:
Do you want this as a SOL payout, or as hosted GPU time?
If SOL: unchanged.
If GPU time:
- mark grant as
fulfilled_as = gpu_allocation
- create
gpu_allocations
- no wallet needed
- post/DM: “You have X compute credit. Use
/gpu launch when ready.”
For admins, add direct commands/tools:
- “Give Alice 25 H100 hours”
- “Give Bob unlimited GPU access”
- “Revoke Charlie’s compute”
- “Top Alice up by $50”
- “Show active machines”
Unlimited users should still create sessions and usage events. They just bypass budget depletion. That keeps observability and lets you kill idle/abusive machines.
Launch Bot Flow
User runs /gpu launch or DMs the bot.
Bot checks:
- user has active allocation or unlimited flag
- user has no active pod, or admin config allows multiple
- requested GPU/template is allowed
- estimated max runtime fits remaining balance
- account-level RunPod spend cap is not exceeded
Then it asks for:
- GPU type
- template/image
- disk/container disk size
- optional network volume
- SSH public key, preferably
- optional env vars/secrets, with strong restrictions
- intended max runtime
For access, safest path is: ask for SSH public key and inject it via RUNPOD_SSH_PUBLIC_KEY/pod env. Return SSH command, Jupyter/HTTP URL if exposed, pod id, cost/hr, and auto-shutdown policy. Avoid DMing generated private keys unless there is no alternative.
Lifecycle
A new GpuSessionsCog or service should wrap runpod_lifecycle:
- Create
gpu_sessions(status=provisioning).
- Call
launch(config, hooks=...).
- Persist RunPod pod id immediately.
wait_ready.
- Fetch SSH/port details.
- DM the user credentials/access info.
- Start periodic metering.
The lifecycle hooks are useful because they let us persist state transitions instead of relying on memory.
Billing And Termination
Run a scheduler every 5-10 minutes:
- refresh all active RunPod sessions
- compute elapsed billable time since last debit
- debit
gpu_allocations.remaining_usd_cents
- if balance hits zero: warn, then terminate after a short grace period
- if pod disappeared externally: mark terminated/reconciled
- if RunPod reports failed: mark failed and stop debiting
- if DB says terminated but RunPod still exists: terminate again
Idle shutdown:
- after 2 hours idle: DM/user thread warning
- after 3 hours idle: terminate
- idle = GPU util under threshold for repeated checks, not one sample
- ideally also check SSH command activity, Jupyter activity if possible, and active training processes
- allow users to run
/gpu keepalive 4h with limits, or admins can exempt a session
The existing Pod.is_idle() is a starting point, but I’d harden it before using it for real money because it only knows about last bot SSH command and current GPU utilization.
Important Constraints
I would not let arbitrary templates/env vars through unchecked at first. Start with an allowlist:
- approved RunPod templates
- approved GPU types
- max disk sizes
- max runtime
- max concurrent pods per user
- account-wide spend cap
- admin-only custom templates
This prevents someone from launching a giant expensive box or using the bot as a generic RunPod proxy.
Minimal First Version
The smallest clean build is:
- Add
gpu_allocations, gpu_sessions, gpu_usage_events.
- Add admin path to create allocations manually.
- Add grant approval option: SOL or GPU allocation.
- Add
/gpu launch, /gpu status, /gpu terminate.
- Integrate
runpod_lifecycle.launch, wait_ready, terminate.
- Add scheduler for budget depletion and idle termination.
- Keep templates/GPU types allowlisted.
That gives you the direct GPU-hours product without breaking the existing crypto grant flow.