# Changing Python version for an existing deployed model with the REST API  #

You can update an existing  Decision Optimization model using the  Watson Machine Learning REST API\. This can be useful, for example, if in your model you have explicitly specified a Python version that has now become deprecated\.

## Procedure ##

To change Python version for an existing deployed model:

<!-- <ol> -->

1.  Create a **revision to your  Decision Optimization model**
    
    All API requests require a version parameter that takes a date in the format `version=YYYY-MM-DD`. This code example posts a model that uses the file `update_model.json`. The URL will vary according to the chosen region/location for your machine learning service.
    
        curl --location --request POST \
          "https://us-south.ml.cloud.ibm.com/ml/v4/models/MODEL-ID-HERE/revisions?version=2021-12-01" \
          -H "Authorization: bearer TOKEN-HERE" \
          -H "Content-Type: application/json" \
          -d @revise_model.json
    
    The  revise\_model.json file contains the following code:
    
        {
          "commit_message": "Save current model",
          "space_id": "SPACE-ID-HERE"
        }
    
    Note the model revision number "`rev`" that is provided in the output for use in the next step.
2.  Update an existing deployment so that current jobs will not be impacted:
    
        curl --location --request PATCH \
          "https://us-south.ml.cloud.ibm.com/ml/v4/deployments/DEPLOYMENT-ID-HERE?version=2021-12-01&space_id=SPACE-ID-HERE" \
          -H "Authorization: bearer TOKEN-HERE" \
          -H "Content-Type: application/json" \
          -d @revise_deploy.json
    
    The  revise\_deploy.json file contains the following code:
    
        [
          {
          "op": "add",
          "path": "/asset",
          "value": {
            "id":"MODEL-ID-HERE",
            "rev":"MODEL-REVISION-NUMBER-HERE"
           }
          }
        ]
3.  Patch an existing model to explicitly specify Python version  3\.10
    
        curl --location --request PATCH \
          "https://us-south.ml.cloud.ibm.com/ml/v4/models/MODEL-ID-HERE?rev=MODEL-REVISION-NUMBER-HERE&version=2021-12-01&space_id=SPACE-ID-HERE" \
          -H "Authorization: bearer TOKEN-HERE" \
          -H "Content-Type: application/json" \
          -d @update_model.json
    
    The  update\_model.json file, with the default *Python version* stated explicitly, contains the following code:
    
        [
         {
         "op": "add",
         "path": "/custom",
         "value": {
           "decision_optimization":{
              "oaas.docplex.python": "3.10"
             }
           }
         }
        ]
    
    Alternatively, to remove any explicit mention of a Python version so that the default version will always be used:
    
        [
         {
         "op": "remove",
         "path": "/custom/decision_optimization"
         }
        ]
4.  Patch the deployment to use the model that was created for Python to use version  3\.10
    
        curl --location --request PATCH \
          "https://us-south.ml.cloud.ibm.com/ml/v4/deployments/DEPLOYMENT-ID-HERE?version=2021-12-01&space_id=SPACE-ID-HERE" \
          -H "Authorization: bearer TOKEN-HERE" \
          -H "Content-Type: application/json" \
          -d @update_deploy.json
    
    The  update\_deploy.json file contains the following code:
    
        [
         {
           "op": "add",
           "path": "/asset",
           "value": { "id":"MODEL-ID-HERE"}
         }
        ]

<!-- </ol> -->

<!-- </article "role="article" "> -->