---
title: "Building a GPT Backed by a Heroku-Deployed API"
description: "A custom OpenAI GPT can be backed by a simple Express API on Heroku that answers natural-language questions about an employee directory."
url: "https://swe.quest/articles/building-a-gpt-backed-by-a-heroku-deployed-api-48a6672b2eb1e607"
canonical: "https://www.heroku.com/blog/gpt-backed-heroku-api/"
source: "Heroku Engineering"
published: "2024-03-28"
difficulty: "medium"
kind: "How-to"
reading_minutes: 15
tags: ["ai-agents","llms","javascript","postgres"]
---

# Building a GPT Backed by a Heroku-Deployed API

A post on [Heroku Engineering](https://swe.quest/sources/heroku.md), published 2024-03-28, 15 min read, How-to. Original: [https://www.heroku.com/blog/gpt-backed-heroku-api/](https://www.heroku.com/blog/gpt-backed-heroku-api/)

## Summary

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.

Written by swe.quest, not by the author.

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

## Topics

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

## Prerequisites

- Node.js and Express ([easy posts on JavaScript](https://swe.quest/tags/javascript.md?difficulty=easy))
- basic SQL ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- REST APIs ([easy posts on API design](https://swe.quest/tags/api-design.md?difficulty=easy))

## Keywords

OpenAI GPTs, Chat Completions API, Heroku, Heroku Postgres, Express, ChatGPT

## Related posts

- [Building Data-Aware AI Applications with Heroku AI and LlamaIndex](https://swe.quest/articles/building-data-aware-ai-applications-with-heroku-ai-and-llamaindex-8f85403b0aabecc2.md): Heroku Engineering · 2025-08-19 · Medium · 4 min read · RAG & retrieval, Vector search, PostgreSQL, Python, LLMs
  A 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.
- [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.
- [Working with ChatGPT Functions on Heroku](https://swe.quest/articles/working-with-chatgpt-functions-on-heroku-40f46570b8427314.md): Heroku Engineering · 2024-01-30 · Medium · 11 min read · LLMs, JavaScript, React, Cloud platforms
  Menu 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.
- [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.
- [Web-based AI SQL Playground and connecting to Postgres from the browser](https://swe.quest/articles/web-based-ai-sql-playground-and-connecting-to-postgres-from-the-browser-fa7f4eccd9643a37.md): Neon · 2023-05-19 · Medium · 5 min read · PostgreSQL, LLMs, Serverless, JavaScript
  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.

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)
