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

# Quote a gas-in-token fee

> Request a fee quote for paying Soroban gas in a token instead of XLM. The facilitator simulates the calls, prices the XLM fee as a token amount, and returns the quote including the `FeeForwarder` contract address and a ledger-based expiry.

The SDK uses this quote to build the `FeeForwarder.forward()` authorization entry before calling `POST /relay` with `feeToken` set.



## OpenAPI

````yaml /api-reference/openapi.json post /fee/quote
openapi: 3.1.0
info:
  title: Buckspay Facilitator & BFF API
  version: 0.2.0
  description: >-
    HTTP wire contract for the Buckspay SDK. The SDK calls these endpoints
    internally via `@buckspay/relayer`; this reference is for teams building
    their own BFF relay route or calling the facilitator from server-side code.


    All facilitator endpoints require the `x-api-key` header. **The API key is a
    server-side secret - it must only appear in BFF or server-side code and must
    never be shipped to a browser bundle.** Use `createRelayRoute` and
    `createSignerProxyRoute` from `@buckspay/nextjs` to build compliant BFF
    handlers.
servers:
  - url: '{facilitatorUrl}'
    description: >-
      Buckspay facilitator (all endpoints). Set via BUCKSPAY_FACILITATOR_URL on
      the server.
    variables:
      facilitatorUrl:
        default: https://facilitator.buckspay.xyz
        description: Base URL of the Buckspay facilitator service.
security:
  - FacilitatorApiKey: []
tags:
  - name: Relay
    description: >-
      Submit a signed Soroban authorization entry for gasless relaying to the
      Stellar network.
  - name: Fee
    description: >-
      Quote the fee-token amount required for gas-in-token (token gas mode)
      before building the forward() invocation.
  - name: Account State
    description: Read on-chain state for classic G-addresses and contract C-addresses.
  - name: Onboarding
    description: >-
      Build and submit the sponsored onboarding transaction; deploy passkey
      smart-accounts and policy session-accounts.
  - name: Auth
    description: >-
      Signer-proxy for social and email authentication. The BFF forwards these
      requests to the facilitator; provider secrets remain server-side.
  - name: Swap
    description: >-
      Quote a gasless EVM token swap. Requires `swapChain` to be configured in
      the relayer.
paths:
  /fee/quote:
    post:
      tags:
        - Fee
      summary: Quote a gas-in-token fee
      description: >-
        Request a fee quote for paying Soroban gas in a token instead of XLM.
        The facilitator simulates the calls, prices the XLM fee as a token
        amount, and returns the quote including the `FeeForwarder` contract
        address and a ledger-based expiry.


        The SDK uses this quote to build the `FeeForwarder.forward()`
        authorization entry before calling `POST /relay` with `feeToken` set.
      operationId: postFeeQuote
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/FeeQuoteRequest'
      responses:
        '200':
          description: Fee quote computed successfully.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FeeQuote'
        '400':
          description: The calls could not be simulated or the token is not supported.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error: simulation_failed
                message: could not simulate the provided calls
        '401':
          description: Invalid or missing API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error: unauthorized
        '502':
          description: Facilitator could not reach Stellar Horizon.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error: horizon_unreachable
components:
  schemas:
    FeeQuoteRequest:
      type: object
      required:
        - chain
        - from
        - token
        - calls
      properties:
        chain:
          $ref: '#/components/schemas/FacilitatorChain'
        from:
          allOf:
            - $ref: '#/components/schemas/StellarAddress'
          description: Payer address (G or C) whose account the fee will be deducted from.
        token:
          allOf:
            - $ref: '#/components/schemas/StellarContractAddress'
          description: Token contract address (USDC SAC) used to pay the gas fee.
        calls:
          type: array
          minItems: 1
          description: Calls to simulate for fee estimation.
          items:
            type: object
            required:
              - contract
              - fn
              - args
            properties:
              contract:
                allOf:
                  - $ref: '#/components/schemas/StellarContractAddress'
                description: Target contract address.
              fn:
                type: string
                description: Contract function name (e.g. `transfer`).
              args:
                type: array
                description: Soroban `ScVal` arguments serialized as base64 XDR strings.
                items:
                  allOf:
                    - $ref: '#/components/schemas/Base64'
                  description: One `ScVal` argument as base64 XDR.
      description: >-
        Request body for `POST /fee/quote`. Calls are simulated server-side to
        price the XLM fee as a token amount.
    FeeQuote:
      type: object
      required:
        - forwarder
        - collector
        - token
        - estimatedXlmFee
        - tokenAmount
        - expiresAtLedger
      properties:
        forwarder:
          allOf:
            - $ref: '#/components/schemas/StellarContractAddress'
          description: >-
            `FeeForwarder` contract address. The SDK uses this to build the
            `forward()` authorization entry.
        collector:
          allOf:
            - $ref: '#/components/schemas/StellarAddress'
          description: >-
            Address that collects the fee (G or C). Embedded in the `forward()`
            invocation.
        token:
          allOf:
            - $ref: '#/components/schemas/StellarContractAddress'
          description: Token used to pay the fee. Echoes the request `token`.
        estimatedXlmFee:
          allOf:
            - $ref: '#/components/schemas/Stroops'
          description: Estimated XLM fee in stroops.
        tokenAmount:
          allOf:
            - $ref: '#/components/schemas/Stroops'
          description: >-
            Fee expressed in the requested token's smallest unit (USDC stroops
            for USDC). The SDK passes this as the `fee_amount` argument in the
            `forward()` invocation.
        expiresAtLedger:
          type: integer
          minimum: 1
          description: >-
            Ledger sequence after which this quote expires. The SDK refuses to
            build a relay with an expired quote.
      description: >-
        Fee quote returned by `POST /fee/quote`. Mirrors the SDK `FeeQuote` type
        from `@buckspay/core`.
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          description: >-
            Machine-readable error code. SDK error codes (e.g.
            `RELAYER_REJECTED`, `SESSION_POLICY_VIOLATION`) or raw facilitator
            codes (e.g. `auth_expired`, `simulation_failed`) depending on
            context.
        message:
          type: string
          description: >-
            Optional human-readable detail. Never log raw upstream messages -
            they may contain addresses or sensitive information.
        details:
          type: object
          description: >-
            Optional structured validation errors (present on BFF-level schema
            failures).
      description: >-
        Error body returned on non-2xx responses. The `error` field maps to a
        `BuckspayErrorCode` or a raw facilitator error string (see
        `mapFacilitatorError` in `@buckspay/relayer`).
    FacilitatorChain:
      type: string
      enum:
        - stellar-testnet
        - stellar-pubnet
      description: Stellar network identifier used in facilitator requests.
    StellarAddress:
      type: string
      pattern: ^[GC][A-Z2-7]{55}$
      description: 'Stellar address: either a classic G-address or a contract C-address.'
    StellarContractAddress:
      type: string
      pattern: ^C[A-Z2-7]{55}$
      description: Stellar contract address (C-address, 56-character StrKey).
    Base64:
      type: string
      pattern: ^[A-Za-z0-9+/]+=*$
      minLength: 1
      description: Standard base64-encoded bytes.
    Stroops:
      type: string
      pattern: ^\d+$
      description: >-
        A non-negative integer encoded as a decimal string to preserve
        precision. For Stellar token amounts this is the smallest unit with the
        asset's implied decimals (USDC = 7, i.e. stroops); the same string
        encoding also carries fees, nonces, and EVM swap amounts (which use
        their own token's decimals).
  securitySchemes:
    FacilitatorApiKey:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        Server-held API key. Injected by the BFF (`createRelayRoute` /
        `createSignerProxyRoute` from `@buckspay/nextjs`). This key must only
        appear in server-side code and must never be shipped to a browser
        bundle.

````