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

# Create a discount

> Creates a new discount code.

<Info>Click the base URL in the API playground and select the **Sandbox** host for test data or the **Production** host for live data. Use credentials from the same environment.</Info>


## OpenAPI

````yaml /api-reference/openapi.json post /discount/
openapi: 3.0.0
info:
  title: kelviq API
  version: 1.0.0
  description: >-
    API for interacting with kelviq services, derived from Python SDK
    documentation.
servers:
  - url: https://sandboxapi.kelviq.com/api/v1
    description: Sandbox — Test payments
  - url: https://api.kelviq.com/api/v1
    description: Production — Live payments
security:
  - bearerAuth: []
tags:
  - name: Products
    description: Catalog products.
  - name: Product Settings
    description: Per-product settings (currency, VPN/Tor/proxy, product URL).
  - name: Product Files
    description: Product images and downloadable assets.
  - name: Features
    description: Catalog features that can be granted as plan entitlements.
  - name: Plans
    description: Catalog plans (CRUD, publish, versions, prices).
  - name: Plan Entitlements
    description: Feature entitlements attached to a plan.
  - name: Plan Files
    description: Files attached to plans, and signed download links.
  - name: Media
    description: Generate presigned S3 upload URLs for product/plan images and files.
  - name: Partner
    description: Partner integration APIs (organization provisioning, lookup).
  - name: Charges
    description: >-
      One-time payments charged immediately against a customer's default payment
      method.
  - name: Refunds
    description: Full and partial refunds for paid orders.
  - name: Transactions
    description: >-
      Charges, refunds, disputes, and other financial movements for the
      authenticated organization.
  - name: Payment Methods
    description: Saved customer payment methods (cards, etc.).
  - name: Orders
    description: Completed and resolved orders for the authenticated organization.
  - name: Order Events
    description: Timeline events for a specific order.
  - name: Invoices
    description: Invoices generated for orders and subscription billing cycles.
  - name: Discounts
    description: >-
      Discount codes (coupons) that can be applied to products and plans at
      checkout.
  - name: Webhook Endpoints
    description: >-
      Configure the destination URLs and event subscriptions that receive
      webhook deliveries.
  - name: Webhooks
    description: Delivery logs for webhook events sent to your configured endpoints.
  - name: Checkout Sessions
    description: Merchant-side view of checkout sessions created by customers.
  - name: Checkout Session Events
    description: Timeline events for a specific checkout session.
paths:
  /discount/:
    post:
      tags:
        - Discounts
      summary: Create a discount
      description: Creates a new discount code.
      operationId: createDiscount
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DiscountCreateRequest'
      responses:
        '201':
          description: Discount created.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Discount'
        '400':
          description: >-
            Validation error, or the organization is not enrolled as Merchant of
            Record.
        '401':
          description: Unauthorized — missing or invalid API key.
components:
  schemas:
    DiscountCreateRequest:
      type: object
      properties:
        discountType:
          type: string
          enum:
            - PERCENTAGE
            - FIXED_AMOUNT
        amountOff:
          type: string
          description: Required (and only used) when `discountType` is FIXED_AMOUNT.
        percentageOff:
          type: integer
          description: Required (and only used) when `discountType` is PERCENTAGE.
        currency:
          type: string
          description: >-
            3-letter ISO currency code. Required when `discountType` is
            FIXED_AMOUNT.
        name:
          type: string
          description: Displayed on the customer's invoice.
        code:
          type: string
          description: >-
            Checkout discount code. Uppercase letters and numbers only, and must
            be unique among active discounts for the organization.
        duration:
          type: string
          enum:
            - ONCE
            - REPEATING
            - FOREVER
          default: ONCE
        durationInMonths:
          type: integer
          description: >-
            Number of billing periods the discount applies for. Despite the
            field name, this counts billing cycles, not calendar months — e.g. 3
            on a yearly plan means 3 years. Required when `duration` is
            REPEATING.
        redeemBy:
          type: string
          format: date-time
          description: >-
            UTC time after which this discount can no longer be redeemed. Must
            be in the future.
        maxRedemptions:
          type: integer
          description: >-
            Total number of times this code can be redeemed across all
            customers.
        appliesTo:
          type: array
          items:
            $ref: '#/components/schemas/DiscountAppliesToRequestItem'
          description: >-
            Restrict the discount to specific products/plans. Omit to apply to
            all products.
      required:
        - discountType
        - name
        - code
    Discount:
      type: object
      properties:
        id:
          type: string
          format: uuid
          example: b3f1a2c4-5d6e-4f7a-8b9c-0d1e2f3a4b5c
        discountType:
          type: string
          enum:
            - PERCENTAGE
            - FIXED_AMOUNT
          description: >-
            PERCENTAGE discounts a percentage off the price. FIXED_AMOUNT
            discounts a flat amount off the total.
        amountOff:
          type: string
          nullable: true
          description: >-
            Amount to discount, in currency units (e.g. "10.00"). Set when
            `discountType` is FIXED_AMOUNT.
          example: '10.00'
        percentageOff:
          type: integer
          nullable: true
          description: Percentage to discount. Set when `discountType` is PERCENTAGE.
          example: 20
        currency:
          type: string
          nullable: true
          description: >-
            3-letter ISO currency code. Required when `discountType` is
            FIXED_AMOUNT.
          example: usd
        currencySymbol:
          type: string
          example: $
        name:
          type: string
          description: Displayed on the customer's invoice.
          example: Summer Sale
        code:
          type: string
          description: Checkout discount code. Uppercase letters and numbers only.
          example: SUMMER20
        duration:
          type: string
          enum:
            - ONCE
            - REPEATING
            - FOREVER
          description: How many billing cycles the discount applies for.
        durationInMonths:
          type: integer
          nullable: true
          description: >-
            Number of billing periods the discount applies for. Despite the
            field name, this counts billing cycles, not calendar months — e.g. 3
            on a yearly plan means 3 years. Set when `duration` is REPEATING.
        redeemBy:
          type: string
          format: date-time
          nullable: true
          description: UTC time after which this discount can no longer be redeemed.
        maxRedemptions:
          type: integer
          nullable: true
          description: >-
            Total number of times this code can be redeemed across all
            customers.
        timesRedeemed:
          type: integer
          description: Number of times this code has been redeemed so far.
        appliesTo:
          type: array
          description: >-
            Products/plans this discount is restricted to. Empty means the
            discount applies to all products.
          items:
            $ref: '#/components/schemas/DiscountAppliesTo'
        isActive:
          type: boolean
    DiscountAppliesToRequestItem:
      type: object
      properties:
        product:
          type: string
          format: uuid
          description: Product ID this discount applies to.
        plans:
          type: array
          items:
            type: string
          description: >-
            Plan identifiers within the product to restrict the discount to.
            Omit or leave empty to apply to all plans of the product.
      required:
        - product
    DiscountAppliesTo:
      type: object
      description: >-
        One product (and optionally specific plans of that product) this
        discount is restricted to.
      properties:
        product:
          $ref: '#/components/schemas/DiscountAppliesToProduct'
        plans:
          type: array
          items:
            $ref: '#/components/schemas/DiscountAppliesToPlan'
    DiscountAppliesToProduct:
      type: object
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
    DiscountAppliesToPlan:
      type: object
      properties:
        identifier:
          type: string
        name:
          type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        The Server API Key obtained from the kelviq application. Pass as a
        Bearer token in the Authorization header. Example: 'Authorization:
        Bearer __YOUR_API_KEY__'

````