Skip to content

Commit c3fb6cc

Browse files
authored
Merge branch 'main' into fix-access-level-message-constructors
2 parents 35e3f4a + 0c7d768 commit c3fb6cc

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,19 @@ For SAP internal development, you can also use `SNAPSHOT` builds from the [inter
155155

156156
### _"How to add a custom header to AI Core requests?"_
157157

158-
Create a [HeaderProvider](https://sap.github.io/cloud-sdk/docs/java/features/connectivity/http-destinations#about-headerproviders).
158+
The AI SDK leverages the destination concept from the SAP Cloud SDK to manage the connection to AI Core.
159+
This opens up a wide range of possibilities to customize the connection, including adding custom headers.
159160

161+
```java
162+
var service = new AiCoreService();
163+
var service = service.withBaseDestination(
164+
DefaultHttpDestination.fromDestination(service.getBaseDestination())
165+
.header("my-header-key", "my-header-value")
166+
.build()
167+
);
168+
```
169+
170+
For more information, please refer to the [AI Core connectivity guide](./docs/guides/CONNECTING_TO_AICORE.md) and the [SAP Cloud SDK documentation](https://sap.github.io/cloud-sdk/docs/java/features/connectivity/http-destinations).
160171

161172
### _"There's a vulnerability warning `CVE-2021-41251`?"_
162173

docs/guides/CONNECTING_TO_AICORE.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- [Providing a Service Binding Locally](#providing-a-service-binding-locally)
77
- [Using the `AICORE_SERVICE_KEY` Environment Variable](#using-the-aicore_service_key-environment-variable)
88
- [Using a Destination from the BTP Destination Service](#using-a-destination-from-the-btp-destination-service)
9+
- [Creating a Custom Destination](#creating-a-custom-destination)
910

1011

1112
The AI SDK uses the [`Destination` concept of the SAP Cloud SDK](https://sap.github.io/cloud-sdk/docs/java/features/connectivity/destination-service) to connect to AI Core.
@@ -152,4 +153,23 @@ new DeploymentApi(aiCoreService);
152153
> The `destination` obtained from BTP destination service will expire once the contained OAuth2 token expires.
153154
> Please run the above code for each request to ensure the destination is up-to-date.
154155
> Destinations are cached by default, so this does not come with a performance penalty.
155-
> To learn more, see the [SAP Cloud SDK documentation](https://sap.github.io/cloud-sdk/docs/java/features/connectivity/destination-service).
156+
> To learn more, see the [SAP Cloud SDK documentation](https://sap.github.io/cloud-sdk/docs/java/features/connectivity/destination-service).
157+
158+
## Creating a Custom Destination
159+
160+
If the above options are not suitable for your use case (e.g. because you are obtaining the credentials in a completely different way), you can also use a custom-built destination:
161+
162+
```java
163+
var destination = OAuth2DestinationBuilder
164+
.forTargetUrl("https://<ai-api-url>")
165+
.withTokenEndpoint("https://<xsuaa-url>/oauth/token")
166+
.withClient(new ClientCertificate("<cert>", "<key>", "<clientid>"), OnBehalfOf.TECHNICAL_USER_PROVIDER)
167+
.build();
168+
169+
AiCoreService aiCoreService = new AiCoreService().withBaseDestination(destination);
170+
```
171+
172+
The above example assumes you are using a client certificate for authentication and have stored the relevant credentials somewhere.
173+
You are free to use X509 certificates (also via the Zero Trust Identity Service) or a client secret.
174+
175+
For more details, refer to the [SAP Cloud SDK documentation](https://sap.github.io/cloud-sdk/docs/java/features/connectivity/destination-service).

0 commit comments

Comments
 (0)