Remember how I said there were only going to be 2 parts to “Vector Databases (with Supabase and OpenAI)”? 😬
Well… slight change of plans, there are 4 parts now.
And before you start screaming at me through the screen,
I split the series up because I go into these steps in excruciating detail. Cause what if there is somewhere out there is someone doing this for the very first time? And the goal is to make every step feel approachable, not overwhelming.
To keep things digestible, I’m “chunking” the series into four smaller posts instead of one giant wall of text.
And they are:
- Part 1 – The theory
- Part 2 – Setup (👈 YOU ARE HERE)
- Part 3 – Vector database & search
- Part 4 – A chatbot (proof of concept)
So, before doing anything fancy with vector databases, you need three things: a Supabase project, an OpenAI API key, and a Node project that can talk to both.
We are going to set up the above in under easy 9 steps.
- Create a Supabase project
- Enable the vector extension
- Get your Supabase URL and anon key
- Set up your OpenAI API account
- Create a Node project
- Store your secrets in .env
- Create reusable OpenAI and Supabase clients
- Test everything with a tiny script
- Where you are now
1. Create a Supabase project
- Go to Supabase and sign in with GitHub or email
- On the dashboard, click New project
- You will be prompted to create an organization.
- Fill in:
- Name: anything you like (your name, side‑project, or company).
- Type of organization: Personal.
- Pricing plan: Free.
- Click Create
Next you will have to set up your project.
- Under Organization, pick the one you just created
- Set a Project name (for example, vector-embeddings).
- Choose a strong Database password (this is for Postgres, not your login).
- Pick a Region close to you/users for better latency.
- Click Create new project
- Once it’s ready, click on your new project card in the dashboard to enter the Studio
2. Enable the vector extension
- Next, we need to enable Vector extension. To store embeddings efficiently, Supabase uses the vector (pgvector) extension in Postgres
- In your project sidebar, go to Database > Extensions.
- Search for vector.
- Click to Enable the vector extension.
3. Get your Supabase URL and anon key
- In the sidebar, click Project Settings > API Keys
- Under Legacy anon, service_role API keys, find anon public.
- Click Copy.
- This is the key you will use in your Node app.
_NOTE: Never share the **service_role key publicly_**
- In Project Settings, open the Data API (or API section depending on UI).
- Copy the value labeled Project URL (the one that looks like https://xyzcompany.supabase.co)
Store both these values somewhere safe, you will paste them into your .env file in a minute
4. Set up your OpenAI API account
Uhmm, this is the part where I need your 5 dollars. Well, not me, but Open AI. And yes, I know it sounds expensive, but hear me out:
It’s pay-as-you-go. There are no automatic charges unless you explicitly enable auto-pay.
$5 goes a long way. I’ve been using OpenAI’s API for weeks now, started with $5, and I’m still on $5.
And before you ask, “I already pay $20 for ChatGPT, can I just use that?”
Unfortunately, that's not how it works. Paying for ChatGPT is like buying a fully built car, it’s a finished product. Paying for OpenAI’s API is like paying for the engine, the part you can actually build things with.
So, let’s get to it.
- Log in to your OpenAI account.
- Click on API platform
- In the sidebar (or using the search bar), go to Billing.
- Add a payment method and purchase credits.
(At the time of writing, the minimum preload for new API users is 5 USD)
- Keep **auto‑recharge disabled**
- In the dashboard, search for API keys and open the API keys page.
- Click Create new secret key.
- Give it a name and select the Default project.
- Click Create secret key and copy it immediately, you will not be able to see it again.
*NOTE: Treat this key like a password. Never post it online or commit it to GitHub. If it leaks, delete it and create a new *
5. Create a Node project
- Open your terminal and create a fresh folder for this project:
mkdir my-ai-project && cd my-ai-project
- Initialize a Node project with a
package.json:npm init -y
- Install the official OpenAI SDK and the Supabase JavaScript client:
npm install openai @supabase/supabase-js - If you want to use a
.envfile for secrets (recommended), also install dotenv:npm install dotenv
- Open package.json and ensure it looks like this (only showing the important parts):
{
"name": "my-ai-project",
"version": "1.0.0",
"main": "index.js",
"type": "module",
"scripts": {
"start": "node index.js"
}
}
6.Store your secrets in .env
- Create a file named .env in the root of my-ai-project
- Replace the placeholders with the values you copied from OpenAI and Supabase.
OPENAI_API_KEY=your-openai-secret-keySUPABASE_URL=your-supabase-project-urlSUPABASE_API_KEY=your-supabase-anon-key
- Do NOT wrap them in quotes.
- Do NOT commit this file to GitHub;
.envshould stay private.
7. Create reusable OpenAI and Supabase clients
- Create a new file called
config.jsand add this:
import OpenAI from "openai";
import { createClient } from "@supabase/supabase-js";
import "dotenv/config";
export const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
export const supabase = createClient(
process.env.SUPABASE_URL,
process.env.SUPABASE_API_KEY
);
8. Test everything with a tiny script
- Create a file index
.jswith a minimal test, for example:
`import { openai } from "./config.js";
async function main() {
const response = await openai.responses.create({
model: "gpt-4.1-mini",
input: "Say hello from my Node project.",
});
console.log(response.output[0].content[0].text);
}
main();`
- This script sends a tiny test request to the OpenAI API so you can verify that your key and project setup works
- Make sure you are in the project folder in your terminal and run:
node index.js
- If everything is set up correctly, you should see a short greeting printed in the terminal from the model.
9. Where you are now
At the end of Part 2, you have:
- A Supabase project with the vector extension enabled
- A safe place to copy your Supabase URL and anon key
- An OpenAI API key with a small prepaid balance and no auto‑recharge required.
- A Node project where node index.js can successfully call the OpenAI API.
In the next part, i.e. Part 3 of the series,, you can build on this by creating a documents table with a vector column in Supabase, generating embeddings with OpenAI, and storing them for semantic search
























Top comments (0)