> For the complete documentation index, see [llms.txt](https://titan-exchange.gitbook.io/titan/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://titan-exchange.gitbook.io/titan/developer-doc/swap-api/reference/direct/get-swap-price.md).

# GetSwapPrice

**Returns a price quote without instructions or transaction data.** Use it when you need to display prices in a UI without the overhead of building executable transactions — lighter weight than `NewSwapQuoteStream`.

This is a one-shot request, not a stream. The server finds the best direct route and uses the simulated output to determine the price.

## Request

{% tabs %}
{% tab title="Rust" %}

```rust
struct SwapPriceRequest {
  /// Address of the input mint of the swap.
  inputMint: Pubkey,
  /// Address of the desired output token for the swap.
  outputMint: Pubkey,
  /// Raw number of tokens to swap, not scaled by decimals.
  amount: u64,
  /// If set, constrain quotes to the given set of DEXes.
  dexes: Option<Vec<String>>,
  /// If set, exclude the following DEXes when determining routes.
  excludeDexes: Option<Vec<String>>,
}
```

{% endtab %}

{% tab title="TypeScript" %}

```typescript
interface SwapPriceRequest {
  // Address of the input mint.
  inputMint: Pubkey;
  // Address of the output mint.
  outputMint: Pubkey;
  // Raw number of tokens to swap. Use BigInt.
  amount: number | bigint;
  // If set, constrain to these DEXes.
  dexes?: string[];
  // If set, exclude these DEXes.
  excludeDexes?: string[];
}
```

{% endtab %}
{% endtabs %}

## Response

{% tabs %}
{% tab title="Rust" %}

```rust
struct SwapPrice {
  /// Identifier for this price quote.
  id: String,
  /// Address of the input mint.
  inputMint: Pubkey,
  /// Address of the output mint.
  outputMint: Pubkey,
  /// Amount that was used for the price.
  amountIn: u64,
  /// The amount out of the best simulated quote.
  amountOut: u64,
}
```

{% endtab %}

{% tab title="TypeScript" %}

```typescript
interface SwapPrice {
  // Identifier for this price quote.
  id: string;
  // Address of the input mint.
  inputMint: Pubkey;
  // Address of the output mint.
  outputMint: Pubkey;
  // Amount used for pricing.
  amountIn: number | bigint;
  // Best simulated output amount.
  amountOut: number | bigint;
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**The response does not include `instructions`, `addressLookupTables`, or any transaction data.** To get executable swap data, use [NewSwapQuoteStream](/titan/developer-doc/swap-api/reference/direct/new-swap-quote-stream.md) or the Gateway [Quote Swap](/titan/developer-doc/swap-api/reference/gateway/gateway-quote-swap.md) endpoint.
{% endhint %}

## Example

```typescript
import WebSocket from 'ws';
// highlight-next-line
import { Encoder, Decoder } from '@msgpack/msgpack';
import { compressSync, decompressSync } from 'fflate';       // zstd-compatible deflate
import bs58 from 'bs58';

// --- Encoder / Decoder with BigInt support for u64 fields ---
// highlight-start
const encoder = new Encoder({ useBigInt64: true });
const decoder = new Decoder({ useBigInt64: true });
// highlight-end

// Connect with zstd sub-protocol for compressed frames
const url = `${process.env.TITAN_ENDPOINT}?auth=${process.env.TITAN_API_KEY}`;
// highlight-next-line
const ws = new WebSocket(url, ['v1.api.titan.ag+zstd', 'v1.api.titan.ag']);

let requestId = 0;

// Pubkeys as 32-byte binary — MessagePack sends these as raw bytes
const SOL  = bs58.decode('So11111111111111111111111111111111111111112');
const USDC = bs58.decode('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');

/** Encode, optionally compress, and send a request frame. */
function sendRequest(ws: WebSocket, id: number, data: Record<string, unknown>) {
  // highlight-next-line
  const payload = encoder.encode({ id, data });

  // If the server negotiated the +zstd sub-protocol, compress before sending
  const frame =
    ws.protocol === 'v1.api.titan.ag+zstd'
      ? compressSync(new Uint8Array(payload))
      : payload;

  ws.send(frame);
}

/** Decompress (if needed) and decode an incoming frame. */
function decodeMessage(raw: Buffer): any {
  const bytes =
    ws.protocol === 'v1.api.titan.ag+zstd'
      ? decompressSync(new Uint8Array(raw))
      : raw;

  // highlight-next-line
  return decoder.decode(bytes);
}

ws.on('open', () => {
  // Request a price-only quote — no transaction data returned
  sendRequest(ws, requestId++, {
    GetSwapPrice: {
      inputMint: SOL,
      outputMint: USDC,
      amount: 1_000_000_000n, // 1 SOL in lamports
    },
  });
});

ws.on('message', async (raw: Buffer) => {
  const msg = decodeMessage(raw);

  // highlight-start
  // Price response — use amountOut for display
  if ('Response' in msg && 'GetSwapPrice' in msg.Response.data) {
    const price = msg.Response.data.GetSwapPrice;
    console.log('Output amount:', price.amountOut);   // BigInt
    ws.close();
  }
  // highlight-end

  if ('Error' in msg) {
    console.error(`Error ${msg.Error.code}: ${msg.Error.message}`);
    ws.close();
  }
});
```

See [Connection & Negotiation](/titan/developer-doc/swap-api/reference/direct/connection.md#sending-a-request) for `sendRequest` and `decodeMessage` setup.

***

## Related pages

* [NewSwapQuoteStream](/titan/developer-doc/swap-api/reference/direct/new-swap-quote-stream.md) — full quote with executable instructions
* [Gateway Quote Price](/titan/developer-doc/swap-api/reference/gateway/gateway-quote-price.md) — REST equivalent
* [Configure Routing](/titan/developer-doc/swap-api/guides/configure-routing.md) — venue filtering with `dexes` and `excludeDexes`
