Skip to Content

Getting started with SAP Leonard ML Foundation on SAP Cloud Platform Cloud Foundry


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:


* 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



You must be Logged on to comment or reply to a post.
  • 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.



    • 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,


  • Hi Former Member,

    i thought with this one, its clear we´re talking about the "productive" usage:


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

    But anyway i can put this info in this blog.




  • 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,



    • 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 mistake.




  • Hi Fabian,

    Thank you for the wonderful blog series. This is exactly what I wanted to get started in Leonardo ML in CF.

    I have tried SAP Canary CF instance for this, for which the image classification URL becomes :

    I was able to generate the access token from the above mentioned method. But, when I POST image content with the required header values, I receive below error :

    Unable to authorize the request.: Error code 401: Invalid scope: ['ml-foundation-xsuaa-std!b313.functionalservice.all'] 

    I'm not sure why it would look for standard scope when I'm actually looking at internal scope. The response I received while generating access token had one of scope values as 'ml-foundation-xsuaa-int!b313.functionalservice.all' .  My best guess is that the issue is with scope. I am trying internal whereas the scope verified is standard. Is this actually possible in internal scope ?Any pointers on how to change scope and resolve this issue ?

    Thank you & Regards,


    • Hi Former Member,

      i think you should rise 1st of all an ticket.

      Do u have check the sap cp cf "application role builder"?

      For me the following scopes are defined:



      • Hello,


        I also ran into this issue. I get a token from Auth URL with scope parameter set to foundation-int-ml… etc, but the error message is related to std scope:


        “error”: {
        “code”: “401”,
        “message”: “Unable to authorize the request.: Error code 401: Invalid scope: [‘foundation-std-mlfpreproduction!b164.functionalservice.all’]”,
        “requestId”: “1b8c6ebb-c2df-44af-50e5-d6d86da9c352”


        I’m also internal user. Could it be the issue?

        How can ticket be submitted?




        • Hi Konstantin,


          you can rise a ticket via:

          As component u can use: CA-ML-PLT


          best regards,


      • Just tried this alternative and it works for me:

        To the Token Generation URL, also add the parameter scope with available values for your tenant.  Now I got a token that is accepted by SWAGGER for making read calls.

        "scope": "ml-foundation-xsuaa-std! ml-foundation-xsuaa-std!b540.datamanagement.write ml-foundation-xsuaa-std!b540.functionalservice.all ml-foundation-xsuaa-std!b540.inference ml-foundation-xsuaa-std!b540.modeldeployment.all ml-foundation-xsuaa-std! ml-foundation-xsuaa-std! ml-foundation-xsuaa-std!b540.modelrepo.write ml-foundation-xsuaa-std! ml-foundation-xsuaa-std! ml-foundation-xsuaa-std!b540.retrainservice.write ml-foundation-xsuaa-std!b540.storageapi.all uaa.resource",

  • Hello Fabian,

    Looks like I cannot enable the cloud foundry as creation of the organization fails. I also do not see if I can see any global accounts available that I can use.

    Can we get accounts so that we can try out the tutorial?



    • Hi Jude,


      as mentioned in the blog:

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

      Do u have a subscription to SAP Leonardo ML Foundation?

      If yes u should get an "welcome mail" with the details.

      Futhermore u need SAP CP Cf "Global Acc." as well (no trial).





  • Hi Fabian,

    Really great blog, thanks for that.

    I went through it step by step, but in the request of the image classification I get 401 response with this message:

    "Unable to authorize the request.: Error('Incorrect padding',)"

    Any idea what have I done wrong?


      • So the problem was because the ZIP file contained 2 images.

        When I used a ZIP with only one file I also got an error, this time 400.

        This was because I used Mac OS compression method. When I compressed the file via the terminal it was successful.


        • Hi In windows , when i tried to add the images in ZIP. it says

          "error": {
          "code": "400",
          "message": "Invalid request: This service requires at least 1 file. Please put your file(s) into the `files` field of the POST request",
          "requestId": "2dc18a26-7ccb-4720-42ac-64e0d24f095e"

          Even if i add images directly in file and and files in zip.

          • Hi All,


            I am also getting the same error in Window :


            "error": {
            "code": "401",
            "message": "Unable to authorize the request.: Token error: Access token was not prefixed with token type: Bearer",
            "requestId": "76ffd57c-3737-4d61-7f0f-d0cd62a2fe66"


            Any resolution to this ?

            I am doing below steps

            1. Set to Post
            2. Paste the Image Classifier URL and click on Send button
  • I am also getting the same error in Window :


    “error”: {
    “code”: “401”,
    “message”: “Unable to authorize the request.: Token error: Access token was not prefixed with token type: Bearer”,
    “requestId”: “76ffd57c-3737-4d61-7f0f-d0cd62a2fe66”


    Any resolution to this ?

    I am doing below steps

    1. Set to Post
    2. Paste the Image Classifier URL and click on Send button
  • Hi All,


    On the step of image classifier api path, what is the path ?? I am abe to connect the access token via postman,

    can anyone provide me the API path

  • Hello All,


    Even I got this error.

    “error”: {
    “code”: “401”,
    “message”: “Unable to authorize the request.: Token error: Access token was not prefixed with token type: Bearer”,
    “requestId”: “76ffd57c-3737-4d61-7f0f-d0cd62a2fe66”


    Solved by providing below two key values in Headers

    Authorization : Bearer <access token generated>




    provided key as files and values as the attachment  and selected form-data as data type in body








  • Hi Community,

    you may have issues to request the token as I did.
    I would recommend you guys to have a look at the latest tutorial from the SAP Hana Academy.

    I hope I was able to help your headache. 🙂

    "Leonardo ML Foundation: Inference - Image Classification"

  • Dear expert .


    I am able to connect my ML to swagger and test it , which is working perfect.

    But when it comes to postman - it gives me error as " Invalid file format" tho everything ( image) is same . but when I am trying to use via post man is it not working .


    Can you tell me which one to use ??

    I have build my account - activated the service and follow this blog completely and things are working fine now .


    I want to know weather we really need to use postman ? or not ? or swagger will be sufficient ?

    What I understand is we use postman to get the token ( Oauth2) and we use this in Swagger .  ?? Is it correct??


    Thanks and regards,