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

# Server SDK

> A typed, server-side TypeScript client for the Cesto API: baskets, positions, managed wallets, and client-signed open / close / rebalance.

The **Cesto Server SDK** (`@cesto/sdk`) is a typed TypeScript client for the Cesto API.
Use it to list and inspect baskets (products), look up a user's positions by their
Solana wallet, and open, close, or rebalance positions — either on **managed wallets**
(Cesto provisions and signs, you never touch a key) or with client-signed transactions —
all behind a single API key.

> [card] Products
>
> List baskets and fetch full basket detail, optionally with backtested performance and charts.

> [card] Positions
>
> Read a user's positions by wallet, and live per-basket holdings for SDK positions.

> [card] Managed wallets
>
> Cesto provisions a Privy-backed Solana wallet per user and signs server-side — open, close, and rebalance by user reference, no key handling.

> [card] Open, Close & Rebalance
>
> The self-custody alternative: open, close, and rebalance positions where the user's wallet signs its own transactions — Cesto never holds the key.

> [card] Bridging (CCTP)
>
> Bridge native USDC between Base and Solana — the user signs once on the source chain, Cesto handles the rest.

> [card] No gas, no SOL
>
> Cesto sponsors network gas and ATA rent on Solana, and pays destination mint gas when bridging — user wallets need only USDC.

> [card] Typed & resilient
>
> Every method and response is typed (ESM + CJS), with automatic retries, timeouts, and a typed error hierarchy.

## Requirements

* **Node.js 18+** (uses the global `fetch`).
* **Server-side only**: the SDK uses a secret API key and refuses to run in a browser.

> [!WARNING]
>
> Never use the SDK in browser / client-side code; your secret key would be exposed to end
> users. It is meant for backends, scripts, and serverless / edge functions.
>
> Need something in the browser? Use the [Web SDK](https://docs.cesto.co/web-sdk/overview.md) for an in-page invest
> flow, or the keyless [browser client](https://docs.cesto.co/sdk/browser-client.md) for public reads.

## Install

```bash npm theme={null}
npm install @cesto/sdk
```

```bash pnpm theme={null}
pnpm add @cesto/sdk
```

```bash yarn theme={null}
yarn add @cesto/sdk
```

## Quickstart

```ts theme={null}
import { Cesto } from '@cesto/sdk';

const cesto = new Cesto({ apiKey: process.env.CESTO_API_KEY });

// List baskets
const products = await cesto.products.list();

// Fetch one basket by slug
const product = await cesto.products.get({ slug: 'my-basket-slug' });

// Look up positions by external Solana wallet
const { positions } = await cesto.positions.list({
  wallet: 'EXTERNAL_SOLANA_ADDRESS',
});

// Live position in one basket (the position view for SDK-opened positions)
const position = await cesto.positions.getHoldings({
  wallet: 'EXTERNAL_SOLANA_ADDRESS',
  product: 'stable-genius',
});

// Managed wallets (write-scoped key): provision a user, then invest — Cesto signs
const user = await cesto.users.create({ evmWalletAddress: '0xUserEvmWallet' });
const { executionId } = await cesto.open.start({
  user: user.solanaAddress,
  product: 'stable-genius',
  amount: 10_000_000n, // 10 USDC @ 6 decimals
});
```

> [!NOTE]
>
> You need a **secret** API key (`cesto_sk_…`) to use this SDK. See
> [Authentication](https://docs.cesto.co/sdk/authentication.md) to request one, or
> [API keys](https://docs.cesto.co/developers/api-keys.md) for how it differs from the Web SDK's publishable key.

> [!NOTE]
>
> Not sure this is the right surface? [Choose your
> integration](https://docs.cesto.co/developers/choose-an-integration.md) compares it with
> [Widgets](https://docs.cesto.co/widgets/overview.md) and the [Web SDK](https://docs.cesto.co/web-sdk/overview.md) in one page.

> [!NOTE]
>
> Integrating for partner users? The **managed wallets** flow is the recommended path —
> Cesto provisions and signs, you never touch a key: [Managed
> Wallets](https://docs.cesto.co/sdk/managed-wallets.md). [Integration Models](https://docs.cesto.co/sdk/integration-models.md) compares it
> with the self-custody setups — your own Privy, browser EOAs (Phantom / Solflare), and
> cross-chain EVM funding.

## Next steps

> [card] [Integration Models](https://docs.cesto.co/sdk/integration-models.md)
>
> Choose a wallet model: managed wallets, your own Privy, EOAs, or cross-chain.

> [card] [Managed Wallets](https://docs.cesto.co/sdk/managed-wallets.md)
>
> Cesto-managed Privy wallets, signed server-side — the recommended flow.

> [card] [Authentication](https://docs.cesto.co/sdk/authentication.md)
>
> Get a key and start making requests.

> [card] [Configuration](https://docs.cesto.co/sdk/configuration.md)
>
> Client options, timeouts, and retries.

> [card] [Products](https://docs.cesto.co/sdk/products.md)
>
> List and fetch baskets.

> [card] [Positions](https://docs.cesto.co/sdk/positions.md)
>
> Positions by wallet.

> [card] [Fees](https://docs.cesto.co/sdk/fees.md)
>
> Price a basket investment before the user commits.

> [card] [Users](https://docs.cesto.co/sdk/users.md)
>
> Resolve a Solana wallet to an existing Cesto user.

> [card] [Open a Position](https://docs.cesto.co/sdk/open-position.md)
>
> Open positions with client-signed transactions.

> [card] [Close a Position](https://docs.cesto.co/sdk/close-position.md)
>
> Close a wallet's full basket holding.

> [card] [Rebalance a Position](https://docs.cesto.co/sdk/rebalance-position.md)
>
> Migrate a position to the basket's latest version.

> [card] [Bridging (CCTP)](https://docs.cesto.co/sdk/bridging.md)
>
> Bridge USDC between EVM chains and Solana, then invest the arrived amount.

> [card] [Browser Client](https://docs.cesto.co/sdk/browser-client.md)
>
> `@cesto/sdk/client` — public reads from the browser, no key.

> [card] [Examples](https://docs.cesto.co/sdk/examples.md)
>
> Runnable Node.js examples for every feature.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.