---
title: "Building a GPT Backed by a Heroku-Deployed API"
description: "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."
---

# Building a GPT Backed by a Heroku-Deployed API

[Heroku](https://yomu.fyi/company/heroku) · Julián Duque · Mar 28, 2024

**Type:** Tutorial

## 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.

**Tags:** [AI](https://yomu.fyi/topic/ai), [Heroku](https://yomu.fyi/topic/heroku), [Node.js](https://yomu.fyi/topic/node-js), [Postgres](https://yomu.fyi/topic/postgres)

- Source: [Heroku](https://www.heroku.com/blog/gpt-backed-heroku-api)
- Source URL: https://www.heroku.com/blog/gpt-backed-heroku-api
- Ingested by Yomu: 2026-09-09T20:04:45.359Z

[Read original post](https://www.heroku.com/blog/gpt-backed-heroku-api)
