---
title: "Web-based AI SQL Playground and connecting to Postgres from the browser"
description: "Neon's Postgres AI Playground connects to a Postgres database directly from the browser and uses OpenAI's gpt-3.5-turbo to turn natural-language prompts into SQL."
url: "https://swe.quest/articles/web-based-ai-sql-playground-and-connecting-to-postgres-from-the-browser-fa7f4eccd9643a37"
canonical: "https://neon.com/blog/postgres-ai-playground"
source: "Neon"
published: "2023-05-19"
difficulty: "medium"
kind: "Case study"
reading_minutes: 5
tags: ["postgres","llms","serverless","javascript"]
---

# Web-based AI SQL Playground and connecting to Postgres from the browser

A post on [Neon](https://swe.quest/sources/neon.md), published 2023-05-19, 5 min read, Case study. Original: [https://neon.com/blog/postgres-ai-playground](https://neon.com/blog/postgres-ai-playground)

## Summary

Neon's Postgres AI Playground connects to a Postgres database directly from the browser and uses OpenAI's gpt-3.5-turbo to turn natural-language prompts into SQL. Browsers can't open TCP connections, so the Neon serverless driver tunnels the Postgres wire protocol through a WebSocket-to-TCP proxy. The proxy is open source and can be self-hosted to reach other Postgres providers. A Vercel edge function rate-limits requests with Upstash Redis, injects the user's schema (pulled from information\_schema.columns and flattened to a compact text form) into the prompt, and streams the model's response back to the editor.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)
- [Serverless](https://swe.quest/tags/serverless.md) (Backend & APIs)
- [JavaScript](https://swe.quest/tags/javascript.md) (Languages)

## Prerequisites

- PostgreSQL basics ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- OpenAI chat API
- Next.js API routes ([easy posts on React](https://swe.quest/tags/react.md?difficulty=easy))

## Keywords

Neon, Neon serverless driver, OpenAI, gpt-3.5-turbo, Vercel Edge Functions, Upstash Redis, WebSocket

## Related posts

- [How to be AI-fancy](https://swe.quest/articles/how-to-be-ai-fancy-1617ad0989d06ba6.md): Neon · 2024-11-04 · Medium · 6 min read · LLMs, Product engineering, PostgreSQL, TypeScript
  Neon added three LLM-backed features to its SQL editor: natural-language SQL generation, automatic naming of history queries, and one-click error fixing.
- [postgres.new: In-browser Postgres with an AI interface](https://swe.quest/articles/postgres-new-in-browser-postgres-with-an-ai-interface-55583d716a34d5b8.md): Supabase · 2024-08-12 · Medium · 11 min read · PostgreSQL, WebAssembly, LLMs, AI agents, Browsers
  database.build (formerly postgres.new) runs unlimited Postgres databases entirely in the browser via PGlite, a WASM build of Postgres, paired with GPT-4o that has full autonomy over the disposable database.
- [database.build v2: Bring-your-own-LLM](https://swe.quest/articles/database-build-v2-bring-your-own-llm-b2a3b83eee7ef5a0.md): Supabase · 2024-12-06 · Medium · 11 min read · PostgreSQL, LLMs, Browsers, WebAssembly
  database.build, Supabase's in-browser Postgres sandbox built on PGlite, now lets users bring any OpenAI-compatible LLM, with no login and no rate limits.
- [Building an AI-powered ChatBot using Vercel, OpenAI, and Postgres](https://swe.quest/articles/building-an-ai-powered-chatbot-using-vercel-openai-and-postgres-4fd423473384581f.md): Neon · 2023-03-09 · Medium · 13 min read · RAG & retrieval, PostgreSQL, Vector search, LLMs, Serverless
  A ChatGPT-style documentation assistant (Ask Neon) is built by storing OpenAI text-embedding-ada-002 vectors in Postgres with pgvector, retrieving context by cosine distance, and feeding it to text-davinci-003 from a Vercel Edge Function.
- [psql from the browser](https://swe.quest/articles/psql-from-the-browser-f27b7186b8abd76b.md): Neon · 2024-12-11 · Easy · 3 min read · PostgreSQL, Browsers, Developer tools, Open source
  psql.sh is a browser-based emulation of Postgres's psql client, built on Neon's WebSocket proxy and serverless driver because browsers can't open raw TCP connections.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
