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

# Create Setup Intent

> Creates a SetupIntent to collect a customer's payment method details for future off-session use.

A new SetupIntent is created on each call and starts in the `requires_payment_method` status; it
is not an upsert. The response includes a `client_secret` that you use to confirm the SetupIntent
and attach a payment method from your frontend.



## OpenAPI

````yaml /openapi.json post /v1/setup_intents
openapi: 3.1.0
info:
  title: Flex API
  description: >-
    The Flex API powers HSA/FSA payment processing for healthcare commerce:
    checkout sessions, payment intents, subscriptions, customers, refunds,
    disputes, and eligibility. Authenticate with your partner API key as a
    Bearer token. All endpoints are scoped to your partner account, and test
    mode is fully supported via test API keys.
  version: 0.1.0
servers:
  - url: https://api.withflex.com
security:
  - BearerAuth: []
tags:
  - name: Balance Transactions
  - name: Captures
  - name: Checkout Sessions
  - name: Coupons
  - name: Customers
  - name: Disputes
  - name: Events
  - name: Exports
  - name: Files
  - name: Invoices
  - name: Letters
  - name: Orders
  - name: Payment Intents
  - name: Payment Links
  - name: Payouts
  - name: Prices
  - name: Products
  - name: Promo Codes
  - name: Receipts
  - name: Refunds
  - name: Setup Intents
  - name: Shipping Rates
  - name: Subscriptions
paths:
  /v1/setup_intents:
    post:
      tags:
        - Setup Intents
      summary: Create Setup Intent
      description: >-
        Creates a SetupIntent to collect a customer's payment method details for
        future off-session use.


        A new SetupIntent is created on each call and starts in the
        `requires_payment_method` status; it

        is not an upsert. The response includes a `client_secret` that you use
        to confirm the SetupIntent

        and attach a payment method from your frontend.
      operationId: v1.setup_intents.create
      requestBody:
        description: An envelope wrapping a single setup intent object.
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SetupIntentBody_for_CreateSetupIntent'
            example:
              setup_intent:
                partner_id: facct_01J9XR8M3K7VZ8N2YB4WJ6T0RA
                checkout_session: fcs_01J9XR8M3K7VZ8N2YB4WJ6T0RA
        required: true
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SetupIntentBody_for_SetupIntent'
              example:
                setup_intent:
                  setup_intent_id: fseti_01J9XR8M3K7VZ8N2YB4WJ6T0RA
                  description: Premium SPF 50 mineral sunscreen
                  payment_method: fpm_01J9XR8M3K7VZ8N2YB4WJ6T0RA
                  partner_id: facct_01J9XR8M3K7VZ8N2YB4WJ6T0RA
                  metadata:
                    order_id: '8842'
                    channel: shopify
                  created_at: '2026-06-15T14:30:00Z'
                  test_mode: false
                  status: requires_payment_method
                  usage: off_session
                  subscription_id: fsub_01J9XR8M3K7VZ8N2YB4WJ6T0RA
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HttpErrorOut'
              example:
                code: string
                detail: string
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HttpErrorOut'
              example:
                code: string
                detail: string
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HttpErrorOut'
              example:
                code: string
                detail: string
        '409':
          description: Conflict
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HttpErrorOut'
              example:
                code: string
                detail: string
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
              example:
                detail:
                  - loc:
                      - string
                    msg: string
                    type: string
        '429':
          description: Too Many Requests
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HttpErrorOut'
              example:
                code: string
                detail: string
components:
  schemas:
    SetupIntentBody_for_CreateSetupIntent:
      description: An envelope wrapping a single setup intent object.
      type: object
      required:
        - setup_intent
      properties:
        setup_intent:
          $ref: '#/components/schemas/CreateSetupIntent'
          description: The SetupIntent.
      example:
        setup_intent:
          partner_id: facct_01J9XR8M3K7VZ8N2YB4WJ6T0RA
          checkout_session: fcs_01J9XR8M3K7VZ8N2YB4WJ6T0RA
    SetupIntentBody_for_SetupIntent:
      description: An envelope wrapping a single setup intent object.
      type: object
      required:
        - setup_intent
      properties:
        setup_intent:
          $ref: '#/components/schemas/SetupIntent'
          description: The SetupIntent.
      example:
        setup_intent:
          setup_intent_id: fseti_01J9XR8M3K7VZ8N2YB4WJ6T0RA
          description: Premium SPF 50 mineral sunscreen
          payment_method: fpm_01J9XR8M3K7VZ8N2YB4WJ6T0RA
          partner_id: facct_01J9XR8M3K7VZ8N2YB4WJ6T0RA
          metadata:
            order_id: '8842'
            channel: shopify
          created_at: '2026-06-15T14:30:00Z'
          test_mode: false
          status: requires_payment_method
          usage: off_session
          subscription_id: fsub_01J9XR8M3K7VZ8N2YB4WJ6T0RA
    HttpErrorOut:
      title: HttpError
      description: The error response returned when a request cannot be completed.
      type: object
      required:
        - code
        - detail
      properties:
        code:
          description: A short machine-readable error code identifying the type of error.
          type: string
        detail:
          description: A human-readable explanation of what went wrong.
          type: string
      example:
        code: string
        detail: string
    HTTPValidationError:
      description: The error response returned when request validation fails (HTTP 422).
      type: object
      required:
        - detail
      properties:
        detail:
          description: The list of validation errors, one entry per invalid field.
          type: array
          items:
            $ref: '#/components/schemas/ValidationErrorItem'
      example:
        detail:
          - loc:
              - string
            msg: string
            type: string
    CreateSetupIntent:
      description: >-
        Parameters for creating a SetupIntent to collect a customer's payment
        method details.
      type: object
      required:
        - checkout_session
        - partner_id
      properties:
        partner_id:
          description: ID of the account the SetupIntent is created for.
          type: string
          example: facct_01J9XR8M3K7VZ8N2YB4WJ6T0RA
        checkout_session:
          description: ID of the CheckoutSession the SetupIntent is associated with.
          type: string
          example: fcs_01J9XR8M3K7VZ8N2YB4WJ6T0RA
      example:
        partner_id: facct_01J9XR8M3K7VZ8N2YB4WJ6T0RA
        checkout_session: fcs_01J9XR8M3K7VZ8N2YB4WJ6T0RA
    SetupIntent:
      description: >-
        A SetupIntent represents your intent to set up a customer's payment
        method for future payments, without charging it immediately. Use it to
        collect and verify payment method details that can later be used
        off-session (for example, to bill a subscription or invoice).
      type: object
      required:
        - created_at
        - partner_id
        - setup_intent_id
        - status
        - test_mode
        - usage
      properties:
        setup_intent_id:
          description: The unique identifier for the object.
          type: string
          example: fseti_01J9XR8M3K7VZ8N2YB4WJ6T0RA
        client_secret:
          description: >-
            The client secret used to confirm this SetupIntent from your
            frontend. Present when the SetupIntent is retrieved or created;
            `null` when it appears in a list response. Treat it as sensitive: do
            not log or store it, and expose it only to the customer over TLS.
          type:
            - string
            - 'null'
        customer:
          description: >-
            The Customer this SetupIntent belongs to; returned as the ID by
            default and expandable to the full object.
          anyOf:
            - $ref: '#/components/schemas/Expandable_for_Customer'
            - type: 'null'
        description:
          description: An arbitrary string attached to the setup intent.
          type:
            - string
            - 'null'
          example: Premium SPF 50 mineral sunscreen
        payment_method:
          description: Payment method used with this SetupIntent.
          type:
            - string
            - 'null'
          example: fpm_01J9XR8M3K7VZ8N2YB4WJ6T0RA
        partner_id:
          description: The ID of the account this SetupIntent belongs to.
          type: string
          example: facct_01J9XR8M3K7VZ8N2YB4WJ6T0RA
        metadata:
          description: >-
            Set of key-value pairs that you can attach to an object. This can be
            useful for storing additional information about the object in a
            structured format.
          type:
            - object
            - 'null'
          additionalProperties:
            type: object
          example:
            order_id: '8842'
            channel: shopify
        created_at:
          $ref: '#/components/schemas/Timestamptz'
          description: Time at which the object was created. ISO 8601 format.
          example: '2026-06-15T14:30:00Z'
        test_mode:
          description: Whether or not the setup intent is in test mode.
          type: boolean
          example: false
        status:
          $ref: '#/components/schemas/Status2'
          description: The current status of the setup intent.
        usage:
          $ref: '#/components/schemas/Usage'
          description: >-
            Indicates how the payment method is intended to be used in the
            future.
        subscription_id:
          description: >-
            The ID of the Subscription this SetupIntent is associated with (for
            payment method updates).
          type:
            - string
            - 'null'
          example: fsub_01J9XR8M3K7VZ8N2YB4WJ6T0RA
      example:
        setup_intent_id: fseti_01J9XR8M3K7VZ8N2YB4WJ6T0RA
        customer: fcus_01J9XR8M3K7VZ8N2YB4WJ6T0RA
        description: Premium SPF 50 mineral sunscreen
        payment_method: fpm_01J9XR8M3K7VZ8N2YB4WJ6T0RA
        partner_id: facct_01J9XR8M3K7VZ8N2YB4WJ6T0RA
        metadata:
          order_id: '8842'
          channel: shopify
        created_at: '2026-06-15T14:30:00Z'
        test_mode: false
        status: requires_payment_method
        usage: off_session
        subscription_id: fsub_01J9XR8M3K7VZ8N2YB4WJ6T0RA
    ValidationErrorItem:
      description: >-
        Validation errors have their own schema to provide context for invalid
        requests eg. mismatched types and out of bounds values. There may be any
        number of these per 422 UNPROCESSABLE ENTITY error.
      type: object
      required:
        - loc
        - msg
        - type
      properties:
        loc:
          description: >-
            The location as a [`Vec`] of [`String`]s -- often in the form
            `["body", "field_name"]`, `["query", "field_name"]`, etc. They may,
            however, be arbitarily deep.
          type: array
          items:
            type: string
        msg:
          description: The message accompanying the validation error item.
          type: string
        type:
          description: >-
            The type of error, often "type_error" or "value_error", but
            sometimes with more context like as "value_error.number.not_ge"
          type: string
      example:
        loc:
          - string
        msg: string
        type: string
    Expandable_for_Customer:
      anyOf:
        - type: string
          example: fcus_01J9XR8M3K7VZ8N2YB4WJ6T0RA
        - $ref: '#/components/schemas/Customer'
      example: fcus_01J9XR8M3K7VZ8N2YB4WJ6T0RA
      description: An expandable field — either a string ID or an expanded Customer object.
    Timestamptz:
      description: >-
        A timestamp encoded as an RFC 3339 / ISO 8601 string (e.g.
        `2026-06-15T14:30:00Z`).
      type: string
      example: string
    Status2:
      description: The status of the setup intent.
      type: string
      enum:
        - requires_payment_method
        - requires_confirmation
        - requires_action
        - processing
        - succeeded
        - canceled
      example: requires_payment_method
    Usage:
      description: >-
        Whether the saved payment method is intended for off-session or
        on-session future payments.
      type: string
      enum:
        - off_session
        - on_session
      example: off_session
    Customer:
      description: >-
        A Customer object represents a customer of your business. Use it to
        track payments, store reusable payment methods, and reference the
        customer on checkout sessions, invoices, and subscriptions.
      type: object
      required:
        - created_at
        - customer_id
        - email
        - first_name
        - last_name
        - test_mode
      properties:
        customer_id:
          description: The unique identifier for the customer.
          type: string
          example: fcus_01HACM7FZ1084XB1GB6053VM0D
        owner_partner_id:
          description: >-
            The partner that owns this customer. When a customer is shared with
            you by another partner in your organization, this is that sibling
            partner; otherwise it is your own partner id.
          type:
            - string
            - 'null'
          example: obj_01J9XR8M3K7VZ8N2YB4WJ6T0RA
        first_name:
          description: The customer's first name.
          type: string
          example: John
        last_name:
          description: The customer's last name.
          type: string
          example: Doe
        email:
          description: The customer's email address.
          type: string
          format: email
          example: joh.doe@example.com
        phone:
          description: The customer's phone number.
          type:
            - string
            - 'null'
          format: phone
          example: '+15555555555'
        employer:
          description: The customer's employer.
          type:
            - string
            - 'null'
          example: Flex
        shipping:
          description: The customer's shipping address.
          anyOf:
            - $ref: '#/components/schemas/ShippingAddress'
            - type: 'null'
        metadata:
          description: Metadata associated with the customer.
          type:
            - object
            - 'null'
          additionalProperties:
            type: string
          example:
            order_id: '8842'
            channel: shopify
        created_at:
          $ref: '#/components/schemas/Timestamptz'
          description: The time the customer was created.
          example: '2026-06-15T14:30:00Z'
        test_mode:
          description: Whether the customer was created in test mode.
          type: boolean
          example: false
      example:
        customer_id: fcus_01HACM7FZ1084XB1GB6053VM0D
        owner_partner_id: obj_01J9XR8M3K7VZ8N2YB4WJ6T0RA
        first_name: John
        last_name: Doe
        email: joh.doe@example.com
        phone: '+15555555555'
        employer: Flex
        shipping:
          shipping_address_id: fsh_01J9XR8M3K7VZ8N2YB4WJ6T0RA
          line1: 123 Main St
          line2: Suite 100
          city: San Francisco
          state: CA
          postal_code: '94107'
          country: US
        metadata:
          order_id: '8842'
          channel: shopify
        created_at: '2026-06-15T14:30:00Z'
        test_mode: false
    ShippingAddress:
      description: >-
        A ShippingAddress represents the postal address a physical order is
        delivered to. It is referenced by checkout sessions and customers.
      type: object
      required:
        - shipping_address_id
      properties:
        shipping_address_id:
          description: Unique identifier for the shipping address.
          type: string
          example: fsh_01J9XR8M3K7VZ8N2YB4WJ6T0RA
        line1:
          description: The first line of the street address (e.g., street number and name).
          type:
            - string
            - 'null'
          example: 123 Main St
        line2:
          description: >-
            The second line of the street address (e.g., apartment, suite, or
            unit).
          type:
            - string
            - 'null'
          example: Suite 100
        city:
          description: City, district, suburb, town, or village.
          type:
            - string
            - 'null'
          example: San Francisco
        state:
          description: State, county, province, or region.
          type:
            - string
            - 'null'
          example: CA
        postal_code:
          description: ZIP or postal code.
          type:
            - string
            - 'null'
          example: '94107'
        country:
          description: Two-letter country code (ISO 3166-1 alpha-2, e.g., `US`).
          type:
            - string
            - 'null'
          example: US
      example:
        shipping_address_id: fsh_01J9XR8M3K7VZ8N2YB4WJ6T0RA
        line1: 123 Main St
        line2: Suite 100
        city: San Francisco
        state: CA
        postal_code: '94107'
        country: US
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: Use a Bearer token to access this API.

````