Description
SAP AI Core LLM Node for n8n
A custom n8n community node that enables integration with SAP AI Core's LLM models for text generation and chat completion tasks.
Features
- Text Generation: Generate text using deployed LLM models in SAP AI Core
- Chat Completion: Interactive chat with conversation context
- OAuth2 Authentication: Support for OAuth2 authentication with SAP AI Core
- Flexible Configuration: Customizable parameters like temperature, max tokens, top-p, and stop sequences
- Error Handling: Robust error handling with optional continue-on-fail behavior
Prerequisites
- n8n instance (self-hosted or cloud)
- SAP BTP account with AI Core service enabled
- Deployed LLM model in SAP AI Core
- Valid SAP AI Core OAuth2 credentials
Installation
⚠️ Important: This node is designed for self-hosted n8n installations only. It cannot be used with n8n Cloud due to dependency requirements.
Option 1: npm Installation (Recommended)
- Navigate to your n8n installation directory
- Install the package:
npm install n8n-nodes-sap-ai-core - Restart your n8n instance
Option 2: Development Setup
-
Clone this repository:
git clone https://github.com/pondev1/n8n-nodes-sap-ai-core.git cd n8n-nodes-sap-ai-core -
Install dependencies:
npm install -
Build the node:
npm run build -
Package and install locally:
npm pack npm install "C:\path\to\n8n-nodes-sap-ai-core\n8n-nodes-sap-ai-core-1.0.0.tgz" -
Set custom extensions path (Windows):
$env:N8N_CUSTOM_EXTENSIONS = "C:\Users\yourusername\.n8n\custom\node_modules" npx n8n start
SAP AI Core Setup
1. Deploy an LLM Model
First, ensure you have an LLM model deployed in SAP AI Core:
- Access SAP AI Launchpad
- Navigate to ML Operations > Deployments
- Create a new deployment with your desired LLM model
- Note the Deployment ID – you'll need this for the n8n node configuration
2. Get Authentication Credentials
- In SAP BTP Cockpit, navigate to Services > Instances and Subscriptions
- Find your AI Core service instance
- Create a service key
- Extract the following fields from the service key JSON:
- Client ID (from service key "clientid")
- Client Secret (from service key "clientsecret")
- OAuth URL (from service key "url" field)
- Base URL (from service key "serviceurls.AI_API_URL")
Node Configuration
1. Credentials Setup
-
In n8n, go to Credentials and click Add Credential
-
Search for and select SAP AI Core API
-
Fill in the required fields:
- Client ID: Your OAuth2 client ID (from service key "clientid")
- Client Secret: Your OAuth2 client secret (from service key "clientsecret")
- OAuth URL: Your OAuth2 token endpoint (from service key "url")
- Base URL: Your SAP AI Core API endpoint (from service key "serviceurls.AI_API_URL")
-
Save the credentials
2. Node Configuration
-
Add the SAP AI Core LLM node to your workflow
-
Configure the following parameters:
Required Parameters:
- Credentials: Select your SAP AI Core API credentials
- Operation: Choose between "Generate Text" or "Chat Completion"
- Model: Your model name (e.g., "gpt-35-turbo")
- Resource Group: SAP AI Core resource group (usually "default")
- Deployment ID: The deployment ID from SAP AI Launchpad
Operation-Specific Parameters:
For Generate Text:
- Prompt: The text prompt to send to the model
For Chat Completion:
- Messages: Array of conversation messages with roles (system, user, assistant)
Optional Parameters:
- Max Tokens: Maximum number of tokens to generate (default: 100)
- Temperature: Controls randomness (0-2, default: 0.7)
- Top P: Controls diversity via nucleus sampling (0-1, default: 1)
- Stop Sequences: Comma-separated list of stop sequences
Usage Examples
Basic Text Generation
{
"operation": "generateText",
"model": "gpt-35-turbo",
"resourceGroup": "default",
"deploymentId": "dabcd1234567890", // your-deployment-id
"prompt": "Write a brief summary of artificial intelligence."
}
Chat Completion
{
"operation": "chatCompletion",
"model": "gpt-35-turbo",
"resourceGroup": "default",
"deploymentId": "dabcd1234567890", // your-deployment-id
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "What is machine learning?"
}
]
}
Advanced Configuration with Custom Parameters
{
"operation": "generateText",
"model": "gpt-35-turbo",
"prompt": "Generate a creative story about robots.",
"additionalOptions": {
"max_tokens": 500,
"temperature": 0.8,
"top_p": 0.9,
"stop": "The End, END, ."
}
}
Sample Workflows
Ready-to-use n8n workflow examples are available in the workflows/ directory:
1. AI Core Chat Model Workflow
File: workflows/AI Core Chat Model.json
Demonstrates basic chat functionality using SAP AI Core chat models. This workflow shows how to configure and use the chat model for interactive conversations.
Features:
- Simple chat model configuration
- Direct chat interaction
- Response handling and formatting
2. AI Core LLM Agent Workflow
File: workflows/AI Core LLM Agent.json
Advanced workflow showing SAP AI Core integration with LLM agents for complex AI-powered automation tasks.
Features:
- LLM agent configuration
- Advanced AI workflows
- Tool integration capabilities
How to Use Sample Workflows
- Download the desired workflow JSON file
- In n8n, go to Workflows > Import from File
- Select the downloaded JSON file
- Configure your SAP AI Core credentials
- Update the
deploymentIdwith your actual deployment ID - Activate and test the workflow
Response Format
The node returns a JSON object containing:
{
"id": "response-id",
"object": "chat.completion",
"created": 1234567890,
"model": "gpt-35-turbo",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Generated text response..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 10,
"completion_tokens": 50,
"total_tokens": 60
},
"operation": "chatCompletion",
"deploymentId": "dabcd1234567890", // your-deployment-id
"resourceGroup": "default"
}
Troubleshooting
Common Issues
-
Authentication Errors
- Verify your credentials are correct
- Check that your OAuth2 URL is accessible
- Ensure your service key fields are properly extracted
-
Deployment Not Found
- Verify the deployment ID is correct
- Check that the deployment is in "Running" status in SAP AI Launchpad
- Ensure the resource group matches your deployment
-
Model Errors
- Verify the model name matches your deployment configuration
- Check that your prompt format is compatible with the deployed model
-
Rate Limiting
- SAP AI Core may have rate limits – implement appropriate delays between requests
- Monitor your usage in SAP AI Launchpad
Error Codes
- 401: Authentication failed – check credentials
- 403: Insufficient permissions – verify resource group access
- 404: Deployment not found – check deployment ID
- 429: Rate limit exceeded – reduce request frequency
- 500: Internal server error – check SAP AI Core service status
Development
To contribute to this project:
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests:
npm test - Submit a pull request
Build Commands
npm run build: Build the projectnpm run dev: Build in watch modenpm run lint: Run lintingnpm run format: Format code
License
This project is licensed under the MIT License. See the LICENSE file for details.
Support
For issues and questions:
- Check the troubleshooting section
- Review SAP AI Core documentation
- Open an issue on GitHub
- Contact the maintainers
Changelog
v1.0.0
- Initial release
- Support for text generation and chat completion
- OAuth2 authentication
- Basic error handling and configuration options