Skip to Content
Technical Articles
Author's profile photo Bhaskar Sai Shankar

ChatGPT using SAP CPI

To the beginners in CPI, for hands-on this blog would be helpful understanding how can we integrate ChatGPT using CPI basic Iflow with steps.

ChatGPT: It’s a chatbot powered by OpenAI’s GPT (Generative Pre-trained Transformer) language model. It’s capable of generating human-like responses to various questions and prompts. It can be integrated into messaging platforms, customer support systems and other apps.

Prerequisites: OpenAI account, SAP CPI, Postman

Step 1:
First, we need to create a secret key on OpenAI website
Step 2: 
To authenticate we need to download certificate provided by OpenAI and upload it into CPI system. – Open this URL in the browser and download the certificate into your desktop.
Step 3: 
Go to CPI Monitor -> Manage Security -> Keystore and the upload the downloaded certificate
Step 4:
Create the Iflow using HTTPS as sender adapter as we are going to test the Iflow from Postman.
  • Content Modifier  Preparing Request Body (Headers)
  • Authorization value is the secret key that we created in Step 1, it should be in the format Bearer {secret key}


  • Content Modifier – Preparing Request Body (Body)

    "model": "gpt-3.5-turbo",
    "messages": [
            "role": "user",
            "content": "${in.body}"

Here we are building the body in JSON format to post the request content on ChatGPT API.

  • Request Reply – HTTP adapter Configurations

  • JSON To XML Converter – Converting JSON body received from the ChatGPT API to XML for extracting the content from the required field (using XML format is easier to extract the content from required field)

  • Groovy Script – Extracting the content from required field using groovy script and storing in the body

import java.util.HashMap;
import groovy.xml.*;

def Message processData(Message message) {
    def new_body = new XmlParser().parseText(message.getBody(java.lang.String) as String);
    def set_body = new_body.choices.message.content.text();
    return message;


Step 5:

Testing the Iflow using Postman

This is a basic example shows how to use ChatGPT with CPI. I could find it using very useful in building Iflows real-time.

Furthermore, we can use ChatGPT for many other use cases like building XSLT mappings, groovy scripts, building UDFs which helps in building Iflows with complex logics.

Happy Learning 😊

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo suramouli koduri
      suramouli koduri

      Nice blog Bhaskar.keep blogging

      Author's profile photo Bhaskar Sai Shankar
      Bhaskar Sai Shankar
      Blog Post Author

      Thank you suramouli

      Author's profile photo Tushar Rajput
      Tushar Rajput


      Will it work for simple questioning only

      As when I asked to Analyse the code or to write an ABAP report, It is unable to do it.


      Thanks & Regards


      Author's profile photo Bhaskar Sai Shankar
      Bhaskar Sai Shankar
      Blog Post Author

      Hello Tushar,

      Linearize the request body.



      Author's profile photo Avinash Paul Ullamparhti
      Avinash Paul Ullamparhti

      Thanks for the Blog Bhaskar!

      Author's profile photo Richard Nagel
      Richard Nagel

      Can you explain what you fill in in Postman in order to properly execute the iFlow? The POST line must have a proper HTTPS address, as {{host}}{{url_path_HTTPS}} is not understood by Postman ...


      thx Richard

      Author's profile photo Bhaskar Sai Shankar
      Bhaskar Sai Shankar
      Blog Post Author

      Hi Richard,

      {{host}}{{url_path_HTTPS}} are the global variables saved within postman.

      {{host}} - holds the host of my trail account & {{url_path_HTTPS}} - holds the path /http.