Requests and Responses

With CustomGPT, you can use a wide variety of programming languages to make HTTP requests for our API.

Generating a Project

To make your first call, you can copy and paste the below code to create a new Project called "Test", but you will need to replace "sitemap.com" with your actual desired sitemap, and "APIKey_Here" with your actual API key.

curl --request POST \
     --url https://app.customgpt.ai/api/v1/projects \
     --header 'accept: application/json' \
     --header 'authorization: Bearer APIKey_Here' \
     --header 'content-type: multipart/form-data' \
     --form project_name=Test \
     --form sitemap_path=sitemap.com

Sending Messages

Once you have generated your first project, it will receive an associated Project ID. This will be your key to sending a message to your Project via our API.

Creating a Conversation

First, you must create a Conversation within the Project. Below, replace 'projectID' with the Project ID of your new Project, and 'APIKey_Here' with your actual API key.

curl --request POST \
     --url https://app.customgpt.ai/api/v1/projects/projectID/conversations \
     --header 'accept: application/json' \
     --header 'authorization: Bearer APIKey_Here' \
     --header 'content-type: application/json'

Sending a Message to the Conversation

Once you have created a Conversation, you can get started by sending a message in that Conversation. In the below example, replace 'projectID' with the Project ID of your new Project, 'sessionID' with the session ID of the Conversation created, and 'APIKey_Here' with your actual API key.

curl --request POST \
     --url https://app.customgpt.ai/api/v1/projects/projectID/conversations/sessionID/messages \
     --header 'accept: application/json' \
     --header 'authorization: Bearer API_key_Here' \
     --header 'content-type: application/json' \
     --data '{"prompt":"Hello!"}'

Edit Settings to Enable Streaming

Want to see your answer generated in real-time, piece by piece? Try enabling streaming. You can enable streaming by changing the URL line in the previous snippet to add '?stream=true' to the end:

     --url https://app.customgpt.ai/api/v1/projects/projectID/conversations/sessionID/messages?stream=true \

Here's what a sample streaming output would look like:

event: start
data: {"status":"start","prompt":"Hello!"}

event: progress
data: {"status":"progress","message":""}

event: progress
data: {"status":"progress","message":"Hello"}

event: progress
data: {"status":"progress","message":"!"}

event: progress
data: {"status":"progress","message":" How"}

event: progress
data: {"status":"progress","message":" can"}

event: progress
data: {"status":"progress","message":" I"}

event: progress
data: {"status":"progress","message":" assist"}

event: progress
data: {"status":"progress","message":" you"}

event: progress
data: {"status":"progress","message":" today"}

event: progress
data: {"status":"progress","message":"?"}

event: finish
data: {"status":"finish","id":2495484,"created_at":"2024-05-23T03:12:49.000000Z","session_id":"99722e7b-9f6d-4f29-8fcf-aae2566e89e8","citations":null}

Parsing the streamed message and compiling it into a full response has many nuances and should be approached with caution. We have examples in our cookbook if you wish to learn more.

We also offer the ability to query and receive responses from your CustomGPT agents without streaming. Your output can be expected to look something like this for a non-streamed answer from your CustomGPT chatbot:

{
  "data": {
    "id": 2495484,
    "created_at": "2024-05-23T03:12:49.000000Z",
    "updated_at": "2024-05-23T03:12:49.000000Z",
    "user_id": 1408827,
    "user_query": "Hello!",
    "openai_response": "Hello! How can I assist you today?",
    "citations": null,
    "metadata": {
      "user_ip": "IP_Address",
      "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36",
      "external_id": "",
      "request_source": "api"
    }
  },
  "status": "success"
}