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

# Inicio rápido

> Crea, prueba y despliega tu primera Jelou Function en menos de 5 minutos.

<Steps>
  <Step title="Instala el CLI">
    ```bash theme={null}
    npm install -g @jelou/cli
    ```

    Verifica la instalación:

    ```bash theme={null}
    jelou --version
    ```
  </Step>

  <Step title="Autentícate">
    Necesitas un token de acceso personal (créalo en el dashboard de Jelou).

    ```bash theme={null}
    jelou login
    # Paste your access token: ****
    # ✓ Logged in
    ```

    <Tip>
      En CI puedes pasar el token directamente: `jelou login --token jfn_pat_tu_token`
    </Tip>
  </Step>

  <Step title="Inicializa un proyecto">
    Crea un directorio y ejecuta `jelou functions init`:

    ```bash theme={null}
    mkdir consultar-cliente && cd consultar-cliente
    jelou functions init
    # ? Function slug: consultar-cliente
    # ? Description: Busca información de clientes para el bot de WhatsApp
    # ? Create new or link existing? Create new
    # ✓ Created consultar-cliente
    ```

    Esto te genera los archivos base:

    | Archivo      | Propósito                    |
    | ------------ | ---------------------------- |
    | `index.ts`   | Tu función principal         |
    | `jelou.json` | Configuración del proyecto   |
    | `deno.json`  | Import map del SDK           |
    | `.env`       | Variables de entorno locales |
  </Step>

  <Step title="Escribe tu función">
    Reemplaza el contenido de `index.ts` con una función que busca clientes por teléfono:

    ```typescript index.ts theme={null}
    import { define, z } from "@jelou/functions";

    export default define({
      name: "consultar-cliente",
      description: "Busca información de un cliente por número de teléfono para el bot de soporte",
      input: z.object({
        telefono: z.string().min(10).describe("Número de teléfono del cliente"),
      }),
      output: z.object({
        nombre: z.string(),
        email: z.string(),
        plan: z.string(),
        saldo: z.number(),
      }),
      handler: async (input, ctx) => {
        ctx.log("Buscando cliente", {
          telefono: input.telefono,
          company: ctx.company.id,
        });

        const apiKey = ctx.env.get("CRM_API_KEY");
        const res = await fetch(
          `https://crm.example.com/api/clientes?tel=${input.telefono}`,
          { headers: { Authorization: `Bearer ${apiKey}` } },
        );
        const cliente = await res.json();

        return {
          nombre: cliente.nombre,
          email: cliente.email,
          plan: cliente.plan,
          saldo: cliente.saldo,
        };
      },
    });
    ```
  </Step>

  <Step title="Ejecuta en local">
    Inicia el servidor de desarrollo:

    ```bash theme={null}
    jelou functions dev
    # ▸ Listening on http://localhost:3000
    # ▸ Watching for changes...
    ```

    Tu servidor se recarga automáticamente cuando editas archivos.
  </Step>

  <Step title="Prueba con curl">
    En otra terminal, envía una petición:

    ```bash theme={null}
    curl -X POST http://localhost:3000 \
      -H "Content-Type: application/json" \
      -d '{"telefono": "593987654321"}'
    ```

    Respuesta:

    ```json theme={null}
    {
      "nombre": "María García",
      "email": "maria@example.com",
      "plan": "Premium",
      "saldo": 150.00
    }
    ```

    <Tip>
      También puedes probar el endpoint MCP en `http://localhost:3000/mcp` y el health check en `http://localhost:3000/__health`.
    </Tip>
  </Step>

  <Step title="Configura secrets">
    Antes de desplegar, agrega las variables de entorno que necesita tu función:

    ```bash theme={null}
    jelou secrets set consultar-cliente CRM_API_KEY=YOUR_CRM_API_KEY
    # ✓ Set 1 secret
    ```
  </Step>

  <Step title="Despliega a producción">
    ```bash theme={null}
    jelou functions deploy
    # ▸ Files: index.ts (1.2 KB), jelou.json (98 B), deno.json (65 B)
    # ? Deploy consultar-cliente? (Y/n) y
    # ✓ Deployed to https://consultar-cliente.fn.jelou.ai
    # ⚠ A default runtime token was created for this function.
    #   Save it now — it will not be shown again.
    # ▸ Token    jfn_rt_abc123...
    ```

    <Warning>
      Guarda el token — no se mostrará de nuevo. Lo necesitas para llamar a tu función en producción.
    </Warning>

    Tu función ya está disponible en producción. Los agentes IA de Jelou pueden invocarla como herramienta MCP automáticamente.
  </Step>

  <Step title="Verifica en producción">
    ```bash theme={null}
    curl -X POST https://consultar-cliente.fn.jelou.ai \
      -H "Content-Type: application/json" \
      -H "X-Jelou-Token: jfn_rt_abc123..." \
      -d '{"telefono": "593987654321"}'
    ```

    Monitorea los logs en tiempo real:

    ```bash theme={null}
    jelou functions logs consultar-cliente
    ```
  </Step>
</Steps>

## Siguientes pasos

* [Validación de entrada/salida](/guides/functions/validacion) — esquemas Zod, coerción de tipos y formato de errores
* [Funciones multi-tool](/guides/functions/multi-tool) — agrupa varias herramientas en un solo despliegue con `app()`
