> 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/quickstart.md).

# Quickstart

{% hint style="info" %}
You'll need an API token and endpoint URL before starting. See [Get API Access](/titan/developer-doc/getting-started/api-access.md) if you don't have one yet.
{% endhint %}

This is a minimal example to get your first quote from the Titan API. For a complete integration with transaction building, signing, and error handling, see [Stream & Execute a Swap](/titan/developer-doc/swap-api/guides/stream-and-execute.md).

Titan has two integration paths. **Titan Direct** uses WebSocket and streams live quotes continuously. **Titan Gateway** uses REST and returns a single set of quotes per request. Both deliver the same quote quality.

{% hint style="info" %}
Swap quote requests require a `userPublicKey` — a valid Solana wallet address. The server uses it to build transaction instructions scoped to that wallet.
{% endhint %}

The [`@titanexchange/sdk-ts`](/titan/developer-doc/resources/sdk.md) SDK supports Titan Direct (WebSocket) only.

{% tabs %}
{% tab title="Titan Direct" %}
{% stepper %}
{% step %}

#### Install the SDK

```bash
npm install @titanexchange/sdk-ts bs58
```

{% endstep %}

{% step %}

#### Set your credentials

```bash
export TITAN_ENDPOINT="wss://YOUR_ENDPOINT/api/v1/ws"
export TITAN_API_KEY="YOUR_API_TOKEN"
```

{% endstep %}

{% step %}

#### Connect and get a quote

```typescript
import { V1Client } from '@titanexchange/sdk-ts';
import bs58 from 'bs58';

const client = await V1Client.connect(
  `${process.env.TITAN_ENDPOINT}?auth=${process.env.TITAN_API_KEY}`
);

const { stream } = await client.newSwapQuoteStream({
  swap: {
    inputMint: bs58.decode('So11111111111111111111111111111111111111112'),
    outputMint: bs58.decode('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'),
    amount: BigInt(1_000_000_000), // 1 SOL in lamports
    slippageBps: 50,
  },
  transaction: {
    userPublicKey: bs58.decode('YOUR_WALLET_PUBLIC_KEY'),
  },
});

for await (const update of stream) {
  const quotes = update.quotes;
  if (!Object.keys(quotes).length) continue;

  for (const [provider, route] of Object.entries(quotes as Record<string, any>)) {
    console.log(`${provider}: ${route.outAmount} out`);
  }

  break; // First update received — stop here
}

await client.close();
```

{% endstep %}
{% endstepper %}
{% endtab %}

{% tab title="Titan Gateway" %}
{% stepper %}
{% step %}

#### Install dependencies

```bash
npm install @msgpack/msgpack
```

{% endstep %}

{% step %}

#### Set your credentials

```bash
export TITAN_ENDPOINT="https://YOUR_ENDPOINT"
export TITAN_API_KEY="YOUR_API_TOKEN"
```

{% endstep %}

{% step %}

#### Request a quote

```typescript
import { decode } from '@msgpack/msgpack';

const params = new URLSearchParams({
  inputMint: 'So11111111111111111111111111111111111111112',
  outputMint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
  amount: '1000000000', // 1 SOL in lamports
  userPublicKey: 'YOUR_WALLET_PUBLIC_KEY',
  slippageBps: '50',
});

const res = await fetch(
  `${process.env.TITAN_ENDPOINT}/api/v1/quote/swap?${params}`,
  {
    headers: {
      'Authorization': `Bearer ${process.env.TITAN_API_KEY}`,
      'Accept': 'application/vnd.msgpack',
    },
  }
);

if (!res.ok) throw new Error(`${res.status}: ${res.statusText}`);

const data = decode(new Uint8Array(await res.arrayBuffer())) as any;

for (const [provider, route] of Object.entries(data.quotes as Record<string, any>)) {
  console.log(`${provider}: ${route.outAmount} out`);
}
```

{% endstep %}
{% endstepper %}
{% endtab %}
{% endtabs %}

## What a quote looks like

The response contains a `quotes` map keyed by provider ID — `"Titan"`, `"Metis"`, `"Okx"`, etc. Each entry is a `SwapRoute` with everything you need to build and send a transaction:

* **`inAmount`** / **`outAmount`** — the input and output amounts for this route.
* **`slippageBps`** — the slippage tolerance applied to this quote.
* **`computeUnitsSafe`** — recommended compute budget that accounts for on-chain variance.
* **`instructions`** — the swap instructions to include in your transaction.
* **`addressLookupTables`** — ALT addresses needed to compile a V0 transaction.
* **Quote expiry** — if a route expires, `expiresAtMs` contains the expiry as a millisecond UNIX timestamp and `expiresAfterSlot` contains the last valid slot. Check these before executing if present.

Not every provider appears in every response. Iterate with `Object.entries(quotes)` and pick the route with the best `outAmount`.

## Next steps

* [Stream & Execute a Swap](/titan/developer-doc/swap-api/guides/stream-and-execute.md) — full guide with transaction building, signing, and error handling
* [Configure Routing](/titan/developer-doc/swap-api/guides/configure-routing.md) — filter venues and providers, set account limits
* [Authentication](/titan/developer-doc/getting-started/authentication.md) — JWT claims reference
