Benchmark

Claude Code is 4.2x faster & 3.2x cheaper with CustomGPT.ai plugin. See the report →

CustomGPT.ai Blog

Get Citation Details Using CustomGPT RAG API – A Step-by-Step Guide

Author Image

Written by: Priyansh Khodiyar

Retrieval Augmented Generation RAG The Definitive Guide 2025 3 1

In this guide, you’ll learn how to retrieve citation details from a conversation message using the CustomGPT RAG API. We’ll walk through setting up an agent with a sitemap, starting a conversation, sending a message, and finally extracting citation information from the RAG API response. The explanations are written in a friendly, simple tone to help you understand every step.

1. Prerequisites to use CustomGPT RAG API

Before you begin, make sure you have the following:

  • CustomGPT.ai Account: Sign up and log in at CustomGPT.ai.
  • RAG API Key: Retrieve your RAG API token from your dashboard.
  • Basic Python Knowledge: Knowing a bit about Python, REST APIs, and JSON will be helpful.
  • Google Colab: We’re demonstrating this in Google Colab, but you can use any Python environment.
  • Required Libraries: This notebook uses requests, json, and sseclient-py (for streaming responses) along with Google Colab’s file upload utilities.

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

With these basics covered, let’s set up your environment.

2. Setting Up Your Environment

Open the Notebook

Upload the Notebook: Open Google Colab and upload the Get_citation_details.ipynb file.

Install Dependencies

Make sure you have the necessary packages. For example, run:

!pip install sseclient-py

Configure Your RAG API Key

At the beginning of the notebook, replace ‘YOUR_API_TOKEN‘ with your actual RAG API token:

api_endpoint = 'https://app.customgpt.ai/api/v1/'

api_token = 'YOUR_API_TOKEN'

Get Your RAG API Key

To get your RAG 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.
AD 4nXcvxZ9azT79eOuquuRIdrexuigthBvgC6lPEs6Voc3gx1ofmabCHriWvhrgT4lWksO06XydtDvfJQegoachQeqRmCVU36hbzUTP34dssSKre85t TrqP Mik2wh7tCONISVrGbf

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.

Now that your environment is ready, let’s dive into the code.

3. Code Walkthrough

This section explains the code step-by-step. We’ll cover how to create an agent from a sitemap, start a conversation, send a message, and finally extract citation details.

3.1 Creating an Agent with a Sitemap

In this step, we create a new agent by providing a name and a sitemap URL. This example uses a multipart/form-data request, which is useful for file uploads and form data.

# Setup API URL, API Token, and headers for file uploads

api_endpoint = 'https://app.customgpt.ai/api/v1/'

api_token = 'YOUR_API_TOKEN'

from google.colab import files

import requests

import json

# Agent details

project_name = 'Example ChatBot using Sitemap'

sitemap_path = 'https://adorosario.github.io/small-sitemap.xml'

# Construct payload for multipart/form-data

payload = {

    "project_name": (None, project_name),

    "sitemap_path": (None, sitemap_path)

}

headers = {

    'Authorization': 'Bearer ' + api_token

}

# Create the agent

url = api_endpoint + 'projects'

create_project = requests.request('POST', url, headers=headers, files=payload)

print(create_project.text)

Explanation:

  • Payload Construction: The code builds a payload using the multipart/form-data format. It includes the agent’s name (project_name) and the sitemap URL (sitemap_path).
  • Agent Creation: A POST request is sent to the /projects endpoint. Although the code uses “project” in the variable names, think of it as creating your agent. The response includes details like the unique agent ID.

Once your agent is created, we move on to creating a conversation within that agent.

3.2 Creating a Conversation Within the Agent

After creating the agent, we start a conversation. This helps set the stage for sending messages and later retrieving citation details.

# Extract agent ID from the agent creation response

data = json.loads(create_project.text)["data"]

project_id = data["id"]

# Prepare payload to create a conversation

name = 'Test Converasation'

payload = json.dumps({

    "name": project_name

})

headers = {

    'Content-type' : 'application/json',

    'Authorization': 'Bearer ' + api_token

}

# Create a conversation within the agent

url = api_endpoint + 'projects' + f"/{project_id}" + '/conversations'

create_conversation = requests.request('POST', url, headers=headers, data=payload)

print(create_conversation.text)

Explanation:

  • Extracting the Agent ID: The unique agent ID is extracted from the response of the agent creation call.
  • Conversation Creation: A POST request is made to /projects/<project_id>/conversations to start a new conversation. The response contains a session_id, which is needed for the next steps.

With the conversation created, the next step is to send a message.

3.3 Sending a Message to the Conversation

Here, we send a message to the conversation. In this example, the response is returned in one complete chunk (non-streaming), which makes it easier to work with when extracting citation details.

# Install SSE Client (for streaming, if needed)

!pip install sseclient-py

from sseclient import SSEClient


# Extract conversation data and session_id

conversation_data = json.loads(create_conversation.text)["data"]

session_id = conversation_data["session_id"]


# Prepare and send the message to the conversation

prompt = "Who is Tom brady"

stream = 0  # 0 for non-streaming response


url = api_endpoint + 'projects/' + str(project_id) + '/conversations/' + str(session_id) + '/messages'


payload = json.dumps({

    "prompt": prompt,

    "stream": stream

})


response = requests.post(url, stream=False, headers=headers, data=payload)


print(response.text)

Explanation:

  • Message Preparation: The prompt “Who is Tom brady” is sent to the conversation endpoint. We set stream to 0 to get a single, complete response.
  • Response Type: The non-streaming response is easier to parse because all the data is available in one go.

Now that we have the message response, we can extract the citation details.

3.4 Retrieving Citation Details

The message response contains an array of citation IDs. In this step, we extract the first citation ID and use it to fetch detailed citation information.

# Parse the message response to extract citation id

message_data = json.loads(response.text)['data']

citation_id = message_data['citations'][0]


# Construct the URL for retrieving citation details

url = api_endpoint + 'projects/' + str(project_id) + '/citations/' + str(citation_id)


citation_response = requests.get(url, headers=headers, data=payload)

print(citation_response.text)

Explanation:

  • Extracting Citation ID: The code parses the JSON response from the message to get the first citation ID from the citations field.
  • Fetching Citation Details: A GET request is sent to /projects/<project_id>/citations/<citation_id> to retrieve detailed information about the citation. The detailed citation info is then printed out.

Now that we have walked through every step, let’s see how to run and verify the entire notebook.

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 each cell in your notebook sequentially—from creating the agent to fetching citation details.
  2. Monitor the Outputs:
    • Verify that the agent and conversation are created successfully.
    • Check that the message response contains citation IDs.
    • Confirm that the citation details are retrieved and printed correctly.

Verifying on CustomGPT.ai

Log in to your CustomGPT.ai dashboard to see your newly created agent. Review the citation details to ensure everything is processed as expected.

With everything running smoothly, let’s look at a few common issues you might face.

5. Troubleshooting Common Issues

Here are some common problems and simple fixes:

  • Invalid RAG API Token: Double-check that you’ve replaced ‘YOUR_API_TOKEN‘ with your actual RAG API token and that it is active.
  • Multipart/Form-Data Errors: Make sure the payload format is correct for file uploads and form data.
  • JSON Parsing Errors: Confirm that the RAG API responses are valid JSON and that you’re using the correct keys to extract data.
  • Missing Citation Data: If no citation data appears, verify that your conversation message is generating citations and check the RAG API documentation for any additional parameters you might need.

For more help, consult the official CustomGPT.ai documentation or join our community support.

6. Conclusion

Congratulations! In this guide, you learned how to use the CustomGPT.ai API and SDK to:

  • Create an agent using a sitemap with the CustomGPT’s RAG API.
  • Start a conversation within that agent.
  • Send a message and extract citation details from the response.
  • Retrieve detailed citation information using the citation ID.

This step-by-step process makes it easy to harness citation data from your chatbot interactions. Whether you need the citations for content validation or reference management, you now have the tools to get the job done.

If you have any questions or need further assistance, feel free to consult the CustomGPT.ai documentation or join our community. Happy coding, and enjoy building robust chatbot solutions with CustomGPT.ai!

Frequently Asked Questions

What are citations in a RAG API response?

“AI Ace is already trained on the book, knows the answer to the question, and will give the right answer!” — Leon Niederberger, Founder, AI Ace. In a RAG API response, citations are the source references attached to an assistant message so you can trace the answer back to the document or website content used during retrieval. They help you verify the answer, show supporting evidence in your UI, and troubleshoot retrieval quality.

How do I retrieve citation details after sending a message through the RAG API?

GEMA handles 248,000 member inquiries a year with an 88% query success rate. To retrieve citation details, follow the sequence shown in the guide: create an agent from a sitemap, start a conversation, send a message, and then get the citation details for that conversation message. The API uses API-key authentication, and the walkthrough demonstrates the flow in Python.

Why do citation details sometimes appear to be missing?

In a published benchmark, CustomGPT.ai outperformed OpenAI in RAG accuracy, but you still need to read citations from the correct step in the workflow. Citation details are retrieved from the conversation message after the assistant reply is returned, not from earlier setup steps like agent creation or conversation start. A practical check is to test with a small sitemap-based agent, ask one factual question, and inspect the returned assistant message before expanding the implementation.

Can I show citation details as source links in my app?

“Powered by my custom-built Theory of Change AIM GPT agent on the CustomGPT.ai platform. Rapidly Develop a Credible Theory of Change with AI-Augmented Collaboration.” — Barry Barresi, Social Impact Consultant. Yes. You can display the citation metadata returned for each assistant message so users can inspect the underlying source instead of seeing only a generic label. When the citation details include a source identifier or link, render it consistently so users can verify where the answer came from.

What is the simplest way to test citation retrieval before adding UI code?

“The tool I recommended was something I learned through 100 school and used at my job about two and a half years ago. It was CustomGPT.ai! That’s experience. It’s not just knowing what’s new. It’s remembering what works.” — Dan Mowinski, AI Consultant. The simplest test is to keep the setup small: create one agent from a short sitemap, start one fresh conversation, send one factual question, and confirm that the assistant message returns citation details before you add interface or integration code. That keeps the test focused on the API workflow itself.

Why are citation details useful when your RAG API answers from documents?

“I just discovered CustomGPT, and I am absolutely blown away by its capabilities and affordability! This powerful platform allows you to create custom GPT-4 chatbots using your own content, transforming customer service, engagement, and operational efficiency.” — Evan Weber, Digital Marketing Expert. Citation details are especially useful when answers come from PDFs, DOCX files, HTML pages, JSON, or other ingested sources because they let you trace a response back to the content behind it. That makes it easier to verify claims, compare documents, and spot outdated material.

Can citation details support internal or regulated knowledge assistants?

Yes. Citation details improve auditability because users can inspect the source behind an answer instead of relying on an unsupported response. That is useful for internal knowledge assistants and other higher-trust use cases. Supporting safeguards include GDPR compliance, a commitment that data is not used for model training, and SOC 2 Type 2 certification for independently audited security controls.

Related Resources

If you’re evaluating broader deployment options, this guide expands on how CustomGPT.ai supports production-grade RAG use cases.

  • Enterprise RAG API — Explore how CustomGPT.ai’s enterprise RAG API supports scalable, secure retrieval-augmented generation for business applications.

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.