> ## Documentation Index
> Fetch the complete documentation index at: https://lago-ftr-wallet-improvements.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Update a plan

> This endpoint updates a specific plan with subscription and usage-based charges. It supports flexible billing cadence (in-advance or in-arrears) and allows for both recurring and metered charges.

<RequestExample>
  ```bash cURL
  LAGO_URL="https://api.getlago.com"
  API_KEY="__YOUR_API_KEY__"

  curl --location --request PUT "$LAGO_URL/api/v1/plans/__plan_code__" \
  --header "Authorization: Bearer $API_KEY" \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "plan": {
      "name": "Startup Premium",
      "code": "startup",
      "interval": "monthly",
      "description": null,
      "amount_cents": 1000,
      "amount_currency": "USD",
      "trial_period": 10,
      "pay_in_advance": true,
      "bill_charges_monthly": null,
      "tax_codes": ["french_standard_vat"],
      "invoice_display_name": "",
      "minimum_commitment": {
        "amount_cents": 100000,
        "invoice_display_name": "Minimum Commitment (C1)",
        "taxes": []
      },
      "charges": [
        {
          "id": "__CHARGE_ID__",
          "billable_metric_id": "__BILLABLE_METRIC_ID__",
          "charge_model": "graduated",
          "invoiceable": true,
          "pay_in_advance": false,
          "prorated": false,
          "min_amount_cents": 0,
          "invoice_display_name": "My new charge display name",
          "properties": {
            "graduated_ranges": [
              {
                "from_value": 0,
                "to_value": 10000,
                "per_unit_amount": "0.02",
                "flat_amount": "50"
              },
              {
                "from_value": 10001,
                "to_value": null,
                "per_unit_amount": "0.01",
                "flat_amount": "100"
              }
            ]
          },
          "tax_codes": []
        },
        {
          "id": "__CHARGE_ID__",
          "billable_metric_id": "__BILLABLE_METRIC_ID__",
          "charge_model": "package",
          "invoiceable": true,
          "pay_in_advance": false,
          "prorated": false,
          "min_amount_cents": 0,
          "invoice_display_name": "",
          "properties": {
            "amount": "30",
            "free_units": 1000,
            "package_size": 10000
          },
          "tax_codes": []
        },
        {
          "id": "__CHARGE_ID__",
          "billable_metric_id": "__BILLABLE_METRIC_ID__",
          "charge_model": "percentage",
          "invoiceable": true,
          "pay_in_advance": false,
          "prorated": false,
          "min_amount_cents": 0,
          "invoice_display_name": "",
          "properties": {
            "rate": "0.15",
            "fixed_amount": "0.5",
            "free_units_per_events": 5,
            "free_units_per_total_aggregation": "500",
            "per_transaction_min_amount": "1.75",
            "per_transaction_max_amount": "2"
          },
          "tax_codes": []
        },
        {
          "id": "__CHARGE_ID__",
          "billable_metric_id": "__BILLABLE_METRIC_ID__",
          "charge_model": "standard",
          "invoiceable": true,
          "pay_in_advance": false,
          "prorated": false,
          "min_amount_cents": 0,
          "invoice_display_name": "",
          "properties": {
            "amount": "10"
          },
          "tax_codes": []
        },
        {
          "id": "__CHARGE_ID__",
          "billable_metric_id": "__BILLABLE_METRIC_ID__",
          "charge_model": "volume",
          "invoiceable": true,
          "pay_in_advance": false,
          "prorated": false,
          "min_amount_cents": 0,
          "invoice_display_name": "",
          "properties": {
            "volume_ranges": [
              {
                "from_value": 0,
                "to_value": 1000,
                "per_unit_amount": "0.75",
                "flat_amount": "0"
              },
              {
                "from_value": 1001,
                "to_value": null,
                "per_unit_amount": "0.50",
                "flat_amount": "0"
              }
            ]
          },
          "tax_codes": []
        },
        {
          "id": "__CHARGE_ID__",
          "billable_metric_id": "__BILLABLE_METRIC_ID__",
          "charge_model": "graduated",
          "invoiceable": true,
          "pay_in_advance": false,
          "prorated": false,
          "min_amount_cents": 0,
          "properties": {
            "graduated_ranges": [
              {
                "from_value": 0,
                "to_value": null,
                "per_unit_amount": "0",
                "flat_amount": "0"
              }
            ]
          },
          "filters": [
            {
              "values": {
                "cloud": ["aws"],
                "region": ["us-east-1"]
              },
              "properties": {
                "graduated_ranges": [
                  {
                    "from_value": 0,
                    "to_value": 20000,
                    "per_unit_amount": "0.02",
                    "flat_amount": "50"
                  },
                  {
                    "from_value": 20001,
                    "to_value": null,
                    "per_unit_amount": "0.01",
                    "flat_amount": "100"
                  }
                ]
              }
            }
          ],
          "tax_codes": []
        },
        {
          "id": "__CHARGE_ID__",
          "billable_metric_id": "__BILLABLE_METRIC_ID__",
          "charge_model": "package",
          "invoiceable": true,
          "pay_in_advance": false,
          "prorated": false,
          "min_amount_cents": 0,
          "properties": {
            "amount": "0",
            "free_units": 0,
            "package_size": 1
          },
          "filters": [
            {
              "values": {
                "cloud": ["aws"],
                "region": ["us-east-1"]
              },
              "properties": {
                "amount": "30",
                "free_units": 1000,
                "package_size": 10000
              }
            }
          ],
          "tax_codes": []
        },
        {
          "id": "__CHARGE_ID__",
          "billable_metric_id": "__BILLABLE_METRIC_ID__",
          "charge_model": "percentage",
          "invoiceable": true,
          "pay_in_advance": false,
          "prorated": false,
          "min_amount_cents": 0,
          "properties": {
            "rate": "0"
          },
          "filters": [
            {
              "values": {
                "cloud": ["aws"],
                "region": ["us-east-1"]
              },
              "properties": {
                "rate": "0.15",
                "fixed_amount": "0.5",
                "free_units_per_events": 5,
                "free_units_per_total_aggregation": "500",
                "per_transaction_min_amount": "1.75",
                "per_transaction_max_amount": "2"
              }
            }
          ],
          "tax_codes": []
        },
        {
          "id": "__CHARGE_ID__",
          "billable_metric_id": "__BILLABLE_METRIC_ID__",
          "charge_model": "standard",
          "invoiceable": true,
          "pay_in_advance": false,
          "prorated": false,
          "min_amount_cents": 0,
          "properties": {
            "amount": "0"
          },
          "filters": [
            {
              "values": {
                "cloud": ["aws"],
                "region": ["us-east-1"]
              },
              "properties": {
                "amount": "15"
              }
            }
          ],
          "tax_codes": []
        },
        {
          "id": "__CHARGE_ID__",
          "billable_metric_id": "__BILLABLE_METRIC_ID__",
          "charge_model": "volume",
          "invoiceable": true,
          "pay_in_advance": false,
          "prorated": false,
          "min_amount_cents": 0,
          "properties": {
            "volume_ranges": [
              {
                "from_value": 0,
                "to_value": null,
                "per_unit_amount": "0",
                "flat_amount": "0"
              }
            ]
          },
          "filters": [
            {
              "values": {
                "cloud": ["aws"],
                "region": ["us-east-1"]
              },
              "properties": {
                "volume_ranges": [
                  {
                    "from_value": 0,
                    "to_value": 2000,
                    "per_unit_amount": "0.75",
                    "flat_amount": "0"
                  },
                  {
                    "from_value": 2001,
                    "to_value": null,
                    "per_unit_amount": "0.50",
                    "flat_amount": "0"
                  }
                ]
              }
            }
          ],
          "tax_codes": []
        }
      ]
    }
  }
  '
  ```

  ```python Python
  from lago_python_client.client import Client
  from lago_python_client.exceptions import LagoApiError
  from lago_python_client.models import Plan, Charges, Charge

  client = Client(api_key='__YOUR_API_KEY__')

  standard_charge = Charge(
    id='id',
    billable_metric_id='id',
    charge_model='standard',
    prorated=true,
    filters=[
      {
        values={
          cloud=["aws",]
          region:=["us-east-1"]
        },
        properties={
          'amount': '0.22'
        }
      }
    ]
  )

  graduated_charge = Charge(
    id='id',
    billable_metric_id='id,
    charge_model='graduated',
    prorated=false,
    invoice_display_name= 'My new charge display name',
    properties=[
      {
        'from_value': 0,
        'to_value': 10,
        'flat_amount': '0',
        'per_unit_amount': '0.00010'
      },
      {
        'from_value': 11,
        'to_value': None,
        'flat_amount': "0",
        'per_unit_amount': '0.0005'
      }
    ]
  )

  package_charge = Charge(
    id='id',
    billable_metric_id='id,
    charge_model='package',
    prorated=false,
    invoice_display_name= '',
    properties={
      'amount': '100',
      'free_units': 10000,
      'package_size': 1000
    }
  )

  percentage_charge = Charge(
    id='id',
    billable_metric_id='id,
    charge_model='percentage',
    prorated=false,
    invoice_display_name= '',
    properties={
      'rate': '0.5',
      'fixed_amount': '1',
      'free_units_per_events': 3,
      'free_units_per_total_aggregation': None,
      'per_transaction_min_amount': '1.75',
      'per_transaction_max_amount': '2'
    }
  )

  volume_charge = Charge(
    id='id',
    billable_metric_id='id,
    charge_model='volume',
    prorated=true,
    invoice_display_name= '',
    properties={
      'volume_ranges': [
        {
          'to_value': 10,
          'from_value': 0,
          'flat_amount': '0',
          'per_unit_amount': '0.00010'
        },
        {
          'to_value': None,
          'from_value': 11,
          'flat_amount': '0',
          'per_unit_amount': '0.0005'
        }
      ]
    }
  )

  graduated_percentage_charge = Charge(
    id='id',
    billable_metric_id='id,
    charge_model='graduated_percentage',
    prorated=true,
    invoice_display_name= '',
    properties={
      'graduated_percentage_ranges': [
        {
          "rate": "1",
          "from_value": 0,
          "to_value": 1000,
          "flat_amount": "200"
        },
        {
          "rate": "2",
          "from_value": 1001,
          "to_value": 10000,
          "flat_amount": "300"
        },
        {
          "rate": "3",
          "from_value": 10001,
          "to_value": null,
          "flat_amount": "400"
        }
      ]
    }
  )

  charges = Charges(__root__=[
    standard_charge,
    graduated_charge,
    package_charge,
    percentage_charge,
    volume_charge,
    graduated_percentage_charge
  ])

  plan = Plan(
    name='name',
    code='code_first',
    amount_cents=1000,
    amount_currency='EUR',
    description='desc',
    interval='weekly',
    pay_in_advance=True,
    invoice_display_name= '',
    charges=charges
  )

  try:
      client.plans.update(plan, "__identifier__")
  except LagoApiError as e:
      repair_broken_state(e)  # do something on error or raise your own exception
  ```

  ```ruby Ruby
  require 'lago-ruby-client'

  client = Lago::Api::Client.new({api_key: '__YOUR_API_KEY__'})

  plan = {
    name: 'plan name',
    code: 'code',
    interval: 'monthly',
    description: 'description',
    amount_cents: 100,
    amount_currency: 'EUR',
    pay_in_advance: false,
    prorated: false,
    invoice_display_name: '',
    charges: charges: [
      {
        id: 'id',
        billable_metric_id: 'id',
        charge_model: 'standard',
        invoice_display_name: 'My new charge display name',
        filters: [
          {
            values: {
              cloud: ["aws"],
              region: ["us-east-1"]
            },
            properties: {
              amount: '0.10'
            }
          }
        ]
      },
      {
        id: 'id',
        billable_metric_id: 'id',
        charge_model: 'graduated',
        prorated: false,
        invoice_display_name: '',
        properties: [
          {
            to_value: 10,
            from_value: 0,
            flat_amount: '0',
            per_unit_amount: '0.00010'
          },
          {
            to_value: nil,
            from_value: 11,
            flat_amount: '0',
            per_unit_amount: '0.0005'
          }
        ]
      },
      {
        id: 'id',
        billable_metric_id: 'id',
        charge_model: 'package',
        prorated: false,
        invoice_display_name: '',
        properties: {
          amount: '100',
          free_units: 10000,
          package_size: 1000
        }
      },
      {
        id: 'id',
        billable_metric_id: 'id',
        charge_model: 'percentage',
        prorated: false,
        invoice_display_name: '',
        properties: {
          rate: '0.5',
          fixed_amount: '1',
          free_units_per_events: 3,
          free_units_per_total_aggregation: nil,
          per_transaction_min_amount: '1.75',
          per_transaction_max_amount: '2'
        }
      },
      {
        id: 'id',
        billable_metric_id: 'id',
        charge_model: 'volume',
        prorated: true,
        invoice_display_name: '',
        properties: {
          volume_ranges: [
            {
              from_value: 0,
              to_value: 10,
              flat_amount: '0',
              per_unit_amount: '0.00010'
            },
            {
              from_value: 11,
              to_value: nil,
              flat_amount: '0',
              per_unit_amount: '0.0005'
            }
          ]
        }
      },
      {
        id: 'id',
        billable_metric_id: 'id',
        charge_model: 'graduated_percentage',
        prorated: false,
        invoice_display_name: '',
        properties: {
          graduated_percentage_ranges: [
            {
              "rate": "1",
              "from_value": 0,
              "to_value": 1000,
              "flat_amount": "200"
            },
            {
              "rate": "2",
              "from_value": 1001,
              "to_value": 10000,
              "flat_amount": "300"
            },
            {
              "rate": "3",
              "from_value": 10001,
              "to_value": null,
              "flat_amount": "400"
            }
          ]
        }
      }
    ]
  }

  client.plans.update(plan, "__identifier__")
  ```

  ```js Javascript
  await client.plans.updatePlan("code", { plan: { amount_cents: 2000 } });
  ```

  ```go Go
  import "fmt"
  import "github.com/getlago/lago-go-client"

  func main() {
  lagoClient := lago.New().
      SetApiKey("__YOUR_API_KEY__")

  planInput := &lago.PlanInput{
      Name:           "Plan Go",
      Code:           "plan_go",
      Interval:       lago.PlanMonthly,
      PayInAdvance:   true,
      AmountCents:    1500,
      InvoiceDisplayName: "",
      AmountCurrency: lago.EUR,
  }

  planResult, err := lagoClient.Plan().Update(planInput)
  if err != nil {
      // Error is *lago.Error
      panic(err)
  }

  // plan is *lago.Plan
  fmt.Println(plan)
  }
  ```

  ```csharp C#
  using System.Collections.Generic;
  using System.Diagnostics;
  using Org.OpenAPITools.Api;
  using Org.OpenAPITools.Client;
  using Org.OpenAPITools.Model;

  namespace Example
  {
    public class UpdatePlanExample
    {
        public static void Main()
        {
            Configuration.Default.BasePath = "https://api.getlago.com/api/v1";
            // Configure HTTP bearer authorization: bearerAuth
            Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";

            var apiInstance = new PlansApi(Configuration.Default);
            var code = "example_code";  // string | Code of the existing plan
            var planInput = new PlanInput(); // PlanInput | Update an existing plan

            try
            {
                // Update an existing plan
                Plan result = apiInstance.UpdatePlan(code, planInput);
                Debug.WriteLine(result);
            }
            catch (ApiException e)
            {
                Debug.Print("Exception when calling PlansApi.UpdatePlan: " + e.Message );
                Debug.Print("Status Code: "+ e.ErrorCode);
                Debug.Print(e.StackTrace);
            }
        }
    }
  }
  ```

  ```php PHP
  <?php
  require_once(__DIR__ . '/vendor/autoload.php');


  // Configure Bearer authorization: bearerAuth
  $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');


  $apiInstance = new OpenAPI\Client\Api\PlansApi(
    // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
    // This is optional, `GuzzleHttp\Client` will be used as default.
    new GuzzleHttp\Client(),
    $config
  );
  $code = "example_code"; // string | Code of the existing plan
  $plan_input = new \OpenAPI\Client\Model\PlanInput(); // \OpenAPI\Client\Model\PlanInput | Update an existing plan

  try {
    $result = $apiInstance->updatePlan($code, $plan_input);
    print_r($result);
  } catch (Exception $e) {
    echo 'Exception when calling PlansApi->updatePlan: ', $e->getMessage(), PHP_EOL;
  }
  ```
</RequestExample>
