• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
filipecabaco

filipecabaco

nanosupabase-demo

Chat API with nano-supabase
Public
Like
nanosupabase-demo
Home
Code
2
README.md
index.ts
Environment variables
Branches
1
Pull requests
Remixes
History
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
README.md
Code
/
README.md
Search
2/2/2026
Viewing readonly version of main branch: v2
View latest version
README.md

Val.town Example

Deploy nano-supabase as a serverless API on Val.town.

Quick Start

  1. Go to val.town and create a new HTTP val
  2. Copy the contents of index.ts into the editor
  3. Your API is instantly live at https://YOUR_USERNAME-YOUR_VAL_NAME.web.val.run

Using the vt CLI

# Install vt CLI npm install -g @valtown/vt # Login vt login # Create the val from this folder cd examples/valtown vt create my-chat-api . --no-editor-files --upload-if-exists --public # Or clone and modify an existing one vt clone filipecabaco/nano-chat

API Endpoints

MethodPathDescription
GET/API info and available endpoints
GET/conversationsList all conversations
POST/conversationsCreate conversation { title: string }
GET/messages?conversation_id=xxxGet messages for a conversation
POST/messagesAdd message { conversation_id, role, content, tokens? }
GET/statsGet usage statistics

Testing

# Get API info curl https://YOUR_USERNAME-YOUR_VAL_NAME.web.val.run/ # Create a conversation curl -X POST https://YOUR_USERNAME-YOUR_VAL_NAME.web.val.run/conversations \ -H "Content-Type: application/json" \ -d '{"title": "Test Chat"}' # Add a message curl -X POST https://YOUR_USERNAME-YOUR_VAL_NAME.web.val.run/messages \ -H "Content-Type: application/json" \ -d '{"conversation_id": "YOUR_ID", "role": "user", "content": "Hello!"}'

Adding Persistence

Val.town workers are stateless - the database resets on cold starts. For persistence, use Val.town's blob storage:

import { blob } from "https://esm.town/v/std/blob"; // Save state periodically async function saveState() { const dump = await db.dumpDataDir(); await blob.setJSON("chat-db-state", dump); } // Restore on startup (in getDb function) const saved = await blob.getJSON("chat-db-state"); if (saved) { db = new PGlite(); await db.loadDataDir(saved); }

Customization

The example uses a chat schema, but you can modify index.ts to:

  • Add your own tables and schemas
  • Implement different API endpoints
  • Add authentication
  • Connect to AI APIs for chat completions

Troubleshooting

"Invalid version provided" error: This usually means there's a caching issue. Try:

  1. Delete the val and create a new one with a different name
  2. Clear Val.town's module cache by changing the import URL (add ?v=2)

Import errors: Make sure you're using the exact versions specified:

  • PGlite: npm:@electric-sql/pglite@0.2.17
  • nano-supabase: https://raw.githubusercontent.com/filipecabaco/nano-supabase/main/dist/index.js
FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2026 Val Town, Inc.