Building a GPT Backed by a Heroku-Deployed API
A custom OpenAI GPT can be backed by a simple Express API on Heroku that answers natural-language questions about an employee directory. The API makes two Chat Completions calls: one turns the user's question into a PostgreSQL query using the table schema in a system prompt and JSON response format, and a second turns the returned rows into a readable answer, resending the schema because the models keep no memory between requests. The walkthrough covers bearer-token auth, environment configuration, local curl testing, Heroku deployment with Postgres, and configuring the GPT action. It also warns that all data leaves Heroku's trust boundary to reach OpenAI.
Related posts
- Building Data-Aware AI Applications with Heroku AI and LlamaIndex
Heroku Engineering mediumAdeptA RAG stack on Heroku pairs LlamaIndex for ingestion, indexing and retrieval with Heroku Managed Inference (Claude 4 Sonnet via an OpenAI-compatible API), Cohere Embed Multilingual for embeddings, and Heroku Postgres with pgvector as the vector store. The walkthrough provisions the add-ons via the Heroku CLI. It then shows Python code that points LlamaIndex's OpenAILikeEmbedding at Heroku's embedding endpoint, stores 1024-dimension vectors in PGVectorStore, and queries documents through a query engine. Example use cases include financial report analysis, insurance claim agents and support chatbots.
- database.build v2: Bring-your-own-LLM
Supabase mediumAdeptdatabase.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. Requests go straight from the browser to the provider. This works because most LLM APIs send CORS headers, and a service worker intercepts the Vercel AI SDK's /api/chat route, reading its BYO-LLM config from IndexedDB. Models need reliable tool calling, SQL knowledge and Chart.js knowledge, so gpt-4o is recommended; local Ollama models still struggle with tool calls, and Ollama buffers tool-call streams. The release also adds one-click deploys to Supabase by piping server-side pg_dump over Live Share into pg_restore, and replaces the tar.gz export with a WASM pg_dump. Serverless PGlite was shelved because of its memory use and single-connection limit in multi-tenant setups and unreliable s3fs storage.
- Working with ChatGPT Functions on Heroku
Heroku Engineering mediumAdeptMenu Maker is a Node.js reference app with a React front end and Express back end that turns a user's ingredient list into a fine-dining dish description, ingredient list and recipe using OpenAI's Chat Completions API. Function calling with a JSON-schema `updateDish` definition makes the model return structured arguments, so the front end can parse the response and pass it straight into React state instead of handling free-form prose. The walkthrough covers the prompt and function settings, the POST endpoint, testing with curl, and deploying to Heroku from GitHub with config vars. Development API costs were under $1, and an Eco dyno is enough for hosting.
- Building an AI-powered ChatBot using Vercel, OpenAI, and Postgres
Neon mediumAdept
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. A window-function query caps retrieved context at a cumulative 1,500 tokens to fit the 4,096-token model limit, and an ivfflat index (lists ≈ 4·sqrt(rows)) speeds up the similarity search. Neon's WebSocket-based serverless driver works around Edge Functions' lack of TCP, and streaming completions via SSE parsing return answers faster. User feedback is stored for later fine-tuning.
- Web-based AI SQL Playground and connecting to Postgres from the browser
Neon mediumAdept
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.