# ThaiFi MPP Machine Payments Protocol (MPP) server on ThaiFi chain 17. Agents pay per request with **THCFI** (`0x20c000000000000000000000c82102FFe7064362`, 6 decimals) from an on-chain access key. Protocol: MPP `tempo` charge, push mode. Canonical service catalog: `GET https://mpp.thaifi.com/services` (JSON, always current). Payment flow per paid service: on `402 Payment Required`, pay the quoted amount to the recipient on chain 17 (include an MPP attribution memo bound to the challenge), then retry with the payment credential (`Authorization: Payment `). ## Service: iapp — iApp Image Generation - Endpoint: `POST https://mpp.thaifi.com/iapp/generate` - Price: 1.5 THCFI per image (see /openapi.json for the authoritative offer) - Latency: ~20-45s per image - Body (JSON): `prompt` (required, max 1500 chars), `text` (Thai text to render exactly), `font` (default kanit-bold), `size` (1024x1024|1280x768|768x1280|1536x1024|1024x1536), `style`, `seed`, `text_scale` (0.2-0.9) - Response (JSON): `status`, `id`, `width`, `height`, `mime_type`, `image_base64`, `time` ## Service: qwen — Qwen Image - Endpoint: `POST https://mpp.thaifi.com/qwen/generate` - Price: 1 THCFI per image (see /openapi.json for the authoritative offer) - Latency: ~45-60s per image - Body (JSON): `prompt` (required, max 1500 chars), `size` (1024x1024|1280x768|768x1280|1536x1024|1024x1536), `seed`, `n` (1-4) - Response (JSON): `status`, `id`, `width`, `height`, `mime_type`, `image_base64`, `time`, `engine` - Engine: Qwen/Qwen-Image-2.1 on our own GPU — photorealistic subjects, studio-style backgrounds ## Service: qwen3.8 — Qwen3.8 LLM - Endpoint: `POST https://mpp.thaifi.com/llm/chat` - Price: 0.2 THCFI per request (see /openapi.json for the authoritative offer) - Latency: a few seconds to ~1 min depending on completion length - Body (JSON): `messages` (required, OpenAI-compatible `{role, content}` array; roles: system|user|assistant|tool), `temperature` (default 0.7), `max_tokens` (default 1024, hard cap 4096 so the flat price cannot be abused with huge generations) - Response (JSON): OpenAI-compatible chat completion object - Model: nvidia/Qwen3.8-27B-NVFP4 (128K context, tool calling) ## Service: course — Course Booking - Endpoint: `POST https://mpp.thaifi.com/courses/{courseId}/register` - Price: per course — `GET /courses` for current prices and seats - Latency: instant - First: `GET /courses` (free) — list courses with `id`, price (THCFI), seats left, date and location - Then: `POST /courses/{courseId}/register` with `email`, `firstName`, `lastName` (`phone` optional) - On `402` the amount to pay is THAT course's price; after payment the booking is confirmed and the response carries `bookingRef` and `checkinCode` (also emailed to the attendee — show the code at the door) - Ask again later: `GET /bookings/{bookingRef}`, or recover by email: `POST /bookings/lookup` `{"email":"…"}` → OTP arrives by email → `POST /bookings/verify` `{"email":"…","otp":"…"}` returns all bookings with their codes - `409 course_full` / `course_closed` / `already_registered` — refused BEFORE any payment is taken ## Service: agent-auth — Agent Auth (free) - Endpoint: `GET https://mpp.thaifi.com/whoami` - Price: free — requires agent identity, no payment - Auth: ThaiFi Agent Auth (TAA) — the server answers `401` with `WWW-Authenticate: ThaiFiAgent realm="…", challenge="", expires=""`. Sign `keccak256(tag("thaifi-agent-auth")[0:4] ‖ 0x01 ‖ keccak256(realm)[0:10] ‖ nonce ‖ utf8(METHOD) ‖ utf8(path?query) ‖ sha256(body) | 0x00*32 ‖ uint64be(unix timestamp))` with your on-chain access key and retry with `Authorization: ThaiFiAgent `. The server verifies your key against the AccountKeychain precompile — revoked/expired keys are rejected by the chain itself. - `thaifi request` answers this challenge automatically (v0.3.0+) - Response (JSON): `account`, `keyId`, `keyType`, `expiry`, `spendPolicy`, `token` ## Other endpoints - `GET /courses` — course catalog (id, price, seats left, date/location) - `GET /bookings/{ref}` — booking status + check-in code - `POST /bookings/lookup` `{"email":"…"}` + `POST /bookings/verify` `{"email":"…","otp":"…"}` — recover bookings by email (OTP) - `GET /services` — machine-readable service catalog (canonical discovery) - `GET /stats` — usage & sales stats (JSON), optional `?window=24h|7d|30d|all` - `GET /iapp/fonts` — free, list of Thai typefaces - `GET /openapi.json` — discovery document with x-payment-info offers - `GET /healthz` — liveness ## Client `npm i -g thaifi-wallet-cli` then: thaifi login thaifi services thaifi request https://mpp.thaifi.com/iapp/generate -X POST \ -H 'content-type: application/json' \ -d '{"prompt":"การ์ดวันเกิด","text":"สุขสันต์วันเกิด"}'