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
- Send the question and FAQ notes to
/v1/embeddingswithout a model field. - Rank the returned vectors locally; no text search service is needed.
- Send the top notes to
/v1/chat/completions. - For a paid run, sign the x402 challenge and retry on the same network.