> 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/resources/ai-llm-integration.md).

# AI / LLM Integration

Integrate Titan swap functionality into AI agents and LLM-powered applications.

**Use Titan's swap infrastructure from AI agents, LLM tool-calling workflows, and autonomous trading systems.**

***

## Which endpoint and credential

Titan has two access paths with different hosts, credentials and protocols. Agents implementing a Titan integration should determine the path first, from the credential the user holds.

| Credential held                       | Path                                                                  | Host                                                                                               | Protocol                                         | Auth header                                    | Encoding                                                     |
| ------------------------------------- | --------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | ------------------------------------------------ | ---------------------------------------------- | ------------------------------------------------------------ |
| API key from developer.titan.exchange | Developers Portal                                                     | `portal.api.titan.exchange`                                                                        | REST, `GET` only                                 | `x-api-key: <key>`                             | JSON with `Accept: application/json`; MessagePack by default |
| JWT from Triton or QuickNode          | Distributor                                                           | Base URL supplied by the distributor; `/api/v1/ws` for Titan Direct, `/api/v1/*` for Titan Gateway | WebSocket (Titan Direct) or REST (Titan Gateway) | `Authorization: Bearer <jwt>` or `?auth=<jwt>` | MessagePack                                                  |
| DART API key                          | [DART Swap API](/titan/developer-doc/dart-swap-api/get-api-access.md) | `api.titan.exchange/dart`                                                                          | REST                                             | `X-API-Key: <key>`                             | JSON                                                         |

| Rule                                    | Detail                                                                                                                                                             |
| --------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Credentials are not interchangeable     | A JWT sent to the Portal host, or an API key sent to a distributor endpoint, returns `401`. DART keys and Portal keys are separate credentials for separate hosts. |
| The Portal has no WebSocket             | `/api/v1/ws` does not exist on `portal.api.titan.exchange`. Streaming (Titan Direct) is enterprise-only and requires a distributor JWT.                            |
| The Portal has no `/api/v1/quote/price` | Four endpoints only: `/api/v1/quote/swap`, `/api/v1/info`, `/api/v1/venues`, `/api/v1/providers`.                                                                  |
| Parameters are flat on the Portal       | `swap.dexes: [...]` in the Direct schema becomes `?dexes=a,b` on the Portal. Same names, same semantics.                                                           |
| Route selection                         | Read `metadata.ExpectedWinner` and execute `quotes[ExpectedWinner]`. Do not sort by `outAmount`.                                                                   |
| `quotes` is an object                   | Keyed by provider ID. `quotes[0]` is undefined.                                                                                                                    |

The Claude Code skill below targets the distributor path — Titan Direct over WebSocket. For Portal integrations, the [Developers Portal Quickstart](/titan/developer-doc/developers-portal/quickstart.md) contains a complete, tested REST example.

***

## Claude Code Skill

**The fastest way to build Titan integrations with AI.** The `@titanexchange/titan-api-skill` package gives Claude Code protocol-aware code generation for the Titan API.

* **Package:** [@titanexchange/titan-api-skill](https://www.npmjs.com/package/@titanexchange/titan-api-skill)
* **Source:** [github.com/Titan-Pathfinder/titan-api-claude-skills](https://github.com/Titan-Pathfinder/titan-api-claude-skills)

### What it provides

* **Protocol-aware code generation** — Generates TypeScript with correct MessagePack encoding, BigInt amounts, and bs58-decoded token mints matching the Titan WebSocket API spec.
* **SDK and raw WebSocket support** — Covers both SDK-based and direct WebSocket integration depending on developer needs.
* **Parameter structure enforcement** — Places fields like `slippageBps`, `intervalMs`, and `num_quotes` in their correct nested objects matching the expected request schema.
* **Runnable examples included** — Ships with working TypeScript examples that can be executed directly.

### Installation

**npx (recommended):**

```bash
# For current project
npx @titanexchange/titan-api-skill

# For all projects (global)
npx @titanexchange/titan-api-skill --global

# Overwrite existing install
npx @titanexchange/titan-api-skill --force
```

Then type `/titan-swap-api` in Claude Code to use the skill.

**Manual install (curl):**

```bash
# Global
mkdir -p ~/.claude/skills/titan-swap-api
curl -o ~/.claude/skills/titan-swap-api/SKILL.md \
  https://raw.githubusercontent.com/Titan-Pathfinder/titan-api-claude-skills/main/SKILL.md

# Project-level
mkdir -p .claude/skills/titan-swap-api
curl -o .claude/skills/titan-swap-api/SKILL.md \
  https://raw.githubusercontent.com/Titan-Pathfinder/titan-api-claude-skills/main/SKILL.md
```

### Quick example

Ask Claude Code:

> "Help me stream USDC to SOL quotes using Titan API"

Claude will generate protocol-correct code:

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

const client = await V1Client.connect(`${WS_URL}?auth=${AUTH_TOKEN}`);

const { stream } = await client.newSwapQuoteStream({
  swap: {
    inputMint: bs58.decode("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),
    outputMint: bs58.decode("So11111111111111111111111111111111111111112"),
    amount: BigInt(100_000_000), // 100 USDC — must be BigInt
  },
  transaction: {
    userPublicKey: bs58.decode(USER_PUBLIC_KEY),
  },
});

for await (const quotes of stream) {
  console.log(quotes);
}
```

### Runnable examples

The `/examples` directory contains working TypeScript examples:

```bash
cd examples
npm install
cp .env.example .env
# Edit .env with your credentials

npm run stream-sdk   # SDK streaming
npm run stream-raw   # Raw WebSocket
npm run proxy        # Backend proxy
```

### Required credentials

* **`WS_URL`** — Titan Direct WebSocket endpoint, supplied by your distributor.
* **`AUTH_TOKEN`** — Distributor-issued JWT. See [Get API Access](/titan/developer-doc/getting-started/api-access.md).

A Developers Portal API key does not work with this skill. The Portal is REST only.

***

## LLM-friendly docs (llms.txt)

**Titan's documentation is automatically available in LLM-optimized formats** via the [llms.txt](https://llmstxt.org/) standard. AI agents and LLMs can ingest the full docs without scraping HTML.

* **`/llms.txt`** — Index of all doc sections with links to individual pages in Markdown format.
* **`/llms-full.txt`** — The entire documentation as a single Markdown file — ideal for full-context ingestion.
* **Every page as `.md`** — Append `.md` to any doc page URL to get the raw Markdown version.

{% hint style="info" %}
These endpoints are **generated automatically by GitBook** and stay up-to-date with every publish. No configuration needed.
{% endhint %}

***

## Protocol summary

### Titan Direct (distributor, WebSocket)

* **Protocol** — WebSocket + MessagePack (not JSON).
* **Amounts** — Must be `BigInt`, not `number`.
* **Token mints** — Must be `Uint8Array` via `bs58.decode()`.
* **Parameters** — `slippageBps` goes in `swap`; `numQuotes`, `intervalMs` and `includeAltContents` go in `update`; `userPublicKey` goes in `transaction`.

### Developers Portal (API key, REST)

* **Protocol** — HTTPS `GET`. Set `Accept: application/json` for JSON; the default is MessagePack.
* **Amounts** — Decimal strings in the query string, in the token's smallest unit.
* **Token mints** — base58 strings in the query string.
* **Parameters** — Flat query parameters. Lists are comma-separated.
* **Instructions** — Returned with short field names: `p` (program), `a` (accounts), `d` (data, base64).

***

## Related pages

* [Developers Portal Quickstart](/titan/developer-doc/developers-portal/quickstart.md) — REST integration with an API key
* [Developers Portal API Reference](/titan/developer-doc/developers-portal/reference.md) — Flat query parameters and response fields
* [SDK Reference](/titan/developer-doc/resources/sdk.md) — TypeScript and Rust SDK documentation
* [Connection & Negotiation](/titan/developer-doc/swap-api/reference/direct/connection.md) — WebSocket setup and protocol details
* [Quickstart](/titan/developer-doc/swap-api/quickstart.md) — Titan Direct integration example
