# ai-sdk-java **Repository Path**: mirrors_SAP/ai-sdk-java ## Basic Information - **Project Name**: ai-sdk-java - **Description**: Integrate chat completion into your business applications with SAP Cloud SDK for AI. Leverage the Generative AI Hub of SAP AI Core to make use of templating, grounding, data masking, content filtering and more. Access all features of SAP AI Core with the SAP Cloud SDK for AI - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-08-14 - **Last Updated**: 2026-01-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ![build](https://github.com/SAP/ai-sdk-java/actions/workflows/continuous-integration.yaml/badge.svg?branch=main) ![CodeQL](https://github.com/SAP/ai-sdk-java/actions/workflows/github-code-scanning/codeql/badge.svg) [![REUSE status](https://api.reuse.software/badge/git.fsfe.org/reuse/api)](https://api.reuse.software/info/git.fsfe.org/reuse/api) [![Fosstars security rating](https://github.com/SAP/ai-sdk-java/actions/workflows/fosstars-report.yml/badge.svg?branch=main)](https://github.com/SAP/ai-sdk-java/blob/fosstars-report/fosstars_report.md) [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/SAP/ai-sdk-java) # SAP Cloud SDK SAP Cloud SDK for AI (for Java) **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. ## Table of Contents - [General Requirements](#general-requirements) - [Getting Started](#getting-started) - [What You'll Build](#what-youll-build) - [Prerequisites](#prerequisites) - [Use the Orchestration API](#use-the-orchestration-api) - [Run the Application Locally](#run-the-application-locally) - [Explore Further Capabilities](#explore-further-capabilities) - [Documentation](#documentation) - [Build the Project](#build-the-project) - [FAQs](#faqs) - [Contribute, Support and Feedback](#contribute-support-and-feedback) - [Security / Disclosure](#security--disclosure) - [Code of Conduct](#code-of-conduct) - [Licensing](#licensing) ## General Requirements #### Development Environment These are required on the developer side to build and run applications with the SDK: * **Java JDK**: 17 or higher (21 LTS recommended). * **SAP Cloud SDK**: 5.6.0 or later (latest recommended, added as a Maven dependency). #### SAP AI Core Service instance To make of use the services supported by the SDK, you need to have access to an SAP AI Core Service instance. Checkout [how to connect](https://sap.github.io/ai-sdk/docs/java/guides/connecting-to-ai-core). #### Optional Integrations The SDK can be combined with popular Java frameworks. These are not required for core functionality, but version compatibility is listed for reference: * **Spring AI** ≥ 1.0.0 * **Spring Boot** ≥ 3.0 * **CAP Java** ≥ 3.0.0 👉 See an [example `pom.xml`](sample-code/spring-app/pom.xml) in our sample Spring Boot application. > [!WARNING] > All classes under any of the `...model` packages are generated from an OpenAPI specification and marked as `@Beta`. > This means that these model classes are not guaranteed to be stable and may change with future releases. > They are safe to use, but may require updates even in minor releases. ## Getting Started ### What You'll Build In this quickstart, you'll use the OpenAI GPT-4o model through the [Orchestration Service of AI Core](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/orchestration) for generating text. The application will send a prompt to the AI model and display the generated response. ### Prerequisites 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](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/create-deployment-for-orchestration) on how to create one. ### Add the SDK as a Dependency Add the following dependency to your `pom.xml` file: ```xml com.sap.ai.sdk orchestration ${ai-sdk.version} ``` ### Use the Orchestration API We'll use a `client` to interact with the Orchestration service: ```java var client = new OrchestrationClient(); ``` Next, we'll specify the model we want to use: ```java var config = new OrchestrationModuleConfig() .withLlmConfig(OrchestrationAiModel.GPT_4O); ``` Now we can create our first prompt: ```java 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. ### Run the Application Locally 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. ```shell 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](https://sap.github.io/ai-sdk/docs/java/guides/connecting-to-ai-core#using-the-aicore_service_key-environment-variable). ### Explore Further Capabilities 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](https://sap.github.io/ai-sdk/docs/java/guides/orchestration-chat-completion) for more information. ## Documentation For more detailed information and advanced usage, please refer to the following: - [ Connecting to AI Core](https://sap.github.io/ai-sdk/docs/java/guides/connecting-to-ai-core) - [ Orchestration Chat Completion](https://sap.github.io/ai-sdk/docs/java/guides/orchestration-chat-completion) - [ OpenAI Chat Completion](https://sap.github.io/ai-sdk/docs/java/guides/openai-chat-completion) - [ Spring AI Integration](https://sap.github.io/ai-sdk/docs/java/guides/spring-ai-integration) - [🧰 AI Core Deployment](https://sap.github.io/ai-sdk/docs/java/guides/ai-core-deployment) - [ AI Core Grounding](https://sap.github.io/ai-sdk/docs/java/guides/document-grounding) For updating versions, please refer to the [**Release Notes**](https://sap.github.io/ai-sdk/docs/java/release-notes). ## Build the Project You can build the project using Maven: ```shell mvn clean install -DskipTests ``` This will install the current `SNAPSHOT` version of the project into your local Maven repository. For SAP internal development, you can also use `SNAPSHOT` builds from the [internal](https://int.repositories.cloud.sap/ui/repos/tree/General/proxy-build-snapshots-cloudsdk/com/sap/ai/sdk) and [internet-facing](https://common.repositories.cloud.sap/artifactory/build-snapshots-cloudsdk/com/sap/ai/sdk/) Artifactory. ## FAQs ### _"How to add a custom header to AI Core requests?"_ The AI SDK leverages the destination concept from the SAP Cloud SDK to manage the connection to AI Core. This opens up a wide range of possibilities to customize the connection, including adding custom headers. The following shows how to add custom headers to all requests sent to AI Core. ```java var service = new AiCoreService(); var destination = DefaultHttpDestination.fromDestination(service.getBaseDestination()) .header("my-header-key", "my-header-value") .build(); // AI Core client service = service.withBaseDestination(destination); DeploymentApi client = new DeploymentApi(service); ``` For more information, please refer to the [AI Core connectivity guide](https://sap.github.io/ai-sdk/docs/java/guides/connecting-to-ai-core) and the [SAP Cloud SDK documentation](https://sap.github.io/cloud-sdk/docs/java/features/connectivity/http-destinations). There is also a convenient method to add custom headers to single calls through the Orchestration or OpenAI client. ```java var client = new OrchestrationClient(); var result = client.withHeader("my-header-key", "my-header-value").chatCompletion(prompt, config); ``` For more information on this feature, see the respective documentation of the [OrchestrationClient](https://sap.github.io/ai-sdk/docs/java/orchestration/chat-completion#custom-headers) and [OpenAIClient](https://sap.github.io/ai-sdk/docs/java/foundation-models/openai/chat-completion#custom-headers). ### _"There's a vulnerability warning `CVE-2021-41251`?"_ 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](https://github.com/SAP/ai-sdk-java/blob/main/.pipeline/dependency-check-suppression.xml). ### _"Are there any example projects?"_ Explore example applications and code snippets: - [Spring Boot Application Example](sample-code/spring-app) ## Contribute, Support and Feedback This project is open to feature requests/suggestions, bug reports etc. via [GitHub issues](https://github.com/SAP/ai-sdk-java/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](CONTRIBUTING.md). ## Security / Disclosure If you find any bug that may be a security problem, please follow our instructions at [in our security policy](https://github.com/SAP/ai-sdk-java/security/policy) on how to report it. Please do not create GitHub issues for security-related doubts or problems. ## Code of Conduct 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](https://github.com/SAP/.github/blob/main/CODE_OF_CONDUCT.md) at all times. ## Licensing Copyright 2024 SAP SE or an SAP affiliate company and ai-sdk-java contributors. Please see our [LICENSE](LICENSE) for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available [via the REUSE tool](https://api.reuse.software/info/github.com/SAP/ai-sdk-java).