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

# Create Swap

> API reference for POST /swap

<Info>
  We recommend using the [`/order`](/resources/trading-api/order/order) endpoint for new
  integrations. This endpoint is still available but `/order` is the preferred
  approach. For a code example, see the
  [Spot Quickstart](/spot/recipes/quickstart).
</Info>


## OpenAPI

````yaml POST /swap
openapi: 3.1.0
info:
  title: DFlow Aggregator
  description: DFlow Aggregator API
  license:
    name: BUSL-1.1
  version: 0.1.0
servers:
  - url: https://quote-api.dflow.net
security:
  - api_key: []
tags:
  - name: order
    description: Order API endpoints
  - name: swap
    description: Swap API endpoints
  - name: intent
    description: Intent trading endpoints
  - name: prediction_market
    description: Prediction market endpoints
  - name: venues
    description: Venue endpoints
  - name: tokens
    description: Token endpoints
paths:
  /swap:
    post:
      tags:
        - swap
      summary: Returns an imperative swap transaction for the given quote
      operationId: swap_handler
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SwapRequest'
        required: true
      responses:
        '200':
          description: Imperative swap transaction
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SwapResponse'
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SwapBadRequestResponse'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SwapInternalServerErrorResponse'
components:
  schemas:
    SwapRequest:
      type: object
      required:
        - userPublicKey
        - quoteResponse
      properties:
        computeUnitPriceMicroLamports:
          type: integer
          format: int64
          description: >-
            Compute unit price in micro-lamports. Mutually exclusive with
            `prioritizationFeeLamports`.
          minimum: 0
        createFeeAccount:
          $ref: '#/components/schemas/CreateFeeAccountParams'
          description: >-
            If the fee account isn't a referral token account derived from the
            seeds

            `["referral_ata", referral_account, mint]` and the Referral program
            ID

            `REFER4ZgmyYx9c6He5XfaTMiGfdLwRnkV4RPp9t9iF3`, this should be
            unspecified. If specified, the

            transaction will create the `fee_account` if it doesn't already
            exist. The user pays for the

            creation of the fee account. Ignored if `fee_account` is
            unspecified.
        destinationTokenAccount:
          $ref: '#/components/schemas/DestinationTokenAccountParam'
          description: >-
            The account that will receive the output token. If not specified,
            the user's associated

            token account for the output mint will be used. Allowed values are:

            - A base58-encoded address, which specifies the address of the
            destination token account or,
              if the output is native SOL, the destination wallet. If the output isn't native SOL, the
              specified account must exist before the swap executes, or else the swap will fail.
            - An object which specifies the owner of the destination token
            account. In this case, the
              owner's associated token account for the output mint will be used as the destination token
              account. Note that this cannot be used if the output is native SOL. The object contains
              the following:
                - `associatedTokenAccount` - object
                    - `owner` - base58-encoded address of the owner of the destination token account
        dynamicComputeUnitLimit:
          type: boolean
          description: >-
            If true, the server will simulate the transaction to determine its
            compute unit limit. If

            unspecified or false, the transaction will use the default compute
            unit limit.
        feeAccount:
          type: string
          description: >-
            Base58-encoded address of the token account that will receive the
            platform fee if a platform

            fee applies to the swap. If specified, this account's mint must
            match the fee mint for the

            swap.
        includeJitoSandwichMitigationAccount:
          $ref: '#/components/schemas/IncludeJitoSandwichMitigationAccount'
          description: >-
            If specified, the transaction will include a Jito sandwich
            mitigation account in the swap

            instruction. Allowed values are:

            - `true` - uses the default Jito sandwich mitigation account

            - `false` - does not include the account

            - A base58-encoded account address - uses the specified account


            If unspecified, the account is not included.

            See https://docs.jito.wtf/lowlatencytxnsend/#sandwich-mitigation for
            more details.
        outputCloseAuthority:
          type: string
          description: >-
            Base58-encoded address of the close authority to assign to the
            output token account. If

            specified, the swap instruction will idempotently initialize the
            output token account and

            set its close authority to the specified address. The action is a
            no-op if the output

            token account already exists at execution time.


            Cannot be used when the output mint is SOL (wrapped or native).
            Cannot be used with

            `destinationTokenAccount`.
        perLegSlippage:
          type: boolean
          description: >-
            If true or unspecified, per-leg slippage checks are enabled. If
            false, per-leg slippage

            checks are disabled.
        positiveSlippage:
          $ref: '#/components/schemas/PositiveSlippageParams'
          description: >-
            Positive slippage fee parameters. If specified, then the swap will
            pay some or all positive

            slippage to the specified account.
        prioritizationFeeLamports:
          $ref: '#/components/schemas/PrioritizationFeeLamports'
          description: >-
            Prioritization fee in lamports. Mutually exclusive with
            `computeUnitPriceMicroLamports`.

            If both `computeUnitPriceMicroLamports` and
            `prioritizationFeeLamports` are unspecified, the

            default of `prioritizationFeeLamports="auto"` will be used.

            Allowed values are:

            - a u32 which specifies the lamports

            - the string value "auto", where the server determines the fee
            automatically, capped at
              0.005 SOL
            - the string value "disabled", where the server leaves the
            prioritization fee unspecified

            - an object containing the following
                - `priorityLevelWithMaxLamports` - object
                    - `priorityLevel` - string, either `medium`, `high`, or `veryHigh`
                    - `maxLamports` - integer, a cap on the prioritization fee
            - an object containing the following
                - `autoMultiplier` - a u32 which specifies how much to multiply the automatically
                  determined fee by. The total prioritization fee will be capped at 0.005 SOL.
        quoteResponse:
          $ref: '#/components/schemas/QuoteResponse'
          description: The response from the quote endpoint
        sponsor:
          type: string
          description: >-
            Base58-encoded address of the sponsor's wallet. If specified, the
            sponsor will pay the

            transaction fee and for token account creation, and both the user
            and the sponsor must sign

            the swap transaction. This can be used to implement gasless swaps.
        sponsorExec:
          type: boolean
          description: >-
            If true, the sponsor will be the executor of the swap for sponsored
            swaps. If false, the

            user will be the executor of the swap for sponsored swaps. Default
            is true.
        userPublicKey:
          type: string
          description: Base58-encoded address of the swapper's wallet
        wrapAndUnwrapSol:
          type: boolean
          description: If false, the transaction will use wrapped SOL
    SwapResponse:
      type: object
      required:
        - swapTransaction
        - lastValidBlockHeight
        - prioritizationFeeLamports
        - computeUnitLimit
      properties:
        computeUnitLimit:
          type: integer
          format: int32
          description: Compute unit limit assigned to the transaction
          minimum: 0
        lastValidBlockHeight:
          type: integer
          format: int64
          description: The last block height at which the transaction is valid
          minimum: 0
        prioritizationFeeLamports:
          type: integer
          format: int64
          description: Prioritization fee in lamports
          minimum: 0
        prioritizationType:
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/PrioritizationType'
              description: Prioritization fee type for the transaction
        swapTransaction:
          type: string
          description: >-
            Base64-encoded swap transaction. The user must sign before sending
            it to Solana.
    SwapBadRequestResponse:
      type: object
      required:
        - msg
        - code
      properties:
        code:
          $ref: '#/components/schemas/SwapBadRequestCode'
        msg:
          type: string
      example:
        code: <enum<string>>
        msg: <string>
    SwapInternalServerErrorResponse:
      type: object
      required:
        - msg
        - code
      properties:
        code:
          $ref: '#/components/schemas/SwapInternalServerErrorCode'
        msg:
          type: string
      example:
        code: <enum<string>>
        msg: <string>
    CreateFeeAccountParams:
      type: object
      required:
        - referralAccount
      properties:
        referralAccount:
          type: string
          description: >-
            Base58-encoded address of the referral account associated with the
            fee account
    DestinationTokenAccountParam:
      oneOf:
        - type: object
          description: >-
            Use the specified owner's associated token account for the output
            mint as the destination

            token account. If the destination token account is uninitialized at
            swap execution time, the

            swap will create it. This cannot be used if the output is native
            SOL.
          required:
            - associatedTokenAccount
          properties:
            associatedTokenAccount:
              type: object
              description: >-
                Use the specified owner's associated token account for the
                output mint as the destination

                token account. If the destination token account is uninitialized
                at swap execution time, the

                swap will create it. This cannot be used if the output is native
                SOL.
              required:
                - owner
              properties:
                owner:
                  type: string
                  description: >-
                    Base58-encoded address of the owner of the destination token
                    account
        - type: object
          description: >-
            Use the specified base58-encoded address as the destination token
            account. The account must

            already be initialized at swap execution time or else the
            transaction will fail.
          required:
            - address
          properties:
            address:
              type: string
              description: >-
                Use the specified base58-encoded address as the destination
                token account. The account must

                already be initialized at swap execution time or else the
                transaction will fail.
    IncludeJitoSandwichMitigationAccount:
      oneOf:
        - type: boolean
        - type: string
    PositiveSlippageParams:
      type: object
      required:
        - limitPct
      properties:
        feeAccount:
          type: string
          description: >-
            Base58-encoded address of the token account that will receive the
            positive slippage fee.

            This must be a token account for the output mint, regardless of the
            platform fee mode. If at

            swap execution time this account can't receive the positive slippage
            fee, then the positive

            slippage fee transfer is skipped. If the platform fee mode is
            `outputMint` and the platform

            fee account is specified, then this must be unspecified (in which
            case the platform fee

            account will be used) or match the platform fee account. Otherwise,
            this must be specified.
        limitPct:
          type: integer
          format: int32
          description: >-
            Limit on the positive slippage fee in percent. The positive slippage
            fee is limited to the

            lesser of (1) the excess actual out amount above the quoted amount
            and (2) this percentage

            of the actual out amount after platform fee.
          minimum: 0
    PrioritizationFeeLamports:
      oneOf:
        - type: object
          description: >-
            A multiplier applied to the automatically-determined fee. The total
            is capped at 0.005 SOL.
          required:
            - autoMultiplier
          properties:
            autoMultiplier:
              type: integer
              format: int32
              description: >-
                A multiplier applied to the automatically-determined fee. The
                total is capped at 0.005 SOL.
              minimum: 0
        - type: object
          description: >-
            A variable prioritization fee determined by the server based on the
            specified priority level
          required:
            - priorityLevelWithMaxLamports
          properties:
            priorityLevelWithMaxLamports:
              type: object
              description: >-
                A variable prioritization fee determined by the server based on
                the specified priority level
              required:
                - priorityLevel
                - maxLamports
              properties:
                maxLamports:
                  type: integer
                  format: int32
                  description: >-
                    Maximum lamports to cap the prioritization fee determined by
                    the server
                  minimum: 0
                priorityLevel:
                  $ref: '#/components/schemas/PriorityLevel'
                  description: Priority level for the prioritization fee
        - type: string
          description: >-
            A variable prioritization fee determined by the server. The total is
            capped at 0.005 SOL.
          enum:
            - auto
        - type: object
          description: A fixed prioritization fee in lamports
          required:
            - lamports
          properties:
            lamports:
              type: integer
              format: int32
              description: A fixed prioritization fee in lamports
              minimum: 0
        - type: string
          description: Prioritization fee should be left unspecified
          enum:
            - disabled
    QuoteResponse:
      type: object
      required:
        - inputMint
        - inAmount
        - outputMint
        - outAmount
        - otherAmountThreshold
        - minOutAmount
        - slippageBps
        - priceImpactPct
        - routePlan
        - contextSlot
      properties:
        contextSlot:
          type: integer
          format: int64
          description: Slot at which the request was evaluated
          minimum: 0
        forJitoBundle:
          type: boolean
          description: True if and only if the request was for a Jito bundle
        inAmount:
          type: string
          description: >-
            Maximum input amount as a scaled integer. For example, 1 SOL is
            1000000000.
        inputMint:
          type: string
          description: Base58-encoded input mint address
        minOutAmount:
          type: string
          description: Same as `other_amount_threshold`
        otherAmountThreshold:
          type: string
          description: >-
            Minimum output amount after all fees as a scaled integer. If the
            swap transaction doesn't

            produce at least this amount of the output token, the transaction
            will fail.
        outAmount:
          type: string
          description: >-
            Expected output amount after all fees as a scaled integer. For
            example, 1 SOL is 1000000000.
        outTransferFee:
          type: string
          description: Transfer fee amount that was applied to the quote, if any
        outputMint:
          type: string
          description: Base58-encoded output mint address
        platformFee:
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/PlatformFee'
              description: Platform fee that was applied to the quote, if any
        priceImpactPct:
          type: string
          description: >-
            Price impact of the swap. This is an estimate of the percentage
            difference between the

            expected price for the swap and the price for the same swap with the
            smallest input amount

            possible. For example, "0.01" means 1% price impact.
        requestId:
          type: string
          description: Identifier for the request
        routePlan:
          type: array
          items:
            $ref: '#/components/schemas/RoutePlanLeg'
          description: Route that the swap will take
        routingSlot:
          type: integer
          format: int64
          description: Slot of the market state used to compute the quote
          minimum: 0
        simulatedComputeUnits:
          type: integer
          format: int32
          description: Compute units consumed by quote simulation
          minimum: 0
        skipPumpfunCashbackClaim:
          type: boolean
          description: >-
            True if and only if Pump.fun cashback claiming was skipped for this
            quote
        slippageBps:
          type: integer
          format: int32
          description: Max allowed slippage % in basis points
          minimum: 0
    PrioritizationType:
      oneOf:
        - type: object
          description: Prioritization fee specified via the compute budget program
          required:
            - computeBudget
          properties:
            computeBudget:
              type: object
              description: Prioritization fee specified via the compute budget program
              required:
                - microLamports
              properties:
                estimatedMicroLamports:
                  type:
                    - integer
                    - 'null'
                  format: int64
                  description: >-
                    Compute unit price estimated by the server for the
                    transaction
                  minimum: 0
                microLamports:
                  type: integer
                  format: int64
                  description: Compute unit price assigned to the transaction
                  minimum: 0
    SwapBadRequestCode:
      type: string
      enum:
        - invalid_out_amount
        - invalid_user_public_key
        - invalid_sponsor
        - sponsored_swap_cannot_create_fee_account
        - invalid_platform_fee_amount
        - invalid_fee_account
        - invalid_positive_slippage_fee_account
        - invalid_referral_account
        - invalid_destination_token_account
        - invalid_destination_token_account_for_native_sol
        - invalid_output_close_authority
        - output_close_authority_with_native_sol_output
        - output_close_authority_with_destination_token_account
        - both_priority_fee_params_specified
        - route_is_empty
        - route_too_long
        - invalid_route_plan_leg
        - invalid_jito_sandwich_mitigation_account
        - skip_pumpfun_cashback_claim_with_sponsor_executor
    SwapInternalServerErrorCode:
      type: string
      enum:
        - failed_to_compute_swap
    PriorityLevel:
      type: string
      enum:
        - medium
        - high
        - veryHigh
    PlatformFee:
      type: object
      required:
        - amount
        - feeBps
        - mode
      properties:
        amount:
          type: string
          description: >-
            Platform fee as a scaled integer. For example, 1 SOL is 1000000000.
            For output mint fees,

            this is the expected amount that will be paid, but the exact amount
            will vary depending on

            how much output the swap produces. For input mint fees, this is the
            exact amount that will

            be paid.
        feeBps:
          type: integer
          format: int32
          description: Platform fee in basis points
          minimum: 0
        mode:
          $ref: '#/components/schemas/PlatformFeeMode'
          description: Mode for the platform fee
    RoutePlanLeg:
      oneOf:
        - $ref: '#/components/schemas/DynamicRoutePlanLeg'
        - $ref: '#/components/schemas/SingleMarketRoutePlanLeg'
    PlatformFeeMode:
      type: string
      enum:
        - outputMint
        - inputMint
    DynamicRoutePlanLeg:
      type: object
      required:
        - venue
        - marketKey
        - data
        - inputMint
        - outputMint
        - inAmount
        - outAmount
        - inputMintDecimals
        - outputMintDecimals
      properties:
        data:
          type: string
          description: Data for the leg
        inAmount:
          type: string
          description: >-
            Maximum input amount for the leg as a scaled integer. For example, 1
            SOL is 1000000000.
        inputMint:
          type: string
          description: Base58-encoded input mint address
        inputMintDecimals:
          type: integer
          format: int32
          description: Decimals for the input mint
          minimum: 0
        marketKey:
          type: string
          description: Key identifying the market on the venue
        outAmount:
          type: string
          description: >-
            Expected output amount for the leg as a scaled integer. For example,
            1 SOL is 1000000000.
        outputMint:
          type: string
          description: Base58-encoded output mint address
        outputMintDecimals:
          type: integer
          format: int32
          description: Decimals for the output mint
          minimum: 0
        venue:
          type: string
          description: Venue for the leg
    SingleMarketRoutePlanLeg:
      type: object
      required:
        - venue
        - marketKey
        - inputMint
        - outputMint
        - inAmount
        - outAmount
        - inputMintDecimals
        - outputMintDecimals
      properties:
        inAmount:
          type: string
          description: >-
            Maximum input amount for the leg as a scaled integer. For example, 1
            SOL is 1000000000.
        inputMint:
          type: string
          description: Base58-encoded input mint address
        inputMintDecimals:
          type: integer
          format: int32
          description: Decimals for the input mint
          minimum: 0
        marketKey:
          type: string
          description: Key identifying the market on the venue
        outAmount:
          type: string
          description: >-
            Expected output amount for the leg as a scaled integer. For example,
            1 SOL is 1000000000.
        outputMint:
          type: string
          description: Base58-encoded output mint address
        outputMintDecimals:
          type: integer
          format: int32
          description: Decimals for the output mint
          minimum: 0
        venue:
          type: string
          description: Venue for the leg
  securitySchemes:
    api_key:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        API key for authentication. Contact hello@dflow.net to obtain an API
        key.

````