A guide and cloneable template for creating an OpenAI ChatGPT Custom GPT with user authentication and database access.
- Database: Prisma with Neon Serverless Postgres
- Authentication: Clerk.com OAuth 2.0
- Hosting: Vercel
- Language: TypeScript
- Package Manager: pnpm
- Node.js 18+
- pnpm
- A custom domain name (required for Clerk configuration)
- OpenAI API access
- Clerk account
- Neon database account
- Vercel account (optional, for deployment)
- Clone the repository
- Install dependencies:
pnpm install
- Set up environment variables:
cp .env.example .env
- Update the
.env
file with your credentials - Initialize the database:
npx prisma generate npx prisma db push
- Visit the OpenAI GPT Builder
- Follow the setup wizard to create your GPT
- Configure the Actions section with the OpenAPI specification
- Create a new Clerk project
- Set up a production instance with a custom domain
- Create an OAuth2 Provider:
curl -X POST https://api.clerk.com/v1/oauth_applications \ -H "Authorization: Bearer <CLERK_SECRET_KEY>" \ -H "Content-Type: application/json" \ -d '{ "callback_url": "https://oauth-client.com/oauth2/callback", "name": "oauth_app_1", "scopes": "profile email" }'
- Update the callback URL after receiving the OpenAPI schema:
curl -X PATCH https://api.clerk.com/v1/oauth_applications/<oauth_application_id> \ -H "Authorization: Bearer <CLERK_SECRET_KEY>" \ -H "Content-Type: application/json" \ -d '{"callback_url":"https://oauth-client.com/oauth2/callback"}'
- Verify the configuration:
curl -X GET https://api.clerk.com/v1/oauth_applications \ -H "Authorization: Bearer <CLERK_SECRET_KEY>"
- Create a new Neon database
- Update the
DATABASE_URL
in your.env
file - Run database migrations:
npx prisma generate npx prisma db push
Use the ActionsGPT to generate OpenAPI specs based on your Prisma schema and code.
- The project is configured for Vercel deployment
- Use the Vercel CLI for deployment
- All
/api
routes are automatically converted to serverless functions
- Add build script to
package.json
:{ "scripts": { "build": "tsc" } }
- Build the project:
pnpm build
- Use the
dist
folder as your server root
- Generate Prisma client:
npx prisma generate
- Push schema changes:
npx prisma db push
- Format schema:
npx prisma format
- Create migration:
prisma migrate dev --name {name}
- Deploy migrations:
prisma migrate deploy
- Launch Prisma Studio:
npx prisma studio
- Run development server:
pnpm dev
- Note:
vercel dev
may have issues withapp.listen()
- usepnpm dev
instead
Before deploying to production, consider implementing:
- Comprehensive test suite
- Robust error handling
- Additional API endpoints
- Improved API organization following best practices:
src/ ├── controllers/ ├── routes/ └── api/
- Automated OpenAPI spec generation
- Consider using TSOA
Before publishing your GPT, create a privacy policy. Use this template prompt:
Help me create a simple privacy policy to publish on my website for my custom GPT.
My company name is [company name] and my website is [website url].
The company will collect email addresses, but it will never sell this information to third parties.
- Complete your Builder Profile
- Verify your domain name
- Submit for review
For more information, visit: Building and Publishing a GPT
- Vercel dev issues: Use
pnpm dev
instead - Prisma type build errors on Vercel: These are ignorable
- Database connection issues: Verify your
DATABASE_URL
in.env
Contributions are welcome! Please feel free to submit a PR or create an issue.
This project is licensed under the MIT License - see the LICENSE.txt file for details.