What
SQL Chat is a chat-based SQL client, which uses natural language to communicate with the database to implement operations such as query, modification, addition, and deletion of the database.
Why
As we enter the Developer Tools 2.0 era, there is a massive opportunity to rebuild the existing tools using the chat-based interface. SQL Client is no exception. Instead of navigating across many UI controls, a chat-based interface is much more intuitive. Of course, only if that works, and our goal is to deliver that experience.
How
SQL Chat is built by Next.js, it supports the following databases and will add more over time:
- MySQL
- PostgreSQL
- MSSQL
- TiDB Cloud
sqlchat.ai
IP Whitelisting
If you use sqlchat.ai to connect to your database, you need to add 0.0.0.0 (allow all connections) to the database whitelist IP. Because sqlchat.AI is hosted on Vercel which uses dynamic IP. If this is a concern, please consider the self-host option below.
Data Privacy
Self-host
Docker
docker run --name sqlchat --platform linux/amd64 --env NEXTAUTH_SECRET="$(openssl rand -hex 5)" -p 3000:3000 --hostname localhost sqlchat/sqlchat
- Pass an arbitrary string to NEXTAUTH_SECRET otherwise next-auth will complain. It doesn't matter if you don't enable login.
- If you connect to the database on the same host, you need to use
host.docker.internal
as the host name.
Startup options
- Run without database, check .env.nodb. This is suitable if you just want to use for yourself.
- Run with database, check .env.usedb. This is suitable if you want to run a similar multi-tenant service as sqlchat.ai where you need manage account, usage and etc.
OpenAI related
-
OPENAI_API_KEY
: OpenAI API key. You can get one from here. -
OPENAI_API_ENDPOINT
: OpenAI API endpoint. Defaults tohttps://api.openai.com
. -
NEXT_PUBLIC_ALLOW_SELF_OPENAI_KEY
: Set totrue
to allow users to bring their own OpenAI API key.
Database related
NEXT_PUBLIC_USE_DATABASE
: Set totrue
to start SQL Chat with database. This will enable following features:- Account system.
- Per-user quota enforcement.
- Payment.
- Usage data collection.
DATABASE_URL
: Applicable ifNEXT_PUBLIC_USE_DATABASE
istrue
. Postgres connection string to store data. e.g.postgresql://postgres:YOUR_PASSWORD@localhost:5432/sqlchat?schema=sqlchat
.
Local Development
-
Install dependencies
pnpm i
-
Generate prisma client
pnpm prisma generate
-
Make a copy of the example environment variables file:
cp .env.usedb .env
-
Add your API key and OpenAI API Endpoint(optional) to the newly created
.env
file.
Setup database
You can skip this section with NEXT_PUBLIC_USE_DATABASE=false
if you don't build features requiring database
-
Start a Postgres instance. For mac, you can use StackbBricks, DBngin or Postgres.app.
-
Create a database:
CREATE DATABASE sqlchat;
In
.env
file, assign the connection string to environment variableDATABASE_URL
andDATABASE_DIRECT_URL
. This article explains why we need two URLs. -
Set up database schema
pnpm prisma migrate dev
-
(Optional) Seed data
pnpm prisma db seed
Star History
Community

Sponsors
License
This project is under the BSL License. See the LICENSE file for the full license text.
FAQ
How to self host SQL Chat?
How to use my OpenAI API key?
-
You can set the
OPENAI_API_KEY
in environment variable.docker run --name sqlchat --platform linux/amd64 --env OPENAI_API_KEY=xxx -p 3000:3000 sqlchat/sqlchat
-
You can set the
OPENAI_API_KEY
in setting dialog.
It always says that I have a network connection issue?
Please make sure you have a stable network connection which can access the OpenAI API endpoint.
ping api.openai.com
If you cannot access the OpenAI API endpoint, you can try to set the OPENAI_API_ENDPOINT
in UI or environment variable.
You exceeded your current quota, please check your plan and billing details
Your OpenAI Key has run out of quota. Please check your OpenAI account.