MapleAI
Runnable TypeScript example

Free embeddings to paid GPT

The sample embeds a question and a local FAQ, ranks the notes by cosine similarity, then asks GPT to answer from the retrieved context. Embeddings are free; the chat call uses an x402 wallet payment with a configurable USDC cap. Use non-sensitive text only.

Run it

npm install
cp env.example .env
# Set EVM_PRIVATE_KEY for Base, or MAPLEAI_NETWORK=solana and SVM_PRIVATE_KEY
npm run demo -- --quote-only "How do I use embeddings with MapleAI?"
npm run demo -- "How do I use embeddings with MapleAI?"

Node.js 22+. The quote-only run makes no payment. The full run signs only the challenge returned by MapleAI and enforces MAPLEAI_MAX_PAYMENT_USDC.

Project files

Request flow

  1. Send the question and FAQ notes to /v1/embeddings without a model field.
  2. Rank the returned vectors locally; no text search service is needed.
  3. Send the top notes to /v1/chat/completions.
  4. For a paid run, sign the x402 challenge and retry on the same network.