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

# Instalación y autenticación

> Instalá el SDK de TypeScript, configurá el cliente y autenticá requests con tu API key

## Requisitos

* Node.js 18 o superior.
* Un API key de La Pyme con los scopes necesarios.
* Guardar el API key en una variable de entorno del servidor.

## Instalar

<CodeGroup>
  ```bash npm theme={null}
  npm add lapyme
  ```

  ```bash pnpm theme={null}
  pnpm add lapyme
  ```

  ```bash yarn theme={null}
  yarn add lapyme
  ```

  ```bash bun theme={null}
  bun add lapyme
  ```
</CodeGroup>

El paquete es ESM. En proyectos CommonJS, importalo con `await import("lapyme")`.

## Crear el cliente

```typescript theme={null}
import { Lapyme } from "lapyme";

export const lapyme = new Lapyme({
  bearerAuth: process.env["LAPYME_API_KEY"] ?? "",
});
```

La API key se envía como bearer token. El SDK arma el header `Authorization` por vos.

<Warning>
  No uses el SDK con API keys desde el navegador. Usalo en backend, jobs, scripts o cualquier entorno donde puedas proteger secretos.
</Warning>

## Probar credenciales

```typescript theme={null}
import { Lapyme } from "lapyme";

const lapyme = new Lapyme({
  bearerAuth: process.env["LAPYME_API_KEY"] ?? "",
});

const warehouses = await lapyme.warehouses.list({ limit: 1 });

console.log(warehouses.result.data);
```

Si la credencial no existe, está revocada o no tiene permisos, la API responde con un error estructurado. Revisá [Errores](/api-reference/sdk/errores) para capturarlos.

## URL de servidor

Producción es el servidor por default. Para pruebas contra otro entorno, podés sobreescribirlo:

```typescript theme={null}
import { Lapyme } from "lapyme";

const lapyme = new Lapyme({
  serverURL: "https://api.lapyme.com.ar",
  bearerAuth: process.env["LAPYME_API_KEY"] ?? "",
});
```

## Reintentos

Podés configurar reintentos por cliente o por operación. Para writes con `Idempotency-Key`, reutilizá la misma key cuando reintentes la misma operación.

```typescript theme={null}
import { Lapyme } from "lapyme";

const lapyme = new Lapyme({
  bearerAuth: process.env["LAPYME_API_KEY"] ?? "",
  retryConfig: {
    strategy: "backoff",
    backoff: {
      initialInterval: 1,
      maxInterval: 30,
      exponent: 2,
      maxElapsedTime: 120,
    },
    retryConnectionErrors: true,
  },
});
```
