# 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. Operator: บริษัท พลังก์ แล็บส์ จำกัด (Planck Laps Co., Ltd.), 39/130 หมู่ที่ 7 ถนนสุขุมวิท ตำบลบ้านสวน อำเภอเมืองชลบุรี จังหวัดชลบุรี. 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 — LLM Chat (combo) - 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: combo (gateway-routed; 200K context, vision/PDF input, no tool calling) ## Service: legal-search — Legal Knowledge Search - Endpoint: `POST https://mpp.thaifi.com/legal/search` - Price: 0.1 THCFI per query (see /openapi.json for the authoritative offer) - Latency: instant - Body (JSON): `query` (required, 1–300 chars), optional `doc` (document id, see `GET /legal/outline`) and `limit` (1–20, default 8). - Response: `{ results: [{ doc_id, section, chapter, title, citation, body, analysis, amendment }] }` — queries like `มาตรา 26` resolve the exact section deterministically first; otherwise Thai/English trigram full-text search (BM25). - Content = actual gazette text split per มาตรา/ข้อ with curated analysis — informational, not legal advice. ## Service: legal-ask — Legal Q&A (RAG) - Endpoint: `POST https://mpp.thaifi.com/legal/ask` - Price: 0.5 THCFI per question (see /openapi.json for the authoritative offer) - Latency: a few seconds (LLM synthesis) - Body (JSON): `question` (required, 5–2000 chars), optional `doc` and `limit` (3–12, default 6). - Response: `{ answer, citations, results }` — the answer cites every section it used and ends with the not-legal-advice disclaimer. - Upstream down → 503 before payment (circuit breaker); upstream fails after payment → 502 `refundable: true`. ## Service: course — Course Booking - Endpoint: `POST https://mpp.thaifi.com/courses/{courseId}/register` - Price: per course — see GET /courses - 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: token-create — TIP-20 Token Creation - Endpoint: `POST https://mpp.thaifi.com/tokens/create` - Price: 1000 THCFI per token (see /openapi.json for the authoritative offer) - Latency: ~10-20s (7 on-chain transactions) - Body (JSON): `name` (max 64), `symbol` (2-11 A-Z0-9), `mint_amount` (integer human units, 1-1,000,000,000 — decimals are applied for you: 10,000 → 10,000.000000), `recipient` (optional — defaults to YOUR wallet, the payer), `logo_base64` (optional — base64 PNG or WebP, square, ≤1024x1024, ≤2MB; uploaded to assets.thaifi.com and set as the on-chain `logoURI()` so exp.thaifi.com shows it) - What you get: a REAL system TIP-20 on chain 17 (gas-payable standard, full standard interface), initial mint of `mint_amount` to `recipient`, supply locked at the minted amount, and **all admin rights handed to the paying wallet** (DEFAULT_ADMIN + ISSUER) — the service renounces its own roles, so the token is fully yours (raise the cap, pause, mint more — your call) - Response (JSON): `token` (address), `request_id`, `mint_amount_raw`, `recipient`, `logo_url`, `txs` (on-chain step hashes), `explorer_url` - Check later: `GET /tokens/{token_address}` — creation record - Note: your wallet (the payer) is the admin — keep its access key safe ## Service: voucher-create — Voucher / Ticket NFT Collection - Endpoint: `POST https://mpp.thaifi.com/vouchers/collections` - Price: 1,000 THCFI min. (incl. 5,000), then 0.20 THCFI per voucher — POST /vouchers/quote - Latency: ~10-20s (5 on-chain transactions) - Price: `max(1,000, quantity × 0.20)` THCFI — the 1,000 minimum covers up to 5,000 vouchers, each beyond costs 0.20 THCFI - First: `POST /vouchers/quote` (free, same body) — validates the order and returns the exact price. Ask your user the questions below until you have every required field, then quote, then create. - Required fields — `kind: "ticket"`: `name`, `organization`, `description`, `tier_name` (VIP/Regular/5KM…), `quantity`, `event_date` (ISO), `venue_name`; `kind: "voucher"`: `name`, `organization`, `description`, `tier_name`, `quantity`, `redemption_value` ("ส่วนลด 20%", "กาแฟ 1 แก้ว"), `redemption_instructions` - Optional: `valid_from`, `valid_until` (recommended for vouchers), `terms`, `external_url`, `symbol`, `recipient` (defaults to the paying wallet), `logo_base64` (base64 PNG/WebP square ≤1024x1024, ≤2MB) - What you get: a DEDICATED ERC-1155 contract for the collection (own name/symbol, source-verified), `quantity` units of token id 1 minted to `recipient`, ERC-1155 metadata JSON + logo on assets.thaifi.com, and full contract ownership (DEFAULT_ADMIN + MINTER) handed to the paying wallet - Response (JSON): `collection` (contract address), `token_id`, `quantity`, `metadata_url`, `txs`, `explorer_url` - Check later: `GET /vouchers/collections/{request_id}` - Distribute by ordinary transfers — scan-to-redeem flows can verify balance of the holder on chain ## 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) - `POST /vouchers/quote` — free voucher/ticket order validation + exact price (same body as /vouchers/collections) - `GET /tokens/{address}` — a created token's record (name, supply, recipient, txs) - `GET /vouchers/collections/{request_id}` — a voucher collection's record - `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 Created tokens live on https://tokens.thaifi.com (launchpad gallery with supply + holders); assets (logos, voucher metadata) at assets.thaifi.com. ## 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":"สุขสันต์วันเกิด"}'