> ## Documentation Index
> Fetch the complete documentation index at: https://kamino.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# API vs SDK vs Rust Crate

> Access data and build transactions through the API, the TypeScript SDK, or the Rust interface crate

## Overview

Kamino provides three integration options:

| Option               | Description                                                                        |
| -------------------- | ---------------------------------------------------------------------------------- |
| REST API             | HTTPS endpoints for data, analytics, and unsigned transactions. Language-agnostic. |
| TypeScript SDK       | On-chain state reads and transaction building. TS/JS only.                         |
| Rust Interface Crate | Lightweight instruction builder for Rust clients, bots, and on-chain CPI.          |

## Core Differences

Comparison of API, SDK, and Rust crate capabilities.

| Capability                             | REST API                       | TypeScript SDK             | Rust Interface Crate                 |
| -------------------------------------- | ------------------------------ | -------------------------- | ------------------------------------ |
| Data queries (vaults, reserves)        | Ready-made endpoints           | On-chain reads             | On-chain reads (raw account parsing) |
| User position tracking                 | Rich endpoints                 | Real-time account lookup   | Real-time account lookup             |
| Historical metrics & charts            | Built-in history endpoints     | Not available              | Not available                        |
| Transaction building (deposit, borrow) | Unsigned transaction endpoints | Instruction builders       | Instruction builders                 |
| Vault creation                         | Not supported                  | Admin-level creation tools | Not supported                        |
| On-chain CPI                           | Not applicable                 | Not applicable             | Direct CPI from Solana programs      |
| Language/runtime                       | Any (via HTTP)                 | TypeScript/JavaScript only | Rust (client-side or on-chain)       |

## Data & Analytics

Retrieve vault, market, and historical performance data.

<AccordionGroup>
  <Accordion title="Historical Performance">
    **REST API**

    Fetch historical APY data for lending market reserves.

    ```typescript theme={null}
    const options = {method: 'GET'};
    fetch('https://api.kamino.finance/kamino-market/{market-id}/rates/history', options)
      .then(response => response.json())
      .then(response => console.log(response))
      .catch(err => console.error(err));
    ```

    **TypeScript SDK**

    No history tracking. Developers must persist snapshots manually if needed.
  </Accordion>
</AccordionGroup>

## On-Chain Transactions

Build and execute deposit, borrow, repay, and withdraw operations.

<AccordionGroup>
  <Accordion title="Deposit Liquidity">
    **REST API**<br />
    Get unsigned Solana transactions to deposit liquidity into a Kamino Lend market reserve. Returns transaction that must be signed client-side.

    ```typescript theme={null}
    const depositRequest = {
      wallet: 'YOUR_WALLET_ADDRESS',
      market: 'DxXdAyU3kCjnyggvHmY5nAwg5cRbbmdyX3npfDMjjMek',
      reserve: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
      amount: '1.0', // 1 USDC (decimal format, not lamports)
    };

    const res = await fetch('https://api.kamino.finance/ktx/klend/deposit', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(depositRequest),
    });

    const { transaction } = await res.json();
    // Sign and send transaction client-side
    ```

    **TypeScript SDK**<br />
    Build and execute deposit transactions directly on-chain.

    ```typescript theme={null}
    import { KaminoMarket, KaminoAction, VanillaObligation, PROGRAM_ID } from '@kamino-finance/klend-sdk';
    import { createSolanaRpc, address } from '@solana/kit';
    import BN from 'bn.js';

    const rpc = createSolanaRpc('https://api.mainnet-beta.solana.com');
    const market = await KaminoMarket.load(
      rpc,
      address('DxXdAyU3kCjnyggvHmY5nAwg5cRbbmdyX3npfDMjjMek'),
      100
    );

    const depositAction = await KaminoAction.buildDepositTxns(
      market,
      new BN(1_000_000), // 1 USDC
      address('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'),
      signer,
      new VanillaObligation(PROGRAM_ID),
      true
    );
    // Build, sign, and send transaction
    ```

    **Rust Interface Crate**<br />
    Build deposit instructions from a Rust client. Ideal for bots and backend services.

    ```rust theme={null}
    use klend_interface::{helpers, pda, ReserveInfo, KLEND_PROGRAM_ID};
    use spl_associated_token_account::get_associated_token_address;

    let reserve = ReserveInfo::from_account_data(reserve_pubkey, &reserve_data.data)?;
    let user_source_liquidity = get_associated_token_address(&owner, &reserve.liquidity_mint);
    let (collateral_mint, _) = pda::reserve_collateral_mint(&KLEND_PROGRAM_ID, &reserve_pubkey);
    let user_destination_collateral = get_associated_token_address(&owner, &collateral_mint);

    let instructions = helpers::deposit::deposit(
        owner,
        &reserve,
        user_source_liquidity,
        user_destination_collateral,
        1_000_000, // 1 USDC (6 decimals)
    );
    // Build and send transaction
    ```
  </Accordion>

  <Accordion title="Borrow & Repay">
    **REST API**<br />
    Get unsigned transactions for borrow and repay operations.

    ```typescript theme={null}
    // Borrow
    const borrowRequest = {
      wallet: 'YOUR_WALLET_ADDRESS',
      market: '7u3HeHxYDLhnCoErrtycNokbQYbWGzLs6JSDqGAv5PfF',
      reserve: 'D6q6wuQSrifJKZYpR1M8R4YawnLDtDsMmWM1NbBmgJ59',
      amount: '1.0',
    };

    const borrowRes = await fetch('https://api.kamino.finance/ktx/klend/borrow', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(borrowRequest),
    });

    // Repay
    const repayRequest = {
      wallet: 'YOUR_WALLET_ADDRESS',
      market: '7u3HeHxYDLhnCoErrtycNokbQYbWGzLs6JSDqGAv5PfF',
      reserve: 'D6q6wuQSrifJKZYpR1M8R4YawnLDtDsMmWM1NbBmgJ59',
      amount: '1.0',
    };

    const repayRes = await fetch('https://api.kamino.finance/ktx/klend/repay', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(repayRequest),
    });
    ```

    **TypeScript SDK** <br />
    Build borrow and repay transactions directly.

    ```typescript theme={null}
    import { KaminoAction, VanillaObligation, PROGRAM_ID } from '@kamino-finance/klend-sdk';
    import BN from 'bn.js';

    const borrowAction = await KaminoAction.buildBorrowTxns(
      market,
      new BN(1_000_000),
      tokenMint,
      signer,
      new VanillaObligation(PROGRAM_ID),
      true,
      undefined,
      1_000_000,
      true,
      false
    );
    ```

    **Rust Interface Crate**<br />
    Build borrow instructions using `ObligationContext` which handles reserve refresh automatically.

    ```rust theme={null}
    use klend_interface::{ObligationContext, pda, KLEND_PROGRAM_ID};
    use spl_associated_token_account::get_associated_token_address;

    // Build context from on-chain obligation + its reserves
    let ctx = ObligationContext::from_account_data(
        obligation_pubkey, &obligation_data.data, &reserves
    )?;

    let user_dest_liquidity = get_associated_token_address(&owner, &borrow_mint);
    let instructions = ctx.borrow(
        owner,
        &reserve_pubkey,
        user_dest_liquidity,
        1_000_000, // 1 USDC (6 decimals)
    )?;
    // Build and send transaction
    ```
  </Accordion>

  <Accordion title="Vault Creation">
    **TypeScript SDK**<br />

    ```typescript theme={null}
    const { vault: vaultSigner, initVaultIxs: instructions } =
      await kaminoManager.createVaultIxs(kaminoVaultConfig);
    ```

    <br />
  </Accordion>
</AccordionGroup>

## Recommended Usage Patterns

Choose the right tool for your use case.

| Use Case                                     | Best Tool            |
| -------------------------------------------- | -------------------- |
| Display vault list with APR & TVL            | API                  |
| Chart vault APY over 30 days                 | API                  |
| Fetch a user's historical rewards            | API                  |
| Build transactions for client signing        | API                  |
| Execute transactions with full customization | SDK                  |
| Create a new liquidity vault                 | SDK                  |
| Build in non-JS backend (e.g. Python)        | API                  |
| Require zero rate limits                     | SDK with private RPC |
| Build a Rust bot                             | Rust Crate           |
| CPI from an on-chain Solana program          | Rust Crate           |

## Summary

Use the Kamino REST API for fast data integration, history tracking, and building unsigned transactions across any backend. Use the TypeScript SDK for advanced transaction composition, simulation, and vault creation with full on-chain control. Use the Rust interface crate for Rust-native clients, high-performance bots, and CPI from on-chain Solana programs.

## Relevant links

<CardGroup cols={2}>
  <Card title="API Documentation" icon="globe" href="https://api-docs.kamino.com/">
    Explore REST API endpoints and response schemas
  </Card>

  <Card title="SDK Documentation" icon="code" href="https://github.com/Kamino-Finance/klend-sdk">
    Learn how to integrate the TypeScript SDK
  </Card>

  <Card title="Rust Interface Crate" icon="rust" href="https://crates.io/crates/klend-interface">
    Lightweight Rust instruction builder for clients and CPI
  </Card>

  <Card title="Borrow Operations" icon="book" href="/docs/build/developers/borrow/operations/deposit">
    Step-by-step guides for deposit, withdraw, borrow, and repay
  </Card>

  <Card title="SDK Examples" icon="github" href="https://github.com/Kamino-Finance/klend-sdk/tree/master/examples">
    View code examples in the GitHub repository
  </Card>
</CardGroup>
