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

# Create Trade V2 Swap Transaction

> Build the unsigned swap transaction for a previously fetched `trade/v2/quote`. Loads the cached quote by `requestId`, enforces that `userPublicKey` matches the quote's `taker`, and assembles a v0 transaction containing the provider instructions, the Bags treasury fee transfer, an optional tracking transfer, and address lookup tables.

The fee transfer is a native SOL transfer when `feeMint` is SOL, otherwise an idempotent treasury token account creation plus a checked SPL transfer against the mint's own token program (Token or Token-2022). The taker pays a small amount of rent the first time a given fee mint is collected; the idempotent instruction is a no-op afterward.



## OpenAPI

````yaml POST /trade/v2/swap
openapi: 3.1.0
info:
  title: Bags Public API v2
  description: API endpoints for Bags platform
  version: 2.0.0
  contact:
    name: Bags Support
    url: https://support.bags.fm
servers:
  - url: https://public-api-v2.bags.fm/api/v1
    description: Production server
security:
  - ApiKeyAuth: []
tags:
  - name: Token Launch
    description: Endpoints for creating and managing token launches
  - name: Fee Share
    description: Endpoints for managing fee sharing configs
  - name: Fee Share Admin
    description: >-
      Endpoints for fee share admin operations including listing, transferring
      admin authority, and updating configs
  - name: Analytics
    description: Endpoints for retrieving token analytics and metadata
  - name: Fee Claiming
    description: Endpoints for claiming fees from various sources
  - name: State
    description: Endpoints for retrieving on-chain state and derived state
  - name: Trade
    description: Endpoints for getting trade quotes and executing token swaps
  - name: Partner
    description: Endpoints for managing partner configurations and claiming partner fees
  - name: Solana
    description: Endpoints for direct Solana blockchain interactions
  - name: EVM
    description: Endpoints for reading Bags EVM token data
  - name: Robinhood Chain
    description: Read endpoints for Bags V2 tokens on Robinhood Chain (chain id 4663)
  - name: Dexscreener
    description: >-
      Endpoints for managing Dexscreener token info orders, payments, and image
      uploads
  - name: Auth
    description: Endpoints for retrieving authenticated user information
  - name: Agent
    description: Endpoints for AI agent wallet-signature authentication (V2)
paths:
  /trade/v2/swap:
    post:
      tags:
        - Trade
      summary: Create trade v2 swap transaction
      description: >-
        Build the unsigned swap transaction for a previously fetched
        `trade/v2/quote`. Loads the cached quote by `requestId`, enforces that
        `userPublicKey` matches the quote's `taker`, and assembles a v0
        transaction containing the provider instructions, the Bags treasury fee
        transfer, an optional tracking transfer, and address lookup tables.


        The fee transfer is a native SOL transfer when `feeMint` is SOL,
        otherwise an idempotent treasury token account creation plus a checked
        SPL transfer against the mint's own token program (Token or Token-2022).
        The taker pays a small amount of rent the first time a given fee mint is
        collected; the idempotent instruction is a no-op afterward.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateTradeV2SwapRequest'
      responses:
        '200':
          description: Successfully created trade v2 swap transaction
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/SuccessResponse'
                  - type: object
                    properties:
                      response:
                        $ref: '#/components/schemas/TradeV2SwapTransactionResponse'
        '400':
          description: >-
            Bad request - Quote not found or expired, public key does not match
            quote, invalid parameters, or the taker wallet cannot hold a token
            account for the fee mint
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Unauthorized - Invalid or missing API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '502':
          description: >-
            Bad gateway - Failed to resolve the fee mint's token
            program/decimals, or a provider failure
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    CreateTradeV2SwapRequest:
      type: object
      properties:
        requestId:
          type: string
          description: UUID of a previously fetched trade/v2/quote response
        userPublicKey:
          type: string
          description: >-
            Public key of the wallet that will sign the swap; must match the
            quote's taker
      required:
        - requestId
        - userPublicKey
    SuccessResponse:
      type: object
      properties:
        success:
          type: boolean
          example: true
        response:
          description: ''
      required:
        - success
    TradeV2SwapTransactionResponse:
      type: object
      properties:
        swapTransaction:
          type: string
          description: Unsigned v0 transaction, base58-encoded
        computeUnitLimit:
          type: number
          description: Compute unit limit for the transaction
        prioritizationFeeLamports:
          type: number
          description: Prioritization fee in lamports
        lastValidBlockHeight:
          type: number
          description: Last valid block height for the transaction
        feeMint:
          type: string
          description: Mint the fee is charged in
        feeSide:
          type: string
          enum:
            - input
            - output
          description: >-
            Which leg pays the fee: 'input' is deducted from amount before the
            quote, 'output' is skimmed from the quoted proceeds
        feeLamports:
          type: string
          description: >-
            Total Bags fee in raw base units of feeMint as string to support
            bigint (only lamports when feeMint is native SOL)
        revenueLamports:
          type: string
          description: >-
            Treasury share of the fee in raw base units of feeMint as string to
            support bigint (equals feeLamports; the fee is treasury-only)
        provider:
          type: string
          enum:
            - jupiter
            - titan
          description: Provider that built the transaction
      required:
        - swapTransaction
        - computeUnitLimit
        - prioritizationFeeLamports
        - lastValidBlockHeight
        - feeMint
        - feeSide
        - feeLamports
        - revenueLamports
        - provider
    ErrorResponse:
      type: object
      properties:
        success:
          type: boolean
          example: false
        error:
          type: string
          description: Error message
      required:
        - success
        - error
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: API key authentication. Provide your API key as the header value.

````