File Upload to an Existing Project Using CustomGPT APIs – A Step-by-Step Guide

Author Image

Written by: Priyansh Khodiyar

In this tutorial, you’ll learn how to attach a file to an existing project using CustomGPT APIs file upload capabilities. We’ll cover how to set up your environment in Google Colab, create a project (with a sitemap for context), and then add an external file to that project.

Make sure you have read our Getting Started with CustomGPT.ai for New Developers blog to get an overview of the entire platform..

Follow along with the code and explanations to seamlessly integrate file uploads into your projects.

Link to the complete notebook – https://github.com/Poll-The-People/customgpt-cookbook/blob/main/examples/Add_a_file_to_an_existing_project.ipynb

1. Prerequisites

Before you begin, make sure you have the following:

  • CustomGPT.ai Account: Sign up and log in at CustomGPT.ai.
  • API Key: Generate your API token from your dashboard and keep it handy.
  • Basic Python Knowledge: Familiarity with Python and making HTTP requests using libraries like requests.
  • Google Colab: We’ll run our code on Google Colab, so no local environment setup is needed.

2. Setting Up Your Environment in Google Colab

Opening the Notebook

  1. Upload the Notebook: Open Google Colab and upload the Add_a_file_to_an_existing_project.ipynb file.
  2. Install Required Libraries:
    Although this notebook only requires requests and json (which are typically available in Colab), ensure that any additional dependencies are installed as needed.

Configuring Your CustomGPT API Key and Endpoints

At the beginning of the notebook, you’ll find the API endpoint and token configuration:

Replace ‘ADD_YOUR_API_TOKEN_HERE‘ with your actual API token. This token is essential for authenticating your API calls. Plus add the required imports.

Get Your API Key

To get your API key, there are two ways:

Method 1 – Via Agent

  1. Agent > All Agents.
  2. Select your agent and go to deploy, click on the API key section and create an API. 

Method 2 – Via Profile section.

  1. Go to profile (top right corner of your screen)
  2. Click on My Profile
  3. You will see the screen something like this (below screenshot). Here you can click on “Create API key”, give it a name and copy the key.

Please save this secret key somewhere safe and accessible. For security reasons, You won’t be able to view it again through your CustomGPT.ai account. If you lose this secret key, you’ll need to generate a new one.

3. Code Walkthrough

Let’s break down the notebook code to understand how it works.

3.1 Retrieving the Project ID

Go to the particular project you wish to add / upload file to, then, navigate to the Deploy section.

You will find the Agent ID on the right top corner.

project_id = 1234

This ID is crucial as it tells the API where to add the file in the next step.

3.2 Uploading a File from Google Colab

Now, you add a file (a source) to the existing project.

File Upload Process:

  • File Upload Widget: The notebook uses Google Colab’s file upload widget to select a file from your local system:
from google.colab import files

uploaded_file = files.upload()

file_content = next(iter(uploaded_file.values()))

file_data = file_content
  • This interactive step allows you to choose the file you want to attach.
  • Preparing the Payload: Instead of JSON, the file is sent as part of a multipart/form-data payload:
payload = {

    "file": file_data

}

3.3 Making the API Request to Add the File

  • Endpoint Construction: The URL is constructed using the project ID:
url = api_endpoint + 'projects' + f"/{project_id}/" + 'sources'
  • This endpoint specifically handles file (source) additions for the given project.
  • Sending the Request: The file is uploaded via a POST request:
create_source = requests.request('POST', url, headers=headers, files=payload)

print(create_source.text)
  • The response confirms whether the file was successfully attached to your project.

4. Running and Testing the Notebook

Now that your notebook is set up, it’s time to execute it to create your project and upload files. Follow these instructions to make sure everything works as expected.

Step-by-Step Execution

  1. Run Each Cell: Execute the cells in sequential order in your Colab notebook.
  2. Monitor Output:
    • Project Creation: Look for the JSON response that includes the project ID and other details.
    • File Upload: After uploading your file, review the output confirming the file has been added to the project.

Verifying on CustomGPT.ai

Log into your CustomGPT.ai dashboard to verify that your project now includes the new file as a source. This confirms that your API calls were successful and that your project has been updated accordingly.

5. Beyond the Notebook: Scaling Up with Multiple Operations

While this notebook focuses on adding a file to an existing project, you can integrate this functionality into larger applications. Imagine a menu-driven CLI or web interface where you can:

  • Create projects with various metadata.
  • Attach multiple files or data sources.
  • Manage and update project details through a unified interface.

Example: Menu-Driven Program Pseudo-Code

def main_menu():

    print("CustomGPT CLI Menu:")

    print("1. Create Project")

    print("2. Add File to Project")

    print("3. View Project Details")

    # Additional options here...

    choice = input("Enter your choice: ")

    if choice == "1":

        create_project_function()

    elif choice == "2":

        add_file_to_project_function()

    # and so on...

if __name__ == "__main__":

    main_menu()

This modular approach can help you manage multiple API endpoints and operations in one scalable program.

6. Troubleshooting Common Issues

Even with well-documented steps, you might face a few challenges:

  • API Key Issues: Ensure your API key is correctly set and active.
  • File Upload Errors: Confirm the file format and size meet the API requirements.
  • Endpoint Errors: Double-check that the constructed URL (especially the project ID) is correct.
  • Network Issues: Verify your internet connection if requests time out or fail.

For further help, refer to the CustomGPT.ai documentation or engage with the community support forums.

7. Conclusion

In this guide, you learned how to add a file to an existing project using the CustomGPT API in a Google Colab notebook. We covered:

  • Setting up your environment and configuring the API key.
  • Creating a new project with a sitemap.
  • Uploading and attaching a file as a source to your project.
  • How to run the notebook and verify results.

This step-by-step process demonstrates how easily you can extend your projects using the CustomGPT API. As you become more familiar with these operations, consider building a comprehensive, menu-driven tool to manage all your project operations seamlessly.

Happy coding, and enjoy expanding your CustomGPT projects!

Build a Custom GPT for your business, in minutes.

Deliver exceptional customer experiences and maximize employee efficiency with custom AI agents.

Trusted by thousands of organizations worldwide

Related posts

2 Comments


Avatar photo
astro robot clicker
March 11, 2025 at 10:58 pm
Reply

Where can I find the API key?


    priyansh khodiyar cover image
    Priyansh Khodiyar
    March 12, 2025 at 11:08 am
    Reply

    To get your API key, there are two ways:

    Method 1 – Via Agent
    Agent > All Agents
    Select your agent and go to deploy, click on the API key section and create an API.

    Method 2 – Via Profile section.
    1. Go to profile (top right corner of your screen)
    2. Click on My Profile
    3. Click on API tab. Here you can click on “Create API key”, give it a name and copy the key.

Leave a reply

Your email address will not be published. Required fields are marked *

*

3x productivity.
Cut costs in half.

Launch a custom AI agent in minutes.

Instantly access all your data.
Automate customer service.
Streamline employee training.
Accelerate research.
Gain customer insights.

Try 100% free. Cancel anytime.