HerokuJulián DuqueTutorial
Building a GPT Backed by a Heroku-Deployed API
Summary
The walkthrough shows how to connect an OpenAI custom GPT to a Node.js backend that provides natural-language access to an employee directory. It builds an Express API with a POST /search endpoint, where OpenAI’s Chat Completions API converts a user’s question into a single SQL query, the database returns rows, and a second OpenAI call turns those rows into a natural-language response. The project uses Heroku Postgres, environment configuration, bearer-key authentication, Swagger UI, and an OpenAPI specification imported into the GPT action. The deployment flow covers seeding dummy records, deploying from a GitHub-connected repository, and configuring the action to call the hosted API, while noting that data leaves Heroku’s trust boundary for OpenAI services.
Context
The example addresses the need for non-technical employees to search an employee database through natural-language questions rather than SQL queries. It presents custom GPT actions as a way to connect ChatGPT to an external API and database.
Approach / What changed
Build and deploy an Express-based Node.js API on Heroku, backed by Heroku Postgres. The API authenticates callers, uses OpenAI’s Chat Completions API to generate SQL and summarize query results, exposes an OpenAPI specification through Swagger UI, and connects that specification to a configured GPT action.
Takeaways
The /search flow uses one OpenAI call to generate SQL from the user’s question and another to convert database rows into a natural-language answer.
The GPT action uses Bearer API-key authentication and imports the API contract from the Heroku app’s /api-docs/openapi.yaml route.
The architecture sends data beyond Heroku’s trust boundary to OpenAI services, which matters for data-sensitive applications.
Source and freshness
- Source
- heroku.com
- Published
- Added to Yomu
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.