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

# Create Reward

> Create a coupon or feature grant.

export const DynamicResponseExample = ({json, statusCode = "200"}) => {
  const toCamelCase = str => {
    return str.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
  };
  const convertKeysToCamelCase = obj => {
    if (Array.isArray(obj)) {
      return obj.map(item => convertKeysToCamelCase(item));
    }
    if (obj !== null && typeof obj === "object") {
      return Object.keys(obj).reduce((acc, key) => {
        const camelKey = toCamelCase(key);
        acc[camelKey] = convertKeysToCamelCase(obj[key]);
        return acc;
      }, {});
    }
    return obj;
  };
  const [isTypeScript, setIsTypeScript] = useState(() => {
    if (typeof window !== "undefined") {
      try {
        const lang = localStorage.getItem("code");
        return JSON.parse(lang) === "typescript";
      } catch {
        return true;
      }
    }
    return true;
  });
  useEffect(() => {
    const onMintlifyStorage = event => {
      if (event.detail?.key === "code") {
        try {
          const value = JSON.parse(event.detail.value);
          setIsTypeScript(value === "typescript");
        } catch {}
      }
    };
    const pollInterval = setInterval(() => {
      try {
        const lang = localStorage.getItem("code");
        const value = JSON.parse(lang);
        setIsTypeScript(value === "typescript");
      } catch {}
    }, 300);
    document.addEventListener("mintlify-localstorage", onMintlifyStorage);
    return () => {
      document.removeEventListener("mintlify-localstorage", onMintlifyStorage);
      clearInterval(pollInterval);
    };
  }, []);
  const camelCaseJson = useMemo(() => convertKeysToCamelCase(json), [json]);
  const snakeCaseString = JSON.stringify(json, null, 2);
  const camelCaseString = JSON.stringify(camelCaseJson, null, 2);
  return <ResponseExample>
			{isTypeScript ? <CodeBlock language="json" filename={statusCode}>
					{camelCaseString}
				</CodeBlock> : <CodeBlock language="json" filename={statusCode}>
					{snakeCaseString}
				</CodeBlock>}
		</ResponseExample>;
};

export const DynamicResponseField = ({children, name, ...props}) => {
  const convertToCamelCase = str => {
    if (typeof str !== "string") return str;
    return str.replace(/[_-](\w)/g, (_, c) => c.toUpperCase());
  };
  const [lang, setLang] = useState(() => {
    if (typeof window !== "undefined") {
      const stored = localStorage.getItem("code");
      return stored || '"typescript"';
    }
    return '"typescript"';
  });
  useEffect(() => {
    const onMintlifyStorage = event => {
      const key = event.detail?.key;
      if (key === "code") {
        setLang(event.detail.value);
      }
    };
    const pollInterval = setInterval(() => {
      const current = localStorage.getItem("code");
      if (current && current !== lang) {
        setLang(current);
      }
    }, 500);
    document.addEventListener("mintlify-localstorage", onMintlifyStorage);
    return () => {
      document.removeEventListener("mintlify-localstorage", onMintlifyStorage);
      clearInterval(pollInterval);
    };
  }, [lang]);
  const resolvedName = useMemo(() => {
    try {
      const value = JSON.parse(lang);
      const useCamelCase = value === "typescript";
      return useCamelCase ? convertToCamelCase(name) : name;
    } catch {
      return name;
    }
  }, [name, lang]);
  return <ResponseField name={resolvedName} {...props}>
			{children}
		</ResponseField>;
};

export const DynamicParamField = ({children, body, path, ...props}) => {
  const convertToCamelCase = str => {
    if (typeof str !== "string") return str;
    return str.replace(/[_-](\w)/g, (_, c) => c.toUpperCase());
  };
  const [lang, setLang] = useState(() => {
    if (typeof window !== "undefined") {
      const stored = localStorage.getItem("code");
      return stored || '"typescript"';
    }
    return '"typescript"';
  });
  useEffect(() => {
    const onMintlifyStorage = event => {
      const key = event.detail?.key;
      if (key === "code") {
        setLang(event.detail.value);
      }
    };
    const pollInterval = setInterval(() => {
      const current = localStorage.getItem("code");
      if (current && current !== lang) {
        setLang(current);
      }
    }, 500);
    document.addEventListener("mintlify-localstorage", onMintlifyStorage);
    return () => {
      document.removeEventListener("mintlify-localstorage", onMintlifyStorage);
      clearInterval(pollInterval);
    };
  }, [lang]);
  const resolvedBody = useMemo(() => {
    try {
      const value = JSON.parse(lang);
      const useCamelCase = value === "typescript";
      return useCamelCase ? convertToCamelCase(body) : body;
    } catch {
      return body;
    }
  }, [body, lang]);
  const resolvedPath = useMemo(() => {
    try {
      const value = JSON.parse(lang);
      const useCamelCase = value === "typescript";
      return useCamelCase ? convertToCamelCase(path) : path;
    } catch {
      return path;
    }
  }, [path, lang]);
  return <ParamField body={resolvedBody} path={resolvedPath} {...props}>
			{children}
		</ParamField>;
};

### Body Parameters

<DynamicParamField body="coupon" type="object">
  Provide exactly one of coupon or feature\_grant, not both.

  <Expandable title="properties">
    <DynamicParamField body="id" type="string" required />

    <DynamicParamField body="name" type="string" required />

    <DynamicParamField body="duration" type="object" required>
      Use a positive integer length for months, and null for one\_off or forever.

      <Expandable title="properties">
        <DynamicParamField body="type" type="'one_off' | 'months' | 'forever'" required />

        <DynamicParamField body="length" type="integer | null" required />
      </Expandable>
    </DynamicParamField>

    <DynamicParamField body="plan_ids" type="string[] | null" required>
      Plan IDs must be unique.
    </DynamicParamField>

    <DynamicParamField body="promo_codes" type="object[]" required>
      Promo code values must be unique.

      <Expandable title="properties">
        <DynamicParamField body="code" type="string" required />

        <DynamicParamField body="global_max_redemption" type="integer | null" />

        <DynamicParamField body="first_time_transaction" type="boolean | null" />
      </Expandable>
    </DynamicParamField>

    <DynamicParamField body="type" type="'percentage_discount' | 'fixed_discount'" required />

    <DynamicParamField body="value" type="number" required>
      Percentage discounts must be at most 100; fixed discounts must be positive.
    </DynamicParamField>
  </Expandable>
</DynamicParamField>

<DynamicParamField body="feature_grant" type="object">
  Provide exactly one of coupon or feature\_grant, not both.

  <Expandable title="properties">
    <DynamicParamField body="id" type="string" required />

    <DynamicParamField body="name" type="string" required />

    <DynamicParamField body="grants" type="object[]" required>
      Feature IDs must be unique.

      <Expandable title="properties">
        <DynamicParamField body="feature_id" type="string" required />

        <DynamicParamField body="included" type="number | null" required>
          A positive amount to grant, or null for boolean features.
        </DynamicParamField>

        <DynamicParamField body="expiry" type="object | null" required>
          <Expandable title="properties">
            <DynamicParamField body="type" type="'day' | 'week' | 'month' | 'year'" required>
              The unit of time the grant lasts.
            </DynamicParamField>

            <DynamicParamField body="length" type="integer" required>
              The positive integer count of periods before the grant expires.
            </DynamicParamField>
          </Expandable>
        </DynamicParamField>
      </Expandable>
    </DynamicParamField>

    <DynamicParamField body="promo_codes" type="object[]" required>
      Promo code values must be unique.

      <Expandable title="properties">
        <DynamicParamField body="code" type="string" required />

        <DynamicParamField body="max_uses" type="integer | null" required>
          A positive redemption limit, or null for unlimited uses.
        </DynamicParamField>
      </Expandable>
    </DynamicParamField>
  </Expandable>
</DynamicParamField>

### Response

<DynamicResponseField name="coupon" type="object">
  <Expandable title="properties">
    <DynamicResponseField name="id" type="string">
      The unique identifier for the coupon.
    </DynamicResponseField>

    <DynamicResponseField name="name" type="string | null">
      A human-readable name for the coupon.
    </DynamicResponseField>

    <DynamicResponseField name="type" type="'percentage_discount' | 'fixed_discount' | 'invoice_credits'">
      The type of discount: percentage\_discount, fixed\_discount, or invoice\_credits.
    </DynamicResponseField>

    <DynamicResponseField name="value" type="number">
      The discount value. A percentage for percentage\_discount, or an amount for fixed\_discount / invoice\_credits.
    </DynamicResponseField>

    <DynamicResponseField name="duration" type="object">
      How long the coupon applies once redeemed.

      <Expandable title="properties">
        <DynamicResponseField name="type" type="'one_off' | 'months' | 'forever'">
          The unit of time the duration is measured in.
        </DynamicResponseField>

        <DynamicResponseField name="length" type="number | null">
          The number of `type` periods the duration lasts, or null when the type has no length (e.g. one\_off, forever).
        </DynamicResponseField>
      </Expandable>
    </DynamicResponseField>

    <DynamicResponseField name="plan_ids" type="string[] | null">
      The plan IDs the coupon applies to, or null when it applies to all plans.
    </DynamicResponseField>

    <DynamicResponseField name="promo_codes" type="object[]">
      <Expandable title="properties">
        <DynamicResponseField name="code" type="string">
          The promo code customers enter to redeem the coupon.
        </DynamicResponseField>

        <DynamicResponseField name="global_max_redemption" type="number | null">
          Maximum number of times this promo code can be redeemed across all customers, or null for unlimited.
        </DynamicResponseField>

        <DynamicResponseField name="first_time_transaction" type="boolean | null">
          Whether this promo code can only be applied to a customer's first transaction.
        </DynamicResponseField>
      </Expandable>
    </DynamicResponseField>

    <DynamicResponseField name="created_at" type="number">
      The Unix timestamp (in milliseconds) when the coupon was created.
    </DynamicResponseField>
  </Expandable>
</DynamicResponseField>

<DynamicResponseField name="feature_grant" type="object">
  <Expandable title="properties">
    <DynamicResponseField name="id" type="string">
      The unique identifier for the feature grant.
    </DynamicResponseField>

    <DynamicResponseField name="name" type="string | null">
      A human-readable name for the feature grant.
    </DynamicResponseField>

    <DynamicResponseField name="grants" type="object[]">
      <Expandable title="properties">
        <DynamicResponseField name="feature_id" type="string">
          The feature ID this grant applies to.
        </DynamicResponseField>

        <DynamicResponseField name="included" type="number | null">
          The amount of the feature granted, or null for boolean features.
        </DynamicResponseField>

        <DynamicResponseField name="expiry" type="object | null">
          How long the granted amount lasts before expiring, or null for a permanent grant.

          <Expandable title="properties">
            <DynamicResponseField name="type" type="'day' | 'week' | 'month' | 'year'">
              The unit of time the grant lasts.
            </DynamicResponseField>

            <DynamicResponseField name="length" type="integer">
              The positive integer count of periods before the grant expires.
            </DynamicResponseField>
          </Expandable>
        </DynamicResponseField>
      </Expandable>
    </DynamicResponseField>

    <DynamicResponseField name="promo_codes" type="object[]">
      <Expandable title="properties">
        <DynamicResponseField name="code" type="string">
          The promo code customers enter to redeem the feature grant.
        </DynamicResponseField>

        <DynamicResponseField name="max_uses" type="number | null">
          Maximum number of times this promo code can be redeemed, or null for unlimited.
        </DynamicResponseField>
      </Expandable>
    </DynamicResponseField>

    <DynamicResponseField name="created_at" type="number">
      The Unix timestamp (in milliseconds) when the feature grant was created.
    </DynamicResponseField>
  </Expandable>
</DynamicResponseField>


## OpenAPI

````yaml openapi POST /v1/rewards.create
openapi: 3.1.0
info:
  title: Autumn API
  version: 2.3.0
servers:
  - url: https://api.useautumn.com
    description: Production server
security:
  - secretKey: []
paths:
  /v1/rewards.create:
    post:
      tags:
        - rewards
      description: Create a coupon or feature grant.
      operationId: createReward
      parameters:
        - name: x-api-version
          in: header
          required: true
          schema:
            type: string
            default: 2.3.0
          x-speakeasy-globals-hidden: true
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                coupon:
                  type: object
                  properties:
                    id:
                      type: string
                      minLength: 1
                    name:
                      type: string
                      minLength: 1
                    duration:
                      type: object
                      properties:
                        type:
                          enum:
                            - one_off
                            - months
                            - forever
                          type: string
                        length:
                          anyOf:
                            - type: integer
                              minimum: -9007199254740991
                              maximum: 9007199254740991
                              exclusiveMinimum: 0
                            - type: 'null'
                      required:
                        - type
                        - length
                      additionalProperties: false
                      description: >-
                        Use a positive integer length for months, and null for
                        one_off or forever.
                    plan_ids:
                      anyOf:
                        - type: array
                          minItems: 1
                          items:
                            type: string
                            minLength: 1
                        - type: 'null'
                      description: Plan IDs must be unique.
                    promo_codes:
                      type: array
                      items:
                        type: object
                        properties:
                          code:
                            type: string
                            minLength: 1
                          global_max_redemption:
                            anyOf:
                              - type: integer
                                minimum: -9007199254740991
                                maximum: 9007199254740991
                                exclusiveMinimum: 0
                              - type: 'null'
                          first_time_transaction:
                            anyOf:
                              - type: boolean
                              - type: 'null'
                        required:
                          - code
                        additionalProperties: false
                      description: Promo code values must be unique.
                    type:
                      enum:
                        - percentage_discount
                        - fixed_discount
                      type: string
                    value:
                      type: number
                      exclusiveMinimum: 0
                      description: >-
                        Percentage discounts must be at most 100; fixed
                        discounts must be positive.
                  required:
                    - id
                    - name
                    - duration
                    - plan_ids
                    - promo_codes
                    - type
                    - value
                  additionalProperties: false
                  title: CreateRewardCouponRequest
                  description: Provide exactly one of coupon or feature_grant, not both.
                feature_grant:
                  type: object
                  properties:
                    id:
                      type: string
                      minLength: 1
                    name:
                      type: string
                      minLength: 1
                    grants:
                      type: array
                      minItems: 1
                      items:
                        type: object
                        properties:
                          feature_id:
                            type: string
                            minLength: 1
                          included:
                            anyOf:
                              - type: number
                                exclusiveMinimum: 0
                              - type: 'null'
                            description: >-
                              A positive amount to grant, or null for boolean
                              features.
                          expiry:
                            anyOf:
                              - type: object
                                properties:
                                  type:
                                    enum:
                                      - day
                                      - week
                                      - month
                                      - year
                                    type: string
                                    description: The unit of time the grant lasts.
                                  length:
                                    type: integer
                                    minimum: -9007199254740991
                                    maximum: 9007199254740991
                                    exclusiveMinimum: 0
                                    description: >-
                                      The positive integer count of periods
                                      before the grant expires.
                                required:
                                  - type
                                  - length
                                additionalProperties: false
                              - type: 'null'
                        required:
                          - feature_id
                          - included
                          - expiry
                        additionalProperties: false
                      description: Feature IDs must be unique.
                    promo_codes:
                      type: array
                      minItems: 1
                      items:
                        type: object
                        properties:
                          code:
                            type: string
                            minLength: 1
                          max_uses:
                            anyOf:
                              - type: integer
                                minimum: -9007199254740991
                                maximum: 9007199254740991
                                exclusiveMinimum: 0
                              - type: 'null'
                            description: >-
                              A positive redemption limit, or null for unlimited
                              uses.
                        required:
                          - code
                          - max_uses
                        additionalProperties: false
                      description: Promo code values must be unique.
                  required:
                    - id
                    - name
                    - grants
                    - promo_codes
                  additionalProperties: false
                  title: CreateRewardFeatureGrantRequest
                  description: Provide exactly one of coupon or feature_grant, not both.
              additionalProperties: false
              title: CreateRewardParams
              examples:
                - coupon:
                    id: summer_sale
                    name: Summer Sale
                    type: percentage_discount
                    value: 20
                    duration:
                      type: months
                      length: 3
                    plan_ids: null
                    promo_codes:
                      - code: SUMMER20
            example:
              coupon:
                id: summer_sale
                name: Summer Sale
                type: percentage_discount
                value: 20
                duration:
                  type: months
                  length: 3
                plan_ids: null
                promo_codes:
                  - code: SUMMER20
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  coupon:
                    type: object
                    properties:
                      id:
                        type: string
                        description: The unique identifier for the coupon.
                      name:
                        anyOf:
                          - type: string
                          - type: 'null'
                        description: A human-readable name for the coupon.
                      type:
                        enum:
                          - percentage_discount
                          - fixed_discount
                          - invoice_credits
                        type: string
                        description: >-
                          The type of discount: percentage_discount,
                          fixed_discount, or invoice_credits.
                      value:
                        type: number
                        description: >-
                          The discount value. A percentage for
                          percentage_discount, or an amount for fixed_discount /
                          invoice_credits.
                      duration:
                        type: object
                        properties:
                          type:
                            enum:
                              - one_off
                              - months
                              - forever
                            type: string
                            description: The unit of time the duration is measured in.
                          length:
                            anyOf:
                              - type: number
                              - type: 'null'
                            description: >-
                              The number of `type` periods the duration lasts,
                              or null when the type has no length (e.g. one_off,
                              forever).
                        required:
                          - type
                          - length
                        title: CreateRewardDurationResponse
                        description: How long the coupon applies once redeemed.
                      plan_ids:
                        anyOf:
                          - type: array
                            items:
                              type: string
                          - type: 'null'
                        description: >-
                          The plan IDs the coupon applies to, or null when it
                          applies to all plans.
                      promo_codes:
                        type: array
                        items:
                          type: object
                          properties:
                            code:
                              type: string
                              description: >-
                                The promo code customers enter to redeem the
                                coupon.
                            global_max_redemption:
                              anyOf:
                                - type: number
                                - type: 'null'
                              description: >-
                                Maximum number of times this promo code can be
                                redeemed across all customers, or null for
                                unlimited.
                            first_time_transaction:
                              anyOf:
                                - type: boolean
                                - type: 'null'
                              description: >-
                                Whether this promo code can only be applied to a
                                customer's first transaction.
                          required:
                            - code
                          title: CreateRewardCouponPromoCodeResponse
                      created_at:
                        type: number
                        description: >-
                          The Unix timestamp (in milliseconds) when the coupon
                          was created.
                    required:
                      - id
                      - type
                      - value
                      - duration
                      - plan_ids
                      - promo_codes
                      - created_at
                    title: CreateRewardCouponResponse
                    examples:
                      - id: summer_sale
                        name: Summer Sale
                        type: percentage_discount
                        value: 20
                        duration:
                          type: months
                          length: 3
                        plan_ids:
                          - pro
                          - starter
                        promo_codes:
                          - code: SUMMER20
                            global_max_redemption: 100
                            first_time_transaction: false
                        created_at: 1718000000000
                  feature_grant:
                    type: object
                    properties:
                      id:
                        type: string
                        description: The unique identifier for the feature grant.
                      name:
                        anyOf:
                          - type: string
                          - type: 'null'
                        description: A human-readable name for the feature grant.
                      grants:
                        type: array
                        items:
                          type: object
                          properties:
                            feature_id:
                              type: string
                              description: The feature ID this grant applies to.
                            included:
                              anyOf:
                                - type: number
                                - type: 'null'
                              description: >-
                                The amount of the feature granted, or null for
                                boolean features.
                            expiry:
                              anyOf:
                                - type: object
                                  properties:
                                    type:
                                      enum:
                                        - day
                                        - week
                                        - month
                                        - year
                                      type: string
                                      description: The unit of time the grant lasts.
                                    length:
                                      type: integer
                                      minimum: -9007199254740991
                                      maximum: 9007199254740991
                                      exclusiveMinimum: 0
                                      description: >-
                                        The positive integer count of periods
                                        before the grant expires.
                                  required:
                                    - type
                                    - length
                                - type: 'null'
                              title: CreateRewardExpiryResponse
                              description: >-
                                How long the granted amount lasts before
                                expiring, or null for a permanent grant.
                          required:
                            - feature_id
                            - included
                            - expiry
                          title: CreateRewardGrantResponse
                      promo_codes:
                        type: array
                        items:
                          type: object
                          properties:
                            code:
                              type: string
                              description: >-
                                The promo code customers enter to redeem the
                                feature grant.
                            max_uses:
                              anyOf:
                                - type: number
                                - type: 'null'
                              description: >-
                                Maximum number of times this promo code can be
                                redeemed, or null for unlimited.
                          required:
                            - code
                            - max_uses
                          title: CreateRewardFeatureGrantPromoCodeResponse
                      created_at:
                        type: number
                        description: >-
                          The Unix timestamp (in milliseconds) when the feature
                          grant was created.
                    required:
                      - id
                      - grants
                      - promo_codes
                      - created_at
                    title: CreateRewardFeatureGrantResponse
                    examples:
                      - id: beta_credits_grant
                        name: Beta Tester Credits
                        promo_codes:
                          - code: BETA2024
                            max_uses: 500
                        grants:
                          - feature_id: credits
                            included: 1000
                            expiry:
                              type: month
                              length: 1
                        created_at: 1718000000000
                additionalProperties: false
      x-codeSamples:
        - lang: typescript
          label: Typescript (SDK)
          source: |-
            import { Autumn } from 'autumn-js'

            const autumn = new Autumn()

            const result = await autumn.rewards.create({
              coupon: {
                id: "summer_sale",
                name: "Summer Sale",
                duration: {
                  type: "months",
                  length: 3,
                },
                planIds: null,
                promoCodes: [
                  {
                    code: "SUMMER20",
                  },
                ],
                type: "percentage_discount",
                value: 20,
              },
            });
        - lang: python
          label: Python (SDK)
          source: |-
            from autumn_sdk import Autumn

            autumn = Autumn(secret_key="am_sk_test...")

            res = autumn.rewards.create(
                coupon={
                    "id": "summer_sale",
                    "name": "Summer Sale",
                    "duration": {
                        "type": "months",
                        "length": 3,
                    },
                    "plan_ids": None,
                    "promo_codes": [
                        {
                            "code": "SUMMER20",
                        },
                    ],
                    "type": "percentage_discount",
                    "value": 20,
                },
            )
components:
  securitySchemes:
    secretKey:
      type: http
      scheme: bearer
      bearerFormat: JWT

````