Skip to Content

To continue the entire blog series about SAP Leonardo Foundation:

In this blog we want now coverin one of the interesting parts for me.


How to bring your own model up an running with SAP Leonardo ML Foundation.

In detail we will execute the following:

  • Adding a Tensorflow model to SAP Leonardo ML Foundation
  • Deploy the model
  • Create the python app an run it
    • a) local,
    • b) on cloud foundry


As documented here we need:

  • The Cloud Foundry CLI (link)
  • Important: The Postman “native” app (not the chrome plugin)
  • Python, version 2 >=2.7.9 or Python 3 >=3.4

Additional i’am using Docker to to run my “local” app in a container.


Download the Tensorflow Model Archive

The first thing is an Tensorflow as described in the docu, the model supports currently Tensorflow 1.3 (EU10).

Futhermore we expect that the model is exported in the “Saved_Model format”.

We are using here as well as in the official docu the Google inception model.

A suitable version which works u can get from here:


Add the model to the repository

Execute a new request with the “Postman” nativ application.

Path api/v1/models/sap_community_example/versions
HEADER Authorization (OAuth2 Access Token)

Body (form-data):



    "id": "<id>",
    "uploadDate": "16 Mar 2018 08:36:36 UTC",
    "modelStatus": "INACTIVE",
    "fileName": "",
    "metaData": null,
    "trainingInfo": null,
    "version": "5",
    "checkSum": null,
    "namespace": "<namespace>",
    "modelName": "sap_community_example"


Deploy your model

Next we deploy the model.

Path api/v1/deployments
HEADER Authorization (OAuth2 Access Token)

Body (JSON):

{"modelName": "sap_community_example"}


Check the deployment

Afterwards (after some minutes) we can check the deployment and get the required information.

Path api/v1/deployments
HEADER Authorization (OAuth2 Access Token)

Body (JSON):

            "id": "da776432-e468-4ce0-822d-d21dcc0ab559",
            "namespace": "8dd19b31-7dc5-4620-be78-8d5ebbfa5d61",
            "modelName": "sap_community_example",
            "modelVersion": "2",
            "placeholderName": "sap_community_example",
            "resourcePlan": "model-container-cpu-tfs",
            "deploymentStatus": {
                "state": "SUCCEEDED",
                "description": "Service [tfs-c74e4047-ef93-4b93-9b0e-2aa5a923d23e] is ready."
            "modelContainer": {
                "host": "<host>",
                "port": "80"
    "caCrt": "<certificate>",
    "last": true,
    "totalElements": 3,
    "totalPages": 1,
    "sort": null,
    "first": true,
    "numberOfElements": 3,
    "size": 10,
    "number": 0

We need now from the response the following data:

  • host
  • port
  • caCRT

Create the application and execute the API

A complete guide how to create the application is already documented in the SAP help.

Additional u can find it in my git repository

After we´ve build our app wen can run this by entering:


> docker run -p 5000:5000 sap_ml
* Running on (Press CTRL+C to quit)
 To verify if the API works, we can now execute create an new Postman request:


URL http://localhost:5000


Body (form-data):

file <e.g. a image from a cat or dog>




It looks like it works…..

Let´s provide now a “real” API endpoint on SCP Cloud Foundry.

This API can the e.g. used from other applications.

Push you application to SAP CP Cloud Foundry

First of all we need to creat the follwing structure (git link):

In difference to the local api before we have now a new file called:



web: python 

And the deployment descriptor where we need to define the application details:


- name: <you appname>
  host: <your app host>
  memory: 512M
  timeout: 30
  buildpack: python_buildpack
  MODEL_NAME: <model name>
  MODEL_SERVER_HOST: <deployed model host>
  ROOT_CERT: '<caCert>'

Afterwards we can now push this app to cf:

> cf push -f manifest.yml

looks fine after a minute or two:

And if we now recheck this app on the SCP CF cockpit, we see already a successfully started application:


The las step today is now to execute this API and we should get hopefully the same result:


Perfect… works ;o)




I think and hope u can see, the SAP Leonard ML Foundation BYOM functionality can be really easy.

For me ist was sometimes hard, because the docu was in the beginning not perfect.

In the meantime this has been improved (step by step) and hopefully this process should be continue to provide a central point of information for this kind of new fancy stuff ;o)

Comments and questions are welcome.







To report this post you need to login first.


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

  1. Poornapragna Malamandi Suresh

    Thanks for the detailed steps.


    I think small change is required when adding the model to repository:


    PATH is



    To be more precise, you can open the the MODEL_REPO_URL, that takes you to a swagger UI, which provides Model Versions Controller ,where we can directly create model version by providing the zip content comprising of .pb file and Access Token

  2. Poornapragna Malamandi Suresh


    When i execute cf push -f manifest.yml


    i am getting the following error


    Server error, status code: 400, error code: 310006, message: You have exceeded the total routes for your organization’s quota.


    I have a GLOBAL Account and if i check my ORG details i see in the result that quota variable assigned to a value SUBSCRITION_QUOTA


    Can you help me how to over come the above error during cf push?

  3. Former Member



    Process worked for me till step 14 of the BYOM guide.

    When deploying, am getting this error – please can you suggest on the process to onboard the tenant?




      "error": {
        "code": "ValidationError",
        "status": 400,
        "message": "Request is invalid.",
        "target": "/api/v2/deployments",
        "requestId": "4ef58f48-c63a-4e76-672a-06c20520bc54",
        "details": [
            "code": "ValidationError",
            "message": "Model deployment/undeployment can not happen while tenant xx-xx-xx-xx is not onboarded"


  4. René Kessler


    firstly I would like to thank you for your great work in this blog.


    I did the described steps myself and some errors occurred. I am able to upload my model (and also to update it). But when I try to deploy my model an error occur:

    "code": "AccessDenied",
            "status": 403,
            "message": "Access is denied",
            "target": "/api/v2/deployments/",


    My Post-Request: https://<myProductiveEnvironment>


    {“modelName”: “myModel”}


    Does anyone have a solution to my problem?

    1. Matthias A

      Hi René,


      I just started following this blog post and stumbled over the same issue as you. Unfortunately, I see no answers to this one yet.

      By chance, did you find any solution so far?


      Thanks & best regards



Leave a Reply