> ## 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.

# Add Priority Fees

> How to set priority fees for Trading API requests

<Info>
  During development, you can use the [developer endpoints](/get-started/endpoints) without
  an API key. For production use, you'll need an [API key](/get-started/api-key) to avoid
  rate limits.
</Info>

Priority fees only affect **when** a trade executes. They do not change routing,
slippage checks, or trade semantics ([what priority fees do not affect](/spot/trading/priority-fees#what-priority-fees-do-not-affect)).

[How DFlow handles priority fees](/spot/trading/priority-fees#how-dflow-handles-priority-fees) details the two modes.

<Steps>
  <Step title="Set up">
    Imports, env config, and the constants used across every step.

    <AccordionGroup>
      <Accordion title="Imports, env, and constants">
        ```typescript theme={null}
        import "dotenv/config";

        import { Keypair } from "@solana/web3.js";
        import bs58 from "bs58";

        const DFLOW_TRADE_API_URL = process.env.DFLOW_TRADE_API_URL ?? "https://dev-quote-api.dflow.net";
        const DFLOW_API_KEY = process.env.DFLOW_API_KEY; // optional; not needed for dev endpoints
        const DFLOW_SETTLEMENT_MINT = process.env.DFLOW_SETTLEMENT_MINT ?? "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"; // USDC

        const SOL_MINT = "So11111111111111111111111111111111111111112";
        const amount = 1_000_000; // 0.001 SOL

        const keypair = Keypair.fromSecretKey(
          bs58.decode(process.env.SOLANA_PRIVATE_KEY ?? "")
        );

        const headers: HeadersInit = {};
        if (DFLOW_API_KEY) headers["x-api-key"] = DFLOW_API_KEY;
        ```
      </Accordion>
    </AccordionGroup>
  </Step>

  <Step title="Choose your priority fee mode">
    Use [max priority fee](/spot/trading/priority-fees#max-priority-fee) for adaptive speed
    (server selects a fee up to your cap), or [exact priority fee](/spot/trading/priority-fees#exact-priority-fee)
    when you need predictable costs.
  </Step>

  <Step title="Apply priority fees to your request">
    Set `prioritizationFeeLamports` on the `/order` request as either a lamport
    value or one of `auto`, `medium`, `high`, `veryHigh`, `disabled`.

    <AccordionGroup>
      <Accordion title="Max Priority Fee (auto/level)">
        ```typescript theme={null}
        const maxParams = new URLSearchParams();
        maxParams.append("inputMint", SOL_MINT);
        maxParams.append("outputMint", DFLOW_SETTLEMENT_MINT);
        maxParams.append("amount", amount.toString());
        maxParams.append("userPublicKey", keypair.publicKey.toBase58());
        maxParams.append("slippageBps", "50");
        maxParams.append("transactionVersion", "v1");

        // Adaptive fee chosen by the server.
        maxParams.append("prioritizationFeeLamports", "high");
        // Or use automatic selection:
        // maxParams.append("prioritizationFeeLamports", "auto");

        const maxOrderResponse = await fetch(
          `${DFLOW_TRADE_API_URL}/order?${maxParams.toString()}`,
          { headers }
        ).then((x) => x.json());
        ```
      </Accordion>

      <Accordion title="Exact Priority Fee (lamports)">
        ```typescript theme={null}
        const exactParams = new URLSearchParams();
        exactParams.append("inputMint", SOL_MINT);
        exactParams.append("outputMint", DFLOW_SETTLEMENT_MINT);
        exactParams.append("amount", amount.toString());
        exactParams.append("userPublicKey", keypair.publicKey.toBase58());
        exactParams.append("slippageBps", "50");
        exactParams.append("transactionVersion", "v1");

        // Fixed priority fee in lamports.
        exactParams.append("prioritizationFeeLamports", "20000");

        const exactOrderResponse = await fetch(
          `${DFLOW_TRADE_API_URL}/order?${exactParams.toString()}`,
          { headers }
        ).then((x) => x.json());
        ```
      </Accordion>
    </AccordionGroup>
  </Step>
</Steps>

## Related Resources

<CardGroup cols={2}>
  <Card title="Priority Fees" href="/spot/trading/priority-fees" icon="bolt">
    How priority fees and the fee budget work, and when to use each mode.
  </Card>

  <Card title="Send Orders" href="/spot/recipes/quickstart" icon="rocket">
    Send a spot order end-to-end.
  </Card>

  <Card title="Add Platform Fees" href="/spot/recipes/platform-fees" icon="percent">
    Monetize trades with builder fees.
  </Card>

  <Card title="Authenticate Requests" href="/resources/recipes/api-keys" icon="key">
    Authenticate requests for production rate limits.
  </Card>
</CardGroup>

## API Routes

* [GET /order](/resources/trading-api/order/order)
