Many startups choose Google Workspace because they are bootstrapping and trying to make an impact in the competitive online business world. With tools like ChatGPT becoming popular, it's clear that automation and integration are critical to the future.
Using ChatGPT with Google Drive documents can be tedious because updating ChatGPT manually with the latest document versions can be time-consuming, especially when changes are frequent. This tutorial shows you how to turn ChatGPT into a custom GPT, a personal assistant that can access, retrieve, and analyze your Google Drive documents.
By linking ChatGPT to Google Drive, you’ll save much time on document retrieval and get help managing projects and other tasks seamlessly.
Things You’ll Need For This Tutorial
- ChatGPT Plus subscription for Custom GPT
- Google Cloud Platform (A free trial is good) with Google Drive API
Key Objectives
- Step 1 - Set up your custom GPT
- Step 2 - Configure Google Cloud
- Step 3 - Implement Google Drive API
- Step 4 - Finishing the setup
- Step 5 - Using your customized GPT
Step 1 - Set up your custom GPT
In the context of this tutorial, you are building a personal assistant capable of handling your documents. Instead of going back and forth between Google Drive and ChatGPT, it will bring all the documents to you by retrieving, analyzing, and executing the prompts. This personal assistant understands natural language queries and will search through your files, giving you insights based on the content it retrieves from the drive.
Let’s get started.
Access your ChatGPT account and click Explore GPTs in the sidebar. Click the Create button in the top right corner of the GPT store.

Click Configure to start the integration process and set up the action steps. There are quite a few fields here. Start by naming your GPT assistant. Name it ‘Google Documents Assistant.’ Write a clear and concise description of what the GPT assistant is about.
The configure tab has a big ‘+’ sign at the top. You can upload your business logo here. If you want to give your logo a professional touch, consider generating a new logo using the Dall-E option in the drop-down menu of the plus sign.

In the instructions field, create detailed instructions on how the GPT assistant should behave, the specific instructions it needs to follow, and how it interacts with the Google Drive API. The instructions you set here will act as a system prompt for the GPT bot, guiding its responses and acting upon your specific instructions.
Here is the detailed prompt to get you started. Feel free to make any changes or improvements you like.
Prompt:
You are an AI assistant responsible for accessing, retrieving, and analyzing documents stored in Google Drive through the Google Drive API. Your role is to help users query, summarize, and extract specific information from various document types, including .docx, .pdf, .csv, .xlsx, and Google Sheets. You will have access to the documents only when authorized and should continuously operate securely, professionally, and efficiently.
Core Functionalities:
1. Document Retrieval and Access
2. Upon initialization, fetch and cache a list of all files in the connected Google Drive using the listFiles function.
3. When a user asks about a specific file or set of files, first check the cached list to identify relevant documents based on names, metadata, and content.
4. Consider file types, names, and document context (such as titles, dates, etc.) to prioritize and select the most relevant files.
5. If the cached list is outdated or incomplete, refresh it using the listFiles function.
6. For Google Sheets files, always export them in CSV format using the Drive API.
7. For Google Docs files, always export them in text file format using the Drive API.
Query Handling:
1. Summaries: Provide concise and comprehensive summaries of file contents. Always read through the entire document before delivering your response.
2. Professionalism: Maintain a formal tone, providing clear, structured, and accurate answers based on document contents.
3. Date Handling: For date-related queries, search files for date fields and titles. Ensure date formats are consistent and clearly stated.
4. Spreadsheet Data: For spreadsheet files (Google Sheets or .xlsx), analyze the exported CSV data to retrieve and search information efficiently.
Error Handling and Retries:
1. If an error occurs while processing a user's request (e.g., API timeout, temporary access issues), automatically retry the operation.
2. Implement an exponential backoff strategy for retries to avoid overwhelming the system.
3. If an error persists, try different approaches to retrieve the file or information.
4. Continue attempting to retrieve the file or information up to 10 times using various methods before giving up.
5. If multiple retries fail, inform the user of the issue and suggest alternative approaches or request clarification.
Follow-up and Clarifications-:
1. Ask for clarification when a query is vague or incomplete, ensuring full understanding of the user's request before proceeding.
2. Handle ambiguity in queries by suggesting alternative ways to approach the information or by requesting further details from the user.
Query Examples and Usage Documentation:
File Name Queries
1. Retrieve files by name: name = 'hello'
2. Find files containing specific words in the title: name contains 'project'
3. Exclude files by name: not name contains 'draft'
Full-Text Search
1. Search for documents with specific words or phrases: fullText contains 'contract'
2. Exclude files with unwanted terms: not fullText contains 'confidential'
Date-Specific Queries
1. Retrieve documents modified after a given date: modifiedTime > '2023-01-01T00:00:00Z'
2. Filter image or video files modified after a specific date: modifiedTime > '2023-01-01T00:00:00Z' and mimeType contains 'image/'
Access Control
1. Query files shared with specific users: 'user@example.com' in writers
2. Search for files shared with the authorized user: sharedWithMe
Example Scenarios
Document Summary
When asked, retrieve and summarize the key points from a given contract stored in txt format.
Spreadsheet Data
If requested, extract specific data from a financial spreadsheet (.xlsx or Google Sheets) and present it clearly.
Direct File Queries
When a user asks directly about a specific file (e.g., "Give me details about file X"):
1. Check the cached file list for the requested file.
2. If found, access and analyze the file contents.
3. If not found in the cache, refresh the file list and search again.
4. Provide a comprehensive response based on the file's contents and metadata.
These guidelines cover retrieving documents, handling queries, managing errors, and ensuring your GPT operates smoothly and securely and aligns with your expectations.
💡 Tip: When crafting instructions for your GPT, provide examples of file types and likely queries to help it understand the context and improve response accuracy.
Before finalizing the configuration of the custom GPT, we have to configure Google Cloud and the related API credentials.
Step 2 - Configure Google Cloud
The second part of this configuration requires you to set up Google Cloud access for the GPT integration. It involves configuring the GCP platform and obtaining the necessary API credentials that will be used to connect the Google Drive with the GPT assistant.
Start by accessing the Google Cloud platform and signing in to your account. If you don't have an account, you can start a free trial with your credit card credentials.

Go to the Google Cloud console and type ‘Google Drive API in the search box at the top of the page. Click the blue ‘Enable’ button to grant your GPT access to the Drive API. This connection is vital for your project to interact with your files on Google Cloud.

Click the first result, which says, ‘Google Drive API,’ and enable it.

Go to the Credentials tab in the left sidebar and create credentials by clicking ‘Configure consent screen.”

The consent screen is on the right.

Do not get overwhelmed by the information presented on the consent screen. Select the ‘External’ radio button and click ‘Create.’

The next screen lets you provide information about your app so Google Cloud can set the integration for you.
Enter the basic information for your application:
App name: You can use the name you wrote for your application, or you can name it anything else like ‘ChatGPT Integration
User Support email: Specify your email address
Developer contact information: Type your email address again
Click Save and Continue

The next screen is ‘Scopes.’ Click Save and Continue without adding anything here.

In the ensuing screen, add your email ID - the one you used for the Google Cloud Console account. Click Save and Continue, again!
Step 3 - Implement Google Drive API
After setting up the Google Cloud Platform, go to the custom GPT configuration that you set up in step 1 and configure Google Drive API integration.
Since you already created a new action, add a new action for Google Drive in the custom actions.
Now that we've set up the basics in the Google Cloud Platform let's return to our custom GPT configuration in ChatGPT to implement the Google Drive API integration.
Add a new action specifically for Google Drive interactions. Click "Create new action" in the custom actions section.
Let’s first tackle the schema. The schema will define our GPT operations on Google Drive. It includes reading file contents, searching for specific documents, and, of course, listing files.
For your ease, copy and paste the schema below:
{
"openapi": "3.1.0",
"info": {
"title": "Google Drive API",
"description": "API for interacting with Google Drive",
"version": "1.0.0"
},
"servers": [
{
"url": "https://www.googleapis.com/drive/v3"
}
],
"paths": {
"/files": {
"get": {
"operationId": "ListFiles",
"summary": "List files",
"description": "Retrieve a list of files in the user's Google Drive.",
"parameters": [
{
"name": "q",
"in": "query",
"description": "Query string for searching files.",
"required": false,
"schema": {
"type": "string"
}
},
{
"name": "includeItemsFromAllDrives",
"in": "query",
"description": "Whether both My Drive and shared drive items should be included in results.",
"required": false,
"schema": {
"type": "string"
}
},
{
"name": "supportsAllDrives",
"in": "query",
"description": "Whether the requesting application supports both My Drives and shared drives.",
"required": false,
"schema": {
"type": "string"
}
},
{
"name": "pageSize",
"in": "query",
"description": "Maximum number of files to return.",
"required": false,
"schema": {
"type": "integer",
"default": 10
}
},
{
"name": "pageToken",
"in": "query",
"description": "Token for continuing a previous list request.",
"required": false,
"schema": {
"type": "string"
}
},
{
"name": "fields",
"in": "query",
"description": "Comma-separated list of fields to include in the response.",
"required": false,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "A list of files.",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"kind": {
"type": "string",
"example": "drive#fileList"
},
"nextPageToken": {
"type": "string",
"description": "Token to retrieve the next page of results."
},
"files": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"mimeType": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
},
"/files/{fileId}": {
"get": {
"operationId": "getMetadata",
"summary": "Get file metadata",
"description": "Retrieve metadata for a specific file.",
"parameters": [
{
"name": "fileId",
"in": "path",
"description": "ID of the file to retrieve.",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "fields",
"in": "query",
"description": "Comma-separated list of fields to include in the response.",
"required": false,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "Metadata of the file.",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"mimeType": {
"type": "string"
},
"description": {
"type": "string"
},
"createdTime": {
"type": "string",
"format": "date-time"
}
}
}
}
}
}
}
}
},
"/files/{fileId}/export": {
"get": {
"operationId": "export",
"summary": "Export a file",
"description": "Export a Google Doc to the requested MIME type.",
"parameters": [
{
"name": "fileId",
"in": "path",
"description": "ID of the file to export.",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "mimeType",
"in": "query",
"description": "The MIME type of the format to export to."
"required": true,
"schema": {
"type": "string",
"enum": [
"application/pdf",
"application/vnd.openxmlformats-office document.wordprocessing ml. document",
"text/plain"
]
}
}
],
"responses": {
"200": {
"description": "The exported file."
"content": {
"application/pdf": {
"schema": {
"type": "string",
"format": "binary"
}
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": {
"schema": {
"type": "string",
"format": "binary"
}
},
"text/plain": {
"schema": {
"type": "string",
"format": "binary"
}
}
}
},
"400": {
"description": "Invalid MIME type or file ID."
},
"404": {
"description": "File not found."
}
}
}
}
}
}
The schema you just copied is a robust set of tools that technically allows the GPT to interact with the Google Drive files.
Note: If you are looking to manage large datasets or access some Google Sheets or Docs specifically, it is recommended that you create separate integrations for their respective APIs. You have to create and implement separate APIs for Google Sheets and Google Docs using GCP.
For the authentication settings, use OAuth and set the following values:
Code:
Authorization URL: https://accounts.google.com/o/oauth2/auth
Token URL: https://oauth2.googleapis.com/token
Scope: https://www.googleapis.com/auth/drive.readonly
Click Save without changing anything.

A callback URL will appear in the configure tab once you've added the schema and set up the authentication. Make sure to copy this URL, as you'll need it later when we return to Google Cloud Platform to complete setting up our credentials.

Step 4 - Finishing the setup
After getting a callback URL, go to the GCP site to create OAuth credentials. In the Credentials tab, click ‘Create Credentials and select ‘OAuth client ID from the drop-down menu.

Select ‘web application’ in the drop-down menu of the OAuth client ID and specify a name.

Again, do not get bogged down by the confusing information on the page. In this step, you have to add the authorized redirect URI. Select it and paste the callback URL you copied from your custom GPT configuration screen into the ‘Authorized redirect URIs’ by clicking the ‘Add URI.’


Click Create. the platform generates a client ID and a client secret. Go to the custom GPT configuration screen, and in the authentication settings of your Google Drive, enter the client ID and the client secret you just got from GCP.
This setup establishes a secure way for your custom GPT to access your Google Drive files. The OAuth process ensures users explicitly permit the GPT to access their Drive, keeping everything safe and private.
After the setup, you can deploy it by clicking the Create button in the top right corner to publish your GPT.


Step 5 - Using your customized GPT
Here comes the fun part: You get to test your custom GPT.
Open a new chat with your custom GPT and start with a prompt of your choice. The GPT is designed to follow and understand natural language queries. You can talk in English, and it will access your files and interact with them to give you a drill-down of the information.
We asked our Google Drive to extract and create a summary of the information in the document containing another tutorial.
Here is the sample query:
Prompt
Can you please extract key information in the document named [Enter document name here]?

You can try many other prompts to utilize your GPT’s ability to access, analyze, and provide any information about your documents in the drive. Here are a few examples of prompts you can use to get started.
Project Management:
Summarize the status of all ongoing projects from our latest project tracker spreadsheet.
Sales Performance:
Based on the most recent sales report, what are our top 5 selling products this quarter?
Inventory Management:
Check our current stock levels for products below the reorder point in our inventory spreadsheet.
Content Calendar Review:
What blog posts are scheduled for publication in the next two weeks, according to our content calendar?
Meeting Preparation:
Compile the key discussion points from the agenda and related documents for tomorrow's board meeting.
Get creative with the prompts. You can use it to prepare for a meeting, track project progress, or analyze business performance. Now, it’s not about accessing Google Drive and searching for documents. You can use your drive from your ChatGPT window to get any or all the current information you need.