# AI / LLM Integration

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

***

## 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 WebSocket endpoint.
* **`AUTH_TOKEN`** — API authentication token. See [Get API Access](/titan/developer-doc/getting-started/api-access.md).

***

## 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 %}

***

## Key things to know

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

***

## Related pages

* [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) — End-to-end integration example


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://titan-exchange.gitbook.io/titan/developer-doc/resources/ai-llm-integration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
