SpriteDX - Billing - Partner APIs

Working on adding billing in SpriteDX.
Right now, we got to a point where we have Google Auth via Supabase.
Then, there is a credits and transactions table.
credits table records cached balance and transactions record credit transations.
Then, when RunPod ComfyUI needs to use Partner API, it sends the partner API request to a proxy.
UI → Cloudflare A → RunPod (ComfyUI) → Cloudflare B → api.comfy.org
UI passes Supabase authentication token to Cloudflare A.
Cloudflare A authenticates the user then creates a “request_token,” then includes it when it sends the request to RunPod.
RunPod runs without any API keys for safety reasons. But if it want to run any ComfyUI Partner APIs, it will just submit it to our proxy Cloudflare B with a “request_token.“
Cloudflare B validates the request against a allowlist. This allowlist includes pricing information for the request.
It validates if the request should be allowed.
It checks available credit and see if this generation can happen.
Relays the request.
Spend the credit and records it into credits_transactions and update the cached_credits in credits table (single RPC).
If spending is successful, relay the response.

This is more of a prototype and not released yet. I am going to work on it more.
Next Steps:
Only decrease the credit when generation completes
Retrieve the pricing information from api.comfy.org.
Support for unauthenticated mode.
Rate limiting for unauthenticated users.
Add ability to charge credits.
Better error messages for credit related errors.
Support for BFL and Fal.ai endpoints.
Automatic broken user detection.
— Sprited Dev 🐛




