DEV Community

Cover image for How to monetize your custom GPT application today
Gergo Miklos
Gergo Miklos

Posted on

How to monetize your custom GPT application today

While the official OpenAI GPT store may not arrive until 2024, there’s no need to feel sad. You can take control of the situation by implementing a custom paywall into your custom GPT application, even now.

In this article, we’ll walk you through a straightforward implementation for turning your GPT applications into a source of income.

TLDR

We implement a proxy server (a paywall service) for our existing GPT action. Then, in the GPT action editor, we replace the original URL with the URL of our new server.

Behind the scenes, the new action has a new required parameter, the user’s email address. The server checks for successful payments using the Stripe API and the email address provided by the user. When it does not find any previous payment, then it returns a Stripe payment link; otherwise, it returns the requested content using the original URL.

Prerequisites

  • Node.js and some JavaScript (Express.js) knowledge
  • Stripe account
  • ChatGPT Pro subscription

We will use Express.js to create a proxy server for our GPT actions, Stripe to handle user payments, and ChatGPT to create our custom AI application.

Create a custom GPT application

Create a new action in the GPT configurator that we can protect with a payment link. An example OpenAPI schema:

openapi: 3.0.0
info:
  title: Restricted paid content
  version: 1.0.0
servers:
- url: https://buymygpt.com
paths:
  "/api/today":
    get:
      summary: Gets the current date and time
      operationId: GetDateTime
Enter fullscreen mode Exit fullscreen mode

Set up your Express.js server

To begin, make sure you have Node.js installed on your system.

Create a new directory for your project.

Create a package.json file in the project directory and replace its content with the following:

{
  "name": "my-server",
  "version": "1.0.0",
  "description": "A simple Node.js server",
  "main": "server.js",
  "scripts": {
    "start": "node server.js"
  },
  "author": "Your Name",
  "license": "MIT",
  "dependencies": {
  }
}
Enter fullscreen mode Exit fullscreen mode

Navigate to your project's directory in the terminal and run:

npm install express http-proxy stripe
Enter fullscreen mode Exit fullscreen mode

Create a new file, let’s call it server.js, open it in your code editor, and set up your a basic Express.js server as follows:

const express = require('express');

const app = express();
const port = 3000;

app.use(express.json());

app.listen(port, () => {
  console.log(`Server is running on port ${port}`);
});
Enter fullscreen mode Exit fullscreen mode

To start your Node.js server, you can run the following command in your terminal:

npm start
Enter fullscreen mode Exit fullscreen mode

Create your proxy endpoint

Now, let’s create a proxy endpoint within your Express.js server that will forward requests to your original URL.

Add the following code to your server.js file to create the proxy endpoint:

const httpProxy = require('http-proxy');

const proxy = httpProxy.createProxyServer();

app.all('/', (req, res) => {
    proxy.web(req, res, { target: 'https://buymygpt.com' });
});
Enter fullscreen mode Exit fullscreen mode

In this code snippet, we set up a route to forward requests from your GPT application to the original URL using http-proxy.

Create your Stripe payment link

Create a Stripe Payment Link with your GPT as a Product in the Stripe dashboard.

Verify user payment using the Stripe API

Now, let’s integrate the Stripe payment check into your server.

In your server.js file, import the stripe library and initialize it. Replace 'YOUR_STRIPE_SECRET_KEY' with your actual Stripe secret key.

const stripe = require('stripe')('YOUR_STRIPE_SECRET_KEY');
Enter fullscreen mode Exit fullscreen mode

Modify the existing endpoint to include Stripe Checkout payment verification. Update the code as follows:

app.all('/', async (req, res) => {
  // Extract user email address from the request
  const { email } = req.headers;

  if (!email) {
    // If no email is provided, prompt the user to make a payment
    res.status(401).json({ 
      message: 'Payment required. Please follow the payment link: ' +
               'YOUR_STRIPE_PAYMENT_LINK'
    });
  }

  // Use Stripe to list checkout sessions associated with the user's email
  const completedCheckouts = await stripe.checkout.sessions.list({
    customer_details: {
      email,
    },
    status: 'complete', // Check for completed sessions
  });

  if (completedCheckouts.data.length === 0) {
    // If no completed session exists, prompt the user to make a payment
    res.status(401).json({ 
      message: 'Payment required. Please follow the payment link: ' +
               'YOUR_STRIPE_PAYMENT_LINK'
    });
  }

  // If a completed session exists, continue to the original URL
  proxy.web(req, res, { target: 'https://buymygpt.com' });
});
Enter fullscreen mode Exit fullscreen mode

Replace 'YOUR_STRIPE_PAYMENT_LINK' with your actual Stripe payment link.

Publish your new server

Now we can collect email addresses, check for previous payments, return payment links, and it’s time to publish your Express.js server. This will make it accessible over the internet and allow users to interact with your server from your custom GPT application and complete payments.

You need to host your Express.js server on a hosting platform. Some popular options include Railway, Render, Vercel, DigitalOcean, and many others.

While I won’t provide a step-by-step guide for specific hosting platforms in this tutorial, most hosting services offer comprehensive documentation and guides on how to deploy Node.js applications.

Edit your GPT application

Modify the action schema in the GPT editor to contain your new server URL and the required email parameter:

openapi: 3.0.0
info:
  title: Restricted paid content
  version: 1.0.0
servers:
- url: 'YOUR_SERVER_URL'
paths:
  "/api/today":
    get:
      summary: Gets the current date and time
      operationId: GetDateTime
      parameters:
      - name: email
        in: query
        description: The user's email address used for the payment. Ask the user to
          provide it.
        required: true
      responses:
        '401':
          description: Restricted paid content. Direct the user to purchase access
            through the provided link. After a successful payment, the user's email
            address is required in the query parameter to access the content.
Enter fullscreen mode Exit fullscreen mode

Replace 'YOUR_SERVER_URL' with your actual server URL.

Start earning money!

Done! We are live! You are ready to start earning money directly from your custom ChatGPT application.

The action is protected with a payment

Further development

You may want to include some extra user identification logic to prevent account sharing. BuyMyGPT (my no-code tool) uses additional HTTP headers provided by OpenAI to identify account switch attempts within the same day, and it also sends verification emails once a day.

Top comments (0)