Skip to Content


In this blog i want to cover a little “hands on” how to enable an configure SAP Leonardo ML Foundation at your SAP Cloud Platform Acc. for the Cloud Foundry Environment.

Please haave also a look at Abdel DADOUCHE intro to his blog to ML series: Introducing “Project: Machine Learning in a Box”

For Details about the Features pls check the official docu here.

And the official SAP Cloud Platform Page for mor details e.g. pricing here.

I want talking here abut SAP Leonardo ML Foundation “production”, this is not available in the “trial” SCP Cloud Foundry Environment.

To get your hand´s dirty, you can try SAP Leonardo Ml Foundation for free at the SAP API Business Hub

In the Upcoming blogs we’ll cover futher topics like:

1 Getting started with SAP Leonard ML Foundation on SAP Cloud Platform Cloud Foundry (this blog)
2 Overview about the different API´s (planned*)
3 How to integratte the with e.g. SAP CP IoT (planned*)
4 How to retrain your existing model (planned*)
5 Bring your own model (created via ML on Google Cloud Platform (GCP)) (planned*)


* subject to changed

Enter the Cockpit

After we´ve successfully logged in to the “SAP Cloud Platform Cockpit” and select the correct region (in my case Europe (Frankfurt))  we enter our “Global Acc.”:

Enable the elastic plan

Afterwards lets verify the “elastic plan” by choosing the “Entitlements” entry:

And enable the standar plan:

Now we can use “hopefully” SAP Leonard ML Foundation in our space.

I just create therefore the following objects:

Object Name
Space ml
Quota Plan ml

An finally assign the “plan” to our “space”


Create the ml-foundation instance

Now we switch to our space and selecting in the service section the “Service Marketplace” entry.

We can now see there is now our “ml-foundation” service available:

As described in the SAP Help documentation we creating now the new “instance” and select the previous create plan:

Before we complete the creation process we enter a name of our instance:

Finally can now find our previously created instance:

Create a service key

Inside our instance we need now to create our service key to get our requeired data (credentilals / url´s)

In detail we got the following information which we need later to exute the different ML API´s:



name description
clientid OAuth client ID
appname App name
identityzone Name of your identity zone
identityzoneid Id of your identity zone
clientsecret OAuth client secret



Service Name URL
MODEL_REPO_URL https://<



URL: https://<SAP CP subdomain>


Prepare Postman

To access our API endpoints wen need as described here an acces token.

For this i´am using here the Postman Chrome plugin.

After we successfully launched Postman, we need to add an new environment:

Add now a new “Environment” by entering a name:

In the parameter (key, value) section we specify now the details which we got during the creation of the “Service Key”:

Key Value
clientid <clientid from the service key>
appname <appnamefrom the service key>
identityzone <identityzonefrom the service key>
identityzoneid <identityzoneidfrom the service key>
clientsecret <clientsecretfrom the service key>

Additional to these parmeters i just define another one to acces later my “tenant” in Postman via a variable.

Key Value
tenant_id <you tenant id = SAP CP subaccount name>


Request the token

To fetch now our token we create the follwoing GET request via Postman by using our “variable” which we create earlier:


Tip: To save our token directly in the used environment you can defne the following in the “Tests” section of Postman:

Important: The script which is defined in the official documentation did not work for me:

But if we use this modified script we can store the token in the right format:

"Bearer " + JSON.parse(responseBody).access_token);


If we recheck our environment, we can detect the successfully stored value for our “token”:

If we check this against the response body from our request, we can see the indetical token value:


Execute e.g. the “Image Classifier” API

As final step in this blog we want now test the Image Classifier API with the usage of our token and by executing the following URL via HTTP POST:


Header definition:

Important: Also at this point in the documentation i´ve found a litte error. The sample code is only valid for the usage by calling the API via the API Business Hub (APIKey):

For  the productive environment we need (Authorization):

Key Value
Accept application/json
tenantName {{tenant_id}}
Authorization {{token}}

Body definition:

Type Key Value
form-data files <file or archive>

We now provide an zip archive with the following images (pls check the docu about the allowed size and dormat):

Postman request definition:

And our response:

    "_id": "2dd79e88-db66-4f1e-7f60-f368be417314",
    "predictions": [
            "name": "2_and this.jpg",
            "results": [
                    "label": "drake",
                    "score": 0.8697558045387268
                    "label": "traffic light, traffic signal, stoplight",
                    "score": 0.0033478103578090668
                    "label": "American coot, marsh hen, mud hen, water hen, Fulica americana",
                    "score": 0.002334733260795474
                    "label": "lakeside, lakeshore",
                    "score": 0.002084329491481185
                    "label": "goose",
                    "score": 0.002050255425274372
            "name": "1_what is this.jpg",
            "results": [
                    "label": "chimpanzee, chimp, Pan troglodytes",
                    "score": 0.8176430463790894
                    "label": "siamang, Hylobates syndactylus, Symphalangus syndactylus",
                    "score": 0.013287714682519436
                    "label": "file, file cabinet, filing cabinet",
                    "score": 0.003327875630930066
                    "label": "orangutan, orang, orangutang, Pongo pygmaeus",
                    "score": 0.0030073353555053473
                    "label": "patas, hussar monkey, Erythrocebus patas",
                    "score": 0.0018851504428312182
    "processedTime": "2018-01-29T12:30:29.078824",
    "status": "DONE"



In this blog we have covered the initial step how to enable SAP Leonardo ML Foundation in the SAP CP Cloud Foundry Environment.

Futhermore we have verified our authetication credentials and finally sucessfully tested one of the availble API´s (here the Image Classification).

In one of the nex blogs we want cover how we can retrain our model and how to bring your own model (BYOM) in SAP Leonardo ML Foundation.






Helpful links:

SAP Help: SAP Leonardo ML Foundation

Chrome Postman Plugin

SAP API Business Hub

Official SAP Cloud Platform Page – SAP Leonardo ML Foundation



To report this post you need to login first.


You must be Logged on to comment or reply to a post.

  1. Sarabjeet Singh

    Hi Fabian,

    Thanks for sharing such valuable information in this blog, this is really helpful. But looks like ml-foundation is not available in trial accounts. I tried with my trial account but i couldn’t find any place from where i could add the ml-foundation. While creating the cloud foundry account it automatically assign the services from sap marketplace and there was no ml-foundation available. I searched the service marketplace as well. Appreciate if you can confirm if this service is only available for paid accounts or not and if its available in trial how to enable it. That would be helpful for most of the users here.

    Thank you.



    1. Hannah Vogt

      Hi Sarabjeet,

      Many thanks for your interest. We are currently working on getting a limited Trial Access on the way. The pretained, ready-to-use services can be tried out on the API Business Hub. For additional Information, you can also check out this blog.

      Best regards,


  2. Rainer Betrich

    Hi Fabian,


    great blog (as always) – without your valuable input I would have to spend days to get the right http headers (for using the ml subscriptions in CF), as this hasn’t been documented so far – so great input.

    Just one remark: Authentication type needs to be bearer :-).

    It was a pleasure to follow your blog and get an up an running sample.

    Have a nice day,



    1. Fabian Lehmann Post author

      Hi Rainer,


      yes of course the docu (sap help) can/must be improved it was also for me in the begging tricky…..but now all works.

      Oh and yes right it´s berarer……my mistake.





Leave a Reply