# Create or update a plan by its code (versioned on a price change)

`PUT /api/v1/plans/by-code/{code}`

Idempotent; `Idempotency-Key` is honoured when sent. A price change never edits a version in place: existing subscribers keep the version, and the price, they bought.

Needs the `catalog:write` scope, or a full-access key.

## Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `code` | string | required |  |

## Request body

JSON Schema:

```json
{
  "type": "object",
  "properties": {
    "product_id": {
      "type": "string",
      "format": "uuid",
      "example": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
    },
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200
    },
    "pricing_model": {
      "type": "string",
      "enum": [
        "flat",
        "per_seat",
        "metered",
        "tiered",
        "volume",
        "package"
      ]
    },
    "interval": {
      "type": "string",
      "enum": [
        "monthly",
        "quarterly",
        "annual",
        "one_time"
      ]
    },
    "billing_timing": {
      "type": "string",
      "enum": [
        "advance",
        "arrears"
      ]
    },
    "currency": {
      "type": "string",
      "enum": [
        "USD",
        "AUD",
        "CAD",
        "GBP",
        "EUR",
        "INR",
        "NPR"
      ],
      "example": "USD"
    },
    "amount_cents": {
      "type": "string",
      "pattern": "^\\d+$",
      "description": "Base-currency price, in minor units. On a graduated per_seat plan it is set to band 1 of `tier_config`.",
      "example": "1999"
    },
    "tier_config": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "up_to": {
            "type": [
              "integer",
              "null"
            ],
            "exclusiveMinimum": 0,
            "description": "Inclusive upper seat of the band; null on the last band."
          },
          "unit_amount_cents": {
            "type": "string",
            "pattern": "^\\d+$",
            "description": "Per-seat price in this band, in minor units.",
            "example": "1999"
          }
        },
        "required": [
          "up_to",
          "unit_amount_cents"
        ]
      },
      "description": "Base-currency ladder, ascending, last band `up_to: null`."
    },
    "included_units": {
      "type": "string",
      "pattern": "^\\d+$",
      "description": "Included usage units.",
      "example": "1999"
    },
    "package_size": {
      "type": "integer",
      "exclusiveMinimum": 0
    },
    "unit_name": {
      "type": "string",
      "maxLength": 50
    },
    "aggregation": {
      "type": "string",
      "enum": [
        "sum",
        "max",
        "last_during_period"
      ]
    },
    "prices": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "currency": {
            "type": "string",
            "enum": [
              "USD",
              "AUD",
              "CAD",
              "GBP",
              "EUR",
              "INR",
              "NPR"
            ],
            "example": "USD"
          },
          "amount_cents": {
            "type": "string",
            "pattern": "^\\d+$",
            "description": "Price in this currency, in minor units.",
            "example": "1999"
          },
          "tiers": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "object",
              "properties": {
                "up_to": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "exclusiveMinimum": 0,
                  "description": "Inclusive upper seat of the band; null on the last band."
                },
                "unit_amount_cents": {
                  "type": "string",
                  "pattern": "^\\d+$",
                  "description": "Per-seat price in this band, in minor units.",
                  "example": "1999"
                }
              },
              "required": [
                "up_to",
                "unit_amount_cents"
              ]
            }
          }
        },
        "required": [
          "currency",
          "amount_cents"
        ]
      },
      "description": "Other currencies (never the base one, none twice). A graduated per_seat plan needs `tiers` on every one."
    },
    "metadata": {
      "type": "object",
      "additionalProperties": {
        "type": "string",
        "maxLength": 500
      },
      "description": "At most 20 keys; values up to 500 characters."
    },
    "active": {
      "type": "boolean",
      "description": "Omitted: a new plan is active, an existing one keeps its flag."
    }
  },
  "required": [
    "product_id",
    "name",
    "pricing_model",
    "interval",
    "currency",
    "amount_cents"
  ]
}
```

## Responses

### 200

`updated` (name, product, unit name, metadata or active changed in place) or `unchanged`.

JSON Schema:

```json
{
  "type": "object",
  "properties": {
    "data": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid",
          "example": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
        },
        "code": {
          "type": "string"
        },
        "version": {
          "type": "integer"
        },
        "outcome": {
          "type": "string",
          "enum": [
            "created",
            "new_version",
            "updated",
            "unchanged"
          ]
        }
      },
      "required": [
        "id",
        "code",
        "version",
        "outcome"
      ]
    },
    "_agent": {
      "type": "object",
      "properties": {
        "summary": {
          "type": "string"
        },
        "status": {
          "type": "string",
          "enum": [
            "ok"
          ]
        },
        "next_actions": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "warnings": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "summary",
        "status",
        "next_actions",
        "warnings"
      ]
    },
    "api_version": {
      "type": "string",
      "example": "2026-07-01"
    }
  },
  "required": [
    "data",
    "_agent",
    "api_version"
  ]
}
```

### 201

`created` (version 1) or `new_version` (a price changed: version n+1, the previous version retired).

JSON Schema:

```json
{
  "type": "object",
  "properties": {
    "data": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid",
          "example": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
        },
        "code": {
          "type": "string"
        },
        "version": {
          "type": "integer"
        },
        "outcome": {
          "type": "string",
          "enum": [
            "created",
            "new_version",
            "updated",
            "unchanged"
          ]
        }
      },
      "required": [
        "id",
        "code",
        "version",
        "outcome"
      ]
    },
    "_agent": {
      "type": "object",
      "properties": {
        "summary": {
          "type": "string"
        },
        "status": {
          "type": "string",
          "enum": [
            "ok"
          ]
        },
        "next_actions": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "warnings": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "summary",
        "status",
        "next_actions",
        "warnings"
      ]
    },
    "api_version": {
      "type": "string",
      "example": "2026-07-01"
    }
  },
  "required": [
    "data",
    "_agent",
    "api_version"
  ]
}
```

### 422

`validation_failed`, or `invalid_tiers` when the ladders do not hold together.
