SAP Cloud SDK for AI is the official Software Development Kit (SDK) for SAP AI Core, SAP Generative AI Hub, and Orchestration Service.
This SDK enables developers to seamlessly integrate AI capabilities, such as chat completion, into their Java-based business applications using SAP's Generative AI Hub. Leverage powerful features like templating, grounding, data masking, and content filtering to build intelligent applications. The SDK simplifies the setup and interaction with SAP AI Core, allowing you to focus on delivering value through AI integration.
- General Requirements
- Getting Started
- Documentation
- FAQs
- Contribute, Support and Feedback
- Security / Disclosure
- Code of Conduct
- Licensing
To use the SDK in a Java application, it is necessary to understand the technical prerequisites and required versions for common dependencies.
- Java 17 or higher.
- Access to an SAP AI Core Service instance.
Please refer to this documentation on how to connect the SDK to AI Core.
The following table lists the required versions, based on the latest release:
Dependency | Minimum Version | Recommended Version |
---|---|---|
JDK | 17 (LTS) | 21 (LTS) |
SAP Cloud SDK | 5.6.0 | latest |
(optional) CAP Java | 3.0.0 | latest |
(optional) Spring Boot | 3.0 | latest |
See an example pom.xml
in our Spring Boot application.
In this quickstart, you'll use the OpenAI GPT-4o model through the Orchestration Service of AI Core for generating text. The application will send a prompt to the AI model and display the generated response.
This quickstart assumes you have a deployment of the Orchestration service available in the default
resource group of your AI Core instance.
If you don't have a deployment yet, please refer to this guide on how to create one.
Add the following dependency to your pom.xml
file:
<dependency>
<groupId>com.sap.ai.sdk</groupId>
<artifactId>orchestration</artifactId>
<!-- Use the latest version here -->
<version>${ai-sdk.version}</version>
</dependency>
We'll use a client
to interact with the Orchestration service:
var client = new OrchestrationClient();
Next, we'll specify the model we want to use:
var config = new OrchestrationModuleConfig()
.withLlmConfig(OrchestrationAiModel.GPT_4O);
Now we can create our first prompt:
var prompt = new OrchestrationPrompt("Hello world! Why is this phrase so famous?");
var result = client.chatCompletion(prompt, config).getContent();
The result will be the text generated by the AI model.
In order to run the application locally, you need to provide credentials for your AI Core service instance.
For this example we'll use a service key and pass it as an environment variable to the application.
cd your-spring-app/
# assuming a bash, for other shells (e.g. PowerShell) see the below documentation
export AICORE_SERVICE_KEY='{ "clientid": "...", "clientsecret": "...", "url": "...", "serviceurls": { "AI_API_URL": "..." } }'
# assuming Maven and a Spring Boot application
mvn spring-boot:run
Please find detailed instructions and more examples in this documentation.
Check out the options available for the OrchestrationPrompt
and OrchestrationModuleConfig
classes.
You can use templating, content filtering, data masking and more.
Please refer to this documentation for more information.
For more detailed information and advanced usage, please refer to the following:
Create a HeaderProvider.
This is a known false-positive finding. Depending on the tooling any product called "SAP Cloud SDK" or similar with a low version number may be marked as vulnerable, incorrectly. Please consider suppressing the warning, as we do.
Explore example applications and code snippets:
This project is open to feature requests/suggestions, bug reports etc. via GitHub issues. Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our Contribution Guidelines.
If you find any bug that may be a security problem, please follow our instructions at in our security policy on how to report it. Please do not create GitHub issues for security-related doubts or problems.
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone. By participating in this project, you agree to abide by its Code of Conduct at all times.
Copyright 2024 SAP SE or an SAP affiliate company and ai-sdk-java contributors. Please see our LICENSE for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available via the REUSE tool.