Integrating Groq AI with SAP Cloud Integration (CPI) – Calling an AI API and Returning the Response
Share

[[{“value”:”

Introduction

Generative AI is becoming an important part of modern integration architectures. SAP Integration Suite – Cloud Integration (CPI) can act as an orchestration layer between enterprise applications and external AI services.

In this blog, we will see how to integrate Groq AI with SAP Cloud Integration using a simple HTTPS-based integration flow.

The objective is to:

  1. Receive a request from a sender through HTTPS.
  2. Prepare the request payload required by Groq.
  3. Retrieve the Groq API key securely.
  4. Invoke the Groq AI API from SAP Cloud Integration.
  5. Receive the AI-generated response.
  6. Process the response in CPI.
  7. Return/process the generated response as the target output. 

1. Architecture

The following integration flow represents the complete scenario :- 

INTEGRATION FLOW

 

The flow consists of the following major steps :- 

Step Component Purpose

1 HTTPS Sender Receives the request from the client
2 Build_Request Converts the incoming request into Groq API format
3 API_KEY_Script Retrieves the Groq API key securely
4 Call_GroqAI Calls the Groq API using HTTP
5 Attachment_script Processes the response from Groq
6 End Completes the integration flow

Groq provides OpenAI-compatible APIs.

And authentication is performed using a Bearer API key.

2. Prerequisites

Before creating the integration flow, we need the following:

  • SAP Integration Suite / Cloud Integration tenant 
  • Access to create and deploy Integration Flows 
  • A Groq account
  • Groq API key
  • Basic knowledge of SAP Cloud Integration
  • Access to maintain Security Material in CPI
  • A REST client such as Postman for testing 

 

3. Create a Groq Account

First, create an account on GroqCloud.

Open the official Groq website .

After logging in, navigate to the API Keys section.

Groq provides a dedicated API Keys page where project API keys can be created and managed.

4. Generate the Groq API Key

From the Groq console:

  1. Log in to GroqCloud.
  2. Open API Keys.
  3. Select Create API Key.
  4. Provide a meaningful name.

For example:

SAP_CPI_GROQ_API
  1. Create the key.
  2. Copy the generated API key.

Important

The API key is a secret credential.

Do not:

  • hardcode the key in a Groovy script
  • put the key directly into the integration flow source code
  • commit the key to Git
  • expose it in screenshots
  • share it in SAP Community
  • include it directly in Postman collections that are publicly shared

Groq also recommends keeping API keys safe and avoiding unnecessary exposure.

For the CPI implementation, we will store the API key in SAP Cloud Integration Security Material rather than hardcoding it.

 

5. Create a Secure Parameter in SAP Cloud Integration

Now we need to store the Groq API key securely in CPI.

In SAP Cloud Integration:

Monitor → Security Material → Create → Secure Parameter

SAP Cloud Integration provides Secure Parameter artifacts specifically for storing confidential values.

Create a secure parameter with:

Name:
GROQ_API_KEY

For the value, enter the API key generated from Groq.

Then deploy the Secure Parameter.

The alias/name of the secure parameter can subsequently be used by a Groovy script to retrieve the secret at runtime.

 
SHIVARAM__ITHARAJU_0-1786712286102.png

 

6. Create the Integration Flow

Create a new Integration Flow in your SAP Cloud Integration package.

For example:

Package:
AI Integration

Integration Flow:
CPI_Groq_AI_Integration

The flow will look like:

Sender
   |
 HTTPS
   |
 Start
   |
 Build_Request
   |
 API_KEY_Script
   |
 Call_GroqAI
   |
 Attachment_script
   |
 End

 

7. Configure the HTTPS Sender

Add an HTTPS Sender Adapter to the integration flow.

For example:

Address:
 /groq-ai

After deployment, CPI generates an endpoint similar to:

https://<your-cpi-tenant>/http/groq-ai

The exact endpoint depends on your Cloud Integration tenant.

 

8. Define the Input Payload

For this example, we can use a simple TEXT request.

Example:

Explain SAP Cloud Integration in simple terms.

The sender sends this TEXT to CPI .
In my case I used the postman to send input to the CPI.
The responsibility of the Build_Request step is to convert this simple input into the format expected by Groq.

 

 

9. Build_Request Script

Add a Groovy Script step after the Start event.

Name it:

Build_Request

 

The purpose of this script is to create the request expected by the Groq Chat Completions API.

import com.sap.gateway.ip.core.customdev.util.Message
import groovy.json.JsonOutput

def Message processData(Message message) {

def userInput = message.getBody(String) ?: “Hello”
userInput = userInput.trim().replaceAll(“[^\x20-\x7E\s]”, “”)

if (userInput.isEmpty()) {
userInput = “Hello, can you explain what is SAP CPI?”
}

def requestMap = [
model: “openai/gpt-oss-120b”, // ← Updated model
messages: [
[
role : “user”,
content: userInput
]
]
]

def jsonBody = JsonOutput.toJson(requestMap)
message.setBody(jsonBody)

return message
}

 

10. API_KEY_Script

Next, we need to retrieve the API key from SAP Cloud Integration Security Material.

Add another Groovy Script step:

API_KEY_Script

 

The recommended approach is to retrieve the secret from a Secure Parameter rather than hardcoding it.

SAP provides the SecureStoreServiceAPI for retrieving credentials stored in Security Material.

import com.sap.gateway.ip.core.customdev.util.Message
import com.sap.it.api.securestore.SecureStoreService
import com.sap.it.api.securestore.UserCredential
import com.sap.it.api.ITApiFactory

def Message processData(Message message) {

def secureStore = ITApiFactory.getApi(SecureStoreService.class, null)
UserCredential credential = secureStore.getUserCredential(“Groq_API_key”)
def apiKey = credential.getPassword()?.toString()

// Groq uses Bearer token in Authorization header
message.setHeader(“Authorization”, “Bearer ” + apiKey)
message.setHeader(“Content-Type”, “application/json”)

return message
}

 

11. Configure the Call_GroqAI Receiver

Now we configure the HTTP receiver that calls Groq.

Add a Receiver participant and connect it to the “Request Reply” (Call_GroqAI step.

Choose:

HTTP Receiver Adapter

 

SAP Cloud Integration’s HTTP Receiver Adapter is designed to communicate with external target systems using HTTP.

HTTP

Now we are set to test the IFLOW and get the responses from the GroqAI.
You guys can skip the attachment step .

 

12. Common Errors and Troubleshooting

401 – Unauthorized

Possible causes:

  • Incorrect API key
  • API key expired/revoked
  • Incorrect Authorization header
  • Incorrect Secure Parameter alias

Verify:

Authorization: Bearer <API_KEY>

Do not accidentally create:

Authorization: <API_KEY>

or:

Authorization: BearerBearer <API_KEY>

400 – Bad Request

Usually caused by an invalid request body.

Check:

{
    "model": "...",
    "messages": [
        {
            "role": "user",
            "content": "..."
        }
    ]
}

Make sure:

Content-Type = application/json

Also verify that the model ID is currently supported by Groq.


404 – Not Found

Verify that the receiver URL is correct.

For Chat Completions:

https://api.groq.com/openai/v1/chat/completions

Do not accidentally use an incorrect endpoint.


Empty AI Response

Check the response structure.

The generated text is normally located under:

choices[0].message.content

Also verify that the Groq response is actually reaching the Attachment_script.


 

API Key Not Found in CPI

Verify:

  1. Secure Parameter exists.
  2. Secure Parameter is deployed.
  3. Alias matches exactly.
  4. The integration flow is using the correct alias.
  5. The runtime has access to the Security Material.

SAP’s SecureStoreService supports retrieving deployed credentials using the credential alias.

 

13. Important Design Consideration – AI Is an External Dependency

When introducing AI into an enterprise integration, it is important to remember that Groq is an external service.

Therefore, the integration should account for:

  • Network availability
  • API availability
  • Rate limits
  • Model availability
  • API errors
  • Response time
  • Token limits
  • Data privacy
  • Sensitive business data
  • Organizational AI policies

The SAP HTTP Receiver documentation also highlights the need to ensure that external data exchange complies with organizational policies.

Before sending production SAP business data to an external AI service, appropriate security, privacy, legal, and organizational reviews should be completed.

14. Possible Real-World Use Cases

  • AI-Powered Text Summarization
  • Exception Process Error Summarization
  • Incident/Ticket Classification
  • Customer Email Classification
  • Error Message Analysis and Root-Cause Suggestions
  • Automated Business Data Extraction
  • Document Content Analysis
  • AI-Based Data Validation
  • Natural Language to Structured JSON Conversion
  • AI-Powered Response Generation for SAP Applications 

 

15. Response from Groq

SHIVARAM__ITHARAJU_1-1786972212419.png

 

16. Conclusion

In this blog, we implemented a simple but powerful integration between SAP Cloud Integration and Groq AI.

The integration demonstrates how CPI can act as an enterprise orchestration layer for Generative AI services.

The important takeaway is that no dedicated Groq adapter is required. Since Groq exposes an HTTP-based, OpenAI-compatible API, SAP Cloud Integration’s HTTP capabilities can be used to build the integration.

This basic scenario can serve as a foundation for more advanced enterprise AI integration patterns such as AI-powered document processing, ticket classification, text summarization, intelligent routing, email classification, and natural-language processing.

As AI adoption continues to grow, integration platforms such as SAP Cloud Integration can play an important role in securely connecting enterprise applications with external AI capabilities.

“}]] 

  Read More Technology Blog Posts by Members articles 

#abap

By ali

Leave a Reply