OpenAI announced a new mindblowing feature on the DevDay (Nov 2023). It's the custom GPT. With it, you can create your custom-tailored chat GPT. The most exciting part is you can feed your custom GPT with a PDF or even connect it to the internet!

In this blog post, we'll learn how to connect custom chatGPT with Google (a.k.a. internet!)

Connect custom GPT to the internet (Google)

What are we going to build?

We'll create an SEO tool that analyzes Google Search results page (Google SERP) and gives us advice accordingly. By default, custom GPT can browse the web with Bing Search but not with Google. We can extend its capabilities by using an external API with Actions.

Flow of our custom GPT:
- A user will give a keyword to analyze.
- We'll get information from Google SERP using an external API in Actions.
- Chat GPT will give advice based on this accurate live data.

Note: The sky is the limit of what we can do with the ability of custom GPT to connect to an external API.

Tools and preparation

Documentation link: Google Search API .

Video tutorial

If you prefer watching a video, here is a video tutorial on how to use Google search on your custom GPT

Step-by-step tutorial to connect custom GPT to the internet

Make sure you have already subscribed to Chat GPT to follow along.

Step 1: Create a new custom GPT

From your chat.openai.com dashboard, Click on the "explore" button.

Click explore button

Click the "Create a GPT" button.

Step 2: Fill in the basic information

It will redirect you to the "GPT Builder" section. You need to provide this data:
- What it does (in short sentences)
- GPT's name (It will give you a suggestion)
- A profile picture (It will auto-generate for you as well)

connect custom GPT to internet initial setup

Step 3: Give specific instruction
Next, tell the builder about the details of what it will do in the background. Here is mine for this "SEO tool sample":

- It will analyze Google Serp for the user. 
- User will provide a keyword
- It will analyze Google SERP (Via actions - external API)
- It will return with advice to suggest to the user what to cover on their page

Follow up instructions:

- It will take top 5 results from Google SERP
- It will analyze what the user-intent is based on that top ranking results
- It will analyze the people-also-ask-for or related-search
- Returns complete advice based on that (not general SEO advise)

wi

Give specific instructions to custom GPT

A good rule of thumb for the instructions:
- What needs to be done
- What are the expected results

Step 4: Define user interaction
Explain how the user (or you) will interact with this tool. Here is mine:

if user types this: "keyword: $input" - then $input is the keyword user want to cover.
How custom GPT will interact with the user

Step 5: (Optional) Choose capabilities
Since we will only use an external API, I'll uncheck all capabilities in the "configure tab". To make sure it only relies on SerpApi.

Uncheck capabilities at GPT Builder

Step 6: Create the OpenAPI schema
We'll need an OpenAPI schema for our actions. Therefore, we need to create the structure of our schema first.

You can learn and build it yourself, or if you're lazy like me, ask chatGPT to build it for you. I'm copy-pasting the sample curl request from the API documentation.

Ask ChatGPT to create openAPI schema

The returned result is imperfect, but it is enough for the base structure. In my case, I need to add the "servers" block and "operationId."

- Servers is a block for our endpoint
- OperatedId is a unique name for our method

Here is my complete schema:

{
  "openapi": "3.0.0",
  "info": {
    "title": "SerpApi Search Service",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://serpapi.com"
    }
  ],
  "paths": {
    "/search": {
      "get": {
        "summary": "Perform a search using SerpApi",
        "operationId": "seachGoogle",
        "parameters": [
          {
            "name": "api_key",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "enum": ["YOUR_REAL_SERPAPI_API_KEY"]
            }
          },
          {
            "in": "query",
            "name": "engine",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The search engine to use, e.g., 'google'."
          },
          {
            "in": "query",
            "name": "q",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The query string for the search."
          },
          {
            "in": "query",
            "name": "location",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "The geographical location for the search."
          },
          {
            "in": "query",
            "name": "google_domain",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "The specific Google domain to use for the search."
          },
          {
            "in": "query",
            "name": "gl",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "The country to use for the search."
          },
          {
            "in": "query",
            "name": "hl",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "The language setting for the search."
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "results": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  },
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "400": {
            "description": "Bad request"
          }
        }
      }
    }
  }
}

Feel free to add or remove parameters based on your needs. The code above is my "final schema." Feel free to copy and paste it.

Just for your information, I needed to change the api_key structure from this.

 {
            "in": "query",
            "name": "api_key",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The API key for authentication."
},

to store the api_key value in the enum array like this:

{
  "name": "api_key",
  "in": "query",
  "required": true,
  "schema": {
    "type": "string",
    "enum": ["YOUR_REAL_SERPAPI_API_KEY"]
  }
}

Otherwise, the chatGPT won't be able to validate your API key.

Step 7: Use it in action configuration
To add the schema, click on the "create new action" in the configure tab:

Create actions in custom GPT

Now, add the schema inside the textbox:

Adding OpenAPI schema in the actions tab

Step 8: Test the GPT SEO tool

You can click on the "test button" below.

The GPT will test and run the results for us. You'll receive an error message if anything is wrong.

It will also run a search with a sample keyword for us. It shows us the top 5 results with a link to the content to ensure the GPT is not hallucinating.

Step 9: Test with a user input

We've determined that the user can put the keyword like this:

Custom GPT usage example

Besides the accurate top-ranking results, our custom GPT reflects the actual "people also search" content from the Google Live results page.

People also ask for results.

It returns concrete SEO tips after giving us information from the top-ranking results.

Using multiple APIs from the same path

Another API we can use to enhance our SEO tool is Google Autocomplete API. Since autocomplete will show what people usually search for.

Because SerpApi uses the same endpoint for all its APIs (different engine parameters), we only need to update the engine schema. Here are the endpoints:

  • https://serpapi.com/search.json?engine=google_autocomplete&q=coffee
  • https://serpapi.com/search.json?engine=google&q=coffee

Notice the endpoints are the same.

Update Schema's parameter

Here is my engine parameter now:

{
  "in": "query",
  "name": "engine",
  "required": true,
  "schema": {
    "type": "string",
    "enum": ["google", "google_autocomplete"]
  },
  "description": "The search engine to use, e.g., 'google'."
},

Optionally, you can update the description for each parameter to specify which parameter is used for which engine.

Update instruction

I also need to update the instructions by clearly telling what needs to be done and the expected results.

Run the API twice: 
- engine "google" 
- engine "autocomplete" 

Based on this analysis, it offers custom, straightforward advice and generates 5 title ideas that could rank. The ideas are inspired by the top-ranking, questions, and topics identified in the SERP analysis, tailored to the user's keyword. 

Expected Results:
- Show top 5 ranking results
- Show "people also ask for"
- Show "related search"
- Show "autocomplete"
- Show 5 title ideas

Here is the sample result:

comparing autocomplete suggestions from Google and Custom GPT

Our SEO advisor will add "autocomplete suggestions" data alongside other information.

Using multiple APIs from a different path

What if we have a different path? To simulate this, I'll add the "Account API" from SerpAPI, which retrieves the user account information. The endpoint is: https://serpapi.com/account?api_key=123

Given that we have two different paths, /search and /account , after the closing tag of /search I added this schema:

"/account": {
  "get": {
    "summary": "Perform a search using SerpApi",
    "operationId": "seachGoogle",
    "parameters": [
      {
        "name": "api_key",
        "in": "query",
        "required": true,
        "schema": {
            "type": "string",
            "enum": ["API_KEY"]
        }
      }
    ],
    "responses": {
      // ... same as previous response
    }
  }
}

It will be reflected in the available actions section:

Multiple actions on custom GPT

Make sure to add a different "operationId." Feel free to click the "test" button.

You can use individual actions depending on how you want to use it. You can adjust the instruction to run both in one command if needed.

Here is the adjusted instructions to run all the APIs:

Run all APIs: 
- engine "google" 
- engine "autocomplete" 
- /account API

Important notes
Multiple actions will run in sync, so it's possible to use retrieved data from one API endpoint to the following API endpoint.

Optional Extended feature

More specific actions
You can adjust our GPT by interacting in the chat box or from the configure tab. For example, you can ask the GPT to return 5 article ideas for you instead of only returning SEO tips.

Scraping individual pages

You can add multiple APIs from different resources at customGPT. You can add tools like Webpilot AI to scrape the individual top-ranking pages or to analyze the header, structure, and more.

FAQ

Is ChatGPT connected to the internet?

With the recent update, ChatGPT can use Bing search results to get information from the internet. If you want to do this programmatically, OpenAI offers another API, which is the assistant API that you can combine with function calling feature.

How much does custom GPT by OpenAI cost?
It costs $20/month since you must subscribe to ChatGPT Plus to use it.