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

# Instalación

> Como instalar y configurar el SDK de pan

El SDK oficial de pan para JavaScript/TypeScript simplifica la integración con pan API.

## Instalacion

<CodeGroup>
  ```bash npm theme={null}
  npm install @pan/sdk
  ```

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

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

  ```bash bun theme={null}
  bun add @pan/sdk
  ```
</CodeGroup>

## Configuración Basica

```typescript theme={null}
import { Pan } from '@pan/sdk';

const pan = new Pan({
  apiKey: process.env.PAN_API_KEY
});
```

## Opciones de Configuración

```typescript theme={null}
const pan = new Pan({
  // Requerido
  apiKey: 'pan_sk_...',

  // Opcionales
  baseURL: 'https://api.pan.tech/v1',  // URL base de la API
  timeout: 30000,                       // Timeout en ms (default: 30000)
  debug: false,                         // Modo debug (default: false)
  retries: 3,                          // Reintentos automáticos (default: 3)
});
```

| Opcion    | Tipo    | Default                   | Descripción             |
| --------- | ------- | ------------------------- | ----------------------- |
| `apiKey`  | string  | -                         | Tu API key de pan       |
| `baseURL` | string  | `https://api.pan.tech/v1` | URL base                |
| `timeout` | number  | 30000                     | Timeout en milisegundos |
| `debug`   | boolean | false                     | Activa logs de debug    |
| `retries` | number  | 3                         | Reintentos en errores   |

## Verificar Instalación

```typescript theme={null}
import { Pan } from '@pan/sdk';

const pan = new Pan({ apiKey: process.env.PAN_API_KEY });

// Verificar conexión
try {
  const yields = await pan.yields.getAll();
  console.log('Conexión exitosa!');
  console.log('Mejor APY:', yields.best.apy);
} catch (error) {
  console.error('Error de conexión:', error.message);
}
```

## Variables de Entorno

Recomendamos usar variables de entorno para la API key:

```env theme={null}
# .env
PAN_API_KEY=pan_sk_tu_api_key_aqui
```

```typescript theme={null}
// Cargar con dotenv o similar
import 'dotenv/config';
import { Pan } from '@pan/sdk';

const pan = new Pan({
  apiKey: process.env.PAN_API_KEY
});
```

<Warning>
  Nunca commitees tu API key. Agrega `.env` a tu `.gitignore`.
</Warning>

## TypeScript

El SDK incluye tipos TypeScript completos:

```typescript theme={null}
import { Pan, Wallet, Intent, Balances, Yields } from '@pan/sdk';

const pan = new Pan({ apiKey: process.env.PAN_API_KEY! });

// Los tipos se infieren automaticamente
const wallet: Wallet = await pan.wallet.create({
  userId: 'user_123'
});

const balances: Balances = await pan.wallet.getBalances(wallet.id);

const intent: Intent = await pan.lend({
  walletId: wallet.id,
  amount: 1000,
  asset: 'USDC'
});
```

## Próximos Pasos

<CardGroup cols={2}>
  <Card title="Cliente" icon="plug" href="/sdk/cliente">
    Configuración avanzada del cliente
  </Card>

  <Card title="Wallets" icon="wallet" href="/sdk/wallets">
    Operaciones con wallets
  </Card>

  <Card title="Intents" icon="target" href="/sdk/intents">
    Crear y monitorear intents
  </Card>

  <Card title="Errores" icon="exclamation-triangle" href="/sdk/errores">
    Manejo de errores
  </Card>
</CardGroup>
