|
6 | 6 | - [Providing a Service Binding Locally](#providing-a-service-binding-locally) |
7 | 7 | - [Using the `AICORE_SERVICE_KEY` Environment Variable](#using-the-aicore_service_key-environment-variable) |
8 | 8 | - [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) |
9 | 10 |
|
10 | 11 |
|
11 | 12 | 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); |
152 | 153 | > The `destination` obtained from BTP destination service will expire once the contained OAuth2 token expires. |
153 | 154 | > Please run the above code for each request to ensure the destination is up-to-date. |
154 | 155 | > 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