> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agentaos.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Change the plan

> Apply a plan change quoted by the preview. Echo the preview's `prorationDate` so the amount charged matches the quote. An upgrade charges the prorated difference on the saved card now and the response carries the new per-cycle amount; a downgrade is scheduled for the current period end (`effectiveAt`) and charges nothing today. Idempotent on (subscription, target plan, prorationDate). Same plan, a non-active subscription, a different currency, or a different billing interval return `400`.

<Warning>
  An **upgrade** charges the prorated difference on the subscriber's saved card **now**. Always show the [preview](/api-reference/subscriptions/plan-change-preview) first and echo its `prorationDate`; that is what makes the charge equal the quote. A **downgrade** charges nothing today and switches at the current period end.
</Warning>

<Note>
  Idempotent on (subscription, target plan, `prorationDate`): retrying the same request does not charge twice. Same plan, a subscription that is not `active` or `trialing`, a different currency, or a different billing interval return `400`.
</Note>


## OpenAPI

````yaml POST /gateway/subscriptions/{id}/plan-change
openapi: 3.1.0
info:
  title: AgentaOS Gateway API
  version: 1.0.0
  description: >-
    The AgentaOS REST API: payment links, checkouts, subscriptions, customers,
    invoices, and the unified transactions feed. This is the same API the
    TypeScript SDK (`@agentaos/pay`) and the `agenta` CLI call underneath.


    ## Money model


    - **Decimal currency units (`number`)**: a plain `amount` field (on a create
    body, a Payment Link, a Checkout's `amount_override`, or an Invoice's
    `amount`/`fiat_amount`/`tax_amount`) is in currency units. `49.99` means EUR
    49.99, never cents.

    - **Integer minor units (`number`)**: exactly one field breaks that rule:
    `unitAmountMinor` on a Subscription. It is an integer count of the smallest
    currency unit (`1999` means EUR 19.99), named with a `Minor` suffix
    specifically so it is never confused with a plain `amount`. The `money`
    object on Transactions and the `earnings` object on a retrieved Invoice are
    also integer minor units, computed server-side.

    - **String, on webhooks**: the `amount` inside a webhook payload's `data`
    object is a string (e.g. `"49.99"`), since JSON numbers silently drop
    trailing zeros and this value must round-trip exactly for accounting.


    ## Naming convention


    Most response fields mirror the underlying database column and are
    `snake_case` (`created_at`, `seller_mode`, `buyer_email`, ...). A small
    number of computed convenience fields are camelCase with no snake_case
    equivalent: `checkoutUrl` on Checkouts and Payment Links, `sellerMode` on
    Payment Links specifically, `money` on Transactions, and `earnings` on a
    single retrieved Invoice. Two resources (Subscriptions and Customers) are
    fully camelCase end to end.


    ## Pagination


    Every list endpoint takes `limit` and `offset` and returns `{ items, total,
    hasMore }`. `hasMore` is computed server-side (`offset + items.length <
    total`); never derive it client-side.
  contact:
    name: AgentaOS
    url: https://agentaos.ai
  license:
    name: Proprietary
    url: https://agentaos.ai
servers:
  - url: https://api.agentaos.ai/api/v1
    description: Production
security:
  - ApiKeyAuth: []
tags:
  - name: Payment Links
    description: >-
      Reusable, shareable payment products: a fixed amount and description
      behind one URL.
  - name: Checkouts
    description: >-
      One attempt to collect one payment, standalone or built from a payment
      link. Wire path is `/gateway/sessions`; the SDK and CLI call this resource
      "checkout".
  - name: Subscriptions
    description: >-
      Merchant-side read and management surface for recurring plans. Created
      automatically when a buyer pays a `type: subscription` payment link.
  - name: Customers
    description: 'Read-only surface: everyone who has paid you or been sent an invoice.'
  - name: Invoices
    description: >-
      Every checkout issues an invoice. List, retrieve, void, export, and
      download PDFs/receipts.
  - name: Transactions
    description: >-
      The unified activity feed: every inbound payment and outbound send, across
      every rail, in one list.
paths:
  /gateway/subscriptions/{id}/plan-change:
    post:
      tags:
        - Subscriptions
      summary: Change the plan
      description: >-
        Apply a plan change quoted by the preview. Echo the preview's
        `prorationDate` so the amount charged matches the quote. An upgrade
        charges the prorated difference on the saved card now and the response
        carries the new per-cycle amount; a downgrade is scheduled for the
        current period end (`effectiveAt`) and charges nothing today. Idempotent
        on (subscription, target plan, prorationDate). Same plan, a non-active
        subscription, a different currency, or a different billing interval
        return `400`.
      operationId: changeSubscriptionPlan
      parameters:
        - name: id
          in: path
          required: true
          description: Subscription id.
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PlanChangeRequest'
            example:
              targetLinkId: c9e44cf2-b3c3-465c-8ab8-de0706be4974
              prorationDate: 1788434542
      responses:
        '200':
          description: The applied change. Shape depends on `direction`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PlanChangeResponse'
              examples:
                upgrade:
                  value:
                    direction: upgrade
                    applied: true
                    status: active
                    unitAmountMinor: 4900
                    currency: eur
                downgrade:
                  value:
                    direction: downgrade
                    applied: true
                    effectiveAt: '2026-10-03T10:45:13.000Z'
                    unitAmountMinor: 2900
                    currency: eur
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
components:
  schemas:
    PlanChangeRequest:
      type: object
      properties:
        targetLinkId:
          type: string
          format: uuid
          description: The target product's payment-link id.
        prorationDate:
          type: integer
          minimum: 1
          description: From the preview response.
      required:
        - targetLinkId
        - prorationDate
    PlanChangeResponse:
      oneOf:
        - type: object
          title: Upgrade applied
          properties:
            direction:
              type: string
              enum:
                - upgrade
            applied:
              type: boolean
              enum:
                - true
            status:
              type: string
              description: Subscription status after the change.
            unitAmountMinor:
              type: integer
              description: New per-cycle amount.
            currency:
              type: string
          required:
            - direction
            - applied
            - status
            - unitAmountMinor
            - currency
        - type: object
          title: Downgrade scheduled
          properties:
            direction:
              type: string
              enum:
                - downgrade
            applied:
              type: boolean
              enum:
                - true
            effectiveAt:
              type: string
              format: date-time
              description: >-
                When the new plan starts: the current period end. Until then the
                subscription keeps its current plan and reports the change as
                `pendingPlanChange`.
            unitAmountMinor:
              type: integer
              description: Per-cycle amount from `effectiveAt` on.
            currency:
              type: string
          required:
            - direction
            - applied
            - effectiveAt
            - unitAmountMinor
            - currency
        - type: object
          title: Pending downgrade reverted
          properties:
            direction:
              type: string
              enum:
                - revert
            applied:
              type: boolean
              enum:
                - true
            unitAmountMinor:
              type: integer
              description: The current plan's per-cycle amount, unchanged.
            currency:
              type: string
          required:
            - direction
            - applied
            - unitAmountMinor
            - currency
    Error:
      type: object
      description: >-
        Every non-2xx response is JSON in this shape. Every response (success or
        error) also carries an `x-request-id` response header; send that header
        on your request to have your own id echoed back, otherwise the server
        mints one. On errors the same id is repeated in the `requestId` body
        field.
      properties:
        statusCode:
          type: integer
          description: Same as the HTTP status code.
        message:
          description: >-
            Human-readable. A validation failure (400) returns an array of
            per-field messages instead of one string.
          anyOf:
            - type: string
            - type: array
              items:
                type: string
        errors:
          type: array
          description: >-
            Present on 400 validation failures: one entry per invalid field. The
            flat human-readable strings stay in `message` for back-compat; this
            is the machine-readable, per-field view.
          items:
            type: object
            properties:
              field:
                type: string
                description: >-
                  Name of the invalid field, dot-notated for nested properties
                  (e.g. `checkoutFields.0.type`).
              message:
                type: string
                description: Validation messages for that field, joined with `, `.
            required:
              - field
              - message
        requestId:
          type: string
          description: >-
            Correlation id, identical to the `x-request-id` response header.
            Include it when contacting support. On success it is available on
            the header only, not the body.
        timestamp:
          type: string
          format: date-time
      required:
        - statusCode
        - message
        - timestamp
  responses:
    BadRequest:
      description: >-
        A required field is missing, out of range, or the wrong type.
        `ValidationPipe` also rejects any field not in the documented schema.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            statusCode: 400
            message: amount is required when creating a session without a link
            timestamp: '2026-08-06T12:00:00.000Z'
    Unauthorized:
      description: Missing or invalid `x-api-key`.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            statusCode: 401
            message: Invalid API key
            timestamp: '2026-08-06T12:00:00.000Z'
    Forbidden:
      description: The key is valid but the resource belongs to a different organization.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            statusCode: 403
            message: Payment link belongs to another organization
            timestamp: '2026-08-06T12:00:00.000Z'
    NotFound:
      description: >-
        Resource not found (or not visible to your key; the two are not
        distinguished).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            statusCode: 404
            message: Payment link not found
            timestamp: '2026-08-06T12:00:00.000Z'
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        Your secret key, from app.agentaos.ai -> Settings -> Developers -> API
        Keys. The key's prefix is both its identity and its environment:
        `sk_test_...` (sandbox, free, no verification) or `sk_live_...` (real
        money, requires business verification). A missing or invalid key returns
        401.

````