QALS Wiki · the qalarc network⌂ qalarc.com/projects/qals
generated 2026-09-16 · qalcode autonomous research

Talking to AI with automatic token billing — the core use case, running today · content/ai-token-payments.md

Talking to AI with automatic token payments — the use case QALS was built for

Date: 2026-09-15 · Founder's question: "Would it be good for talking to AI with tokens and paying for those AI tokens automatically?"

Answer: Yes. This is the core design target. It's running today on the devnet.


The problem with paying for AI today

Current model Problem
Subscription (ChatGPT Plus, Claude Pro) Pay for what you don't use; hard cap regardless of need
API key (OpenAI, Anthropic) Pre-load $50; if it leaks, someone drains your account; no per-conversation receipts
Per-message (Pay-per-chat) Trust the platform's metering; no proof you got what you paid for
Free tier Rate-limited, no guarantees, your data is the product

What none of them give you: proof of what you paid for, hard spending limits, or the ability to let an AI agent spend on your behalf without risk.

How QALS solves it — the complete flow

YOU → "What is the weather in Sydney?"
  │
  ├── 1. PRE-AUTHORISE: Your agent places a hold for ~AU$0.01
  │      (estimate × 1.15 safety margin, held from YOUR wallet)
  │
  ├── 2. THE AI RESPONDS: the model generates 150 tokens
  │      (runs on our compute, or a data centre, or someone's gaming PC)
  │
  ├── 3. METER: exact cost = 150 tokens × $0.000002/token = AU$0.0003
  │      (the chain records: actual_tokens, actual_cost, model_used)
  │
  ├── 4. SETTLE: AU$0.0003 paid to the compute provider
  │      remainder of your hold released back to you
  │
  ├── 5. RECEIPT: tamper-proof proof anchored on-chain:
  │      "150 tokens, model glm-4.7, cost AU$0.0003, 
  │       provider: minirig, timestamp: 2026-09-15 14:23:01"
  │
  └── You got your answer. The provider got paid. 
     You have a receipt. Nobody could overcharge you.

Total time: under 1 second for the payment (the AI inference is the slow part).

What's already running today

Component Status What it does
qalkeys (port 8841) ✅ Live, 66/66 tests Metered API gateway: you get a qk_ key, every call is charged per-token or per-request
Agent payment loop (loopd) ✅ Live, 14/14 ceremony Holds → settle at actual → receipts anchored
Compute marketplace (qmarket) ✅ Live, 62/62 tests GPU providers list compute, buyers pay per-job, escrowed
MCP server (qalmcp) ✅ Live, 24 tools AI agents can buy compute, send payments, check balances
Agent caps (loopd) ✅ Live, chain-enforced Every agent has a hard daily limit — bytecode, not policy

The three payment modes (all working)

Mode 1: Pay-per-token (like an API, but receipted)

# Get your API key
curl -X POST :8841/buy -d '{"listing_id":"glm-4.7-flash","buyer":"your-name"}'
# → {"api_key": "qk_abc123...", "daily_cap_cents": 500}

# Use it (every call is metered and charged automatically)
curl -X POST :8841/v1/proxy/glm-4.7-flash \
  -H "Authorization: Bearer qk_abc123" \
  -d '{"messages":[{"role":"user","content":"Hello"}]}'
# → AI response + you're charged exactly $0.0002
# → Receipt: {"tokens_used": 95, "cost_cents": 0.02, "receipt_id": "r_..."}

Mode 2: Agent with a capped wallet (the safety model)

# Create an AI agent with a AU$5/day spending limit
curl -X POST :8823/agents -d '{"name":"my-assistant","cap_cents_per_day":500}'
# → {"agent_id": "ag_...", "api_secret": "..."}

# The agent can now buy AI tokens automatically
# If it's compromised by prompt injection, it CANNOT exceed AU$5/day
# (enforced by the chain, not by us or by the agent's code)

# Check what it spent today
curl :8823/account/ag_...
# → {"balance_cents": 380, "spent_today_cents": 120, "cap_cents_per_day": 500}

Mode 3: Subscription with metering (the SaaS model)

# User prepays AU$20/month for AI chat
# Every message is metered: actual cost deducted from their balance
# They can see exactly what each message cost
# At the end of the month: "you used 2.3M tokens = AU$14.20 of your AU$20"
# → no wasted subscription, no surprise bills, every message receipted

Why this is BETTER than existing AI payment systems

Feature OpenAI API ChatGPT Plus QALS metered
Pay only for what you use ❌ flat fee
Per-request receipts ✅ on-chain, tamper-proof
Hard daily spending cap ❌ (your key = unlimited) ✅ (but blunt) ✅ per-agent, bytecode-enforced
AI agent can spend safely ❌ (leak = drained) n/a ✅ capped wallet, 2s revocation
Proof of model used ❌ (trust them) ✅ model hash in the receipt
Proof of output received ✅ output hash anchored
Works with any AI model ❌ (their models only) ✅ any provider lists on the market
Micro-payments (< $0.01) ❌ (minimum charges) n/a ✅ down to 0.01 cent
Offline / LAN ✅ relay works on LAN
Sell your own AI access ✅ list your model on qalkeys

The killer feature: PROOF

When you pay for AI tokens today, you trust the platform's metering. With QALS:

RECEIPT (anchored on-chain, verifiable by anyone):
{
  "model": "glm-4.7-flash",
  "model_hash": "0x7f3a...",           // proves WHICH model version ran
  "input_tokens": 45,
  "output_tokens": 95,
  "cost_cents": 0.03,                    // exact cost, integer math
  "provider": "minirig",                 // WHO ran the compute
  "provider_did": "did:qal:minirig",    // their verified identity
  "output_hash": "0xabc...",             // hash of the actual response
  "timestamp": 1789446000,
  "transaction": "0xdef..."              // the on-chain anchor
}

This proves: what model ran, what it cost, who provided the compute, and that the output hasn't been modified since. No AI platform today gives you this.

The business model

Who earns How
Compute providers Market price per token/second (they set their rate)
Model providers List their model on qalkeys, earn per inference
The network ZERO (the network itself charges nothing)
qalarc Top-up spread (the difference between sale price and redemption price)

A 7B model running on someone's gaming PC can list at half the price of OpenAI and still earn more per inference — because there's no platform fee, no middleman, no 30% app store cut. Just: provider lists → buyer pays → provider earns → both get receipts.

What this means for the AI agent economy

The 2026 AI landscape has a problem: agents need to pay for things, but giving them API keys or credit cards is dangerous. Every month there's another "AI agent drained my account" story.

QALS solves this structurally: - Hard caps — the agent physically cannot spend beyond its limit - Pre-authorisation — every purchase is held before the work starts - Receipts — every transaction is provable - Revocation — kill a compromised agent in 2 seconds - Metering — pay per token, not per month

This is the wallet that makes it safe to give AI agents spending power.