> ## 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.

# Quick start

> Crie, teste e faça o deploy da sua primeira Jelou Function em menos de 5 minutos.

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

    Verifique a instalação:

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

  <Step title="Autentique-se">
    Você precisa de um token de acesso pessoal (crie um no painel do Jelou).

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

    <Tip>
      Em CI você pode passar o token diretamente: `jelou login --token jfn_pat_your_token`
    </Tip>
  </Step>

  <Step title="Inicialize um projeto">
    Crie um diretório e execute `jelou functions init`:

    ```bash theme={null}
    mkdir query-customer && cd query-customer
    jelou functions init
    # ? Function slug: query-customer
    # ? Description: Looks up customer information for the WhatsApp bot
    # ? Create new or link existing? Create new
    # ✓ Created query-customer
    ```

    Isso gera os arquivos base:

    | Arquivo      | Finalidade                   |
    | ------------ | ---------------------------- |
    | `index.ts`   | Sua função principal         |
    | `jelou.json` | Configuração do projeto      |
    | `deno.json`  | Import map do SDK            |
    | `.env`       | Variáveis de ambiente locais |
  </Step>

  <Step title="Escreva sua função">
    Substitua o conteúdo de `index.ts` por uma função que consulta clientes pelo telefone:

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

    export default define({
      name: "query-customer",
      description: "Looks up customer information by phone number for the support bot",
      input: z.object({
        phone: z.string().min(10).describe("Customer phone number"),
      }),
      output: z.object({
        name: z.string(),
        email: z.string(),
        plan: z.string(),
        balance: z.number(),
      }),
      handler: async (input, ctx) => {
        ctx.log("Looking up customer", {
          phone: input.phone,
          company: ctx.company.id,
        });

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

        return {
          name: customer.name,
          email: customer.email,
          plan: customer.plan,
          balance: customer.balance,
        };
      },
    });
    ```
  </Step>

  <Step title="Execute localmente">
    Inicie o servidor de desenvolvimento:

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

    O servidor recarrega automaticamente quando você edita os arquivos.
  </Step>

  <Step title="Teste com curl">
    Em outro terminal, envie uma requisição:

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

    Resposta:

    ```json theme={null}
    {
      "name": "Maria Garcia",
      "email": "maria@example.com",
      "plan": "Premium",
      "balance": 150.00
    }
    ```

    <Tip>
      Você também pode testar o endpoint MCP em `http://localhost:3000/mcp` e o health check em `http://localhost:3000/__health`.
    </Tip>
  </Step>

  <Step title="Configure os secrets">
    Antes de fazer o deploy, adicione as variáveis de ambiente que sua função precisa:

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

  <Step title="Faça o deploy para produção">
    ```bash theme={null}
    jelou functions deploy
    # ▸ Files: index.ts (1.2 KB), jelou.json (98 B), deno.json (65 B)
    # ? Deploy query-customer? (Y/n) y
    # ✓ Deployed to https://query-customer.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>
      Salve o token — ele não será exibido novamente. Você precisa dele para chamar sua função em produção.
    </Warning>

    Sua função já está disponível em produção. Os agentes de IA do Jelou podem invocá-la como ferramenta MCP automaticamente.
  </Step>

  <Step title="Verifique em produção">
    ```bash theme={null}
    curl -X POST https://query-customer.fn.jelou.ai \
      -H "Content-Type: application/json" \
      -H "X-Jelou-Token: jfn_rt_abc123..." \
      -d '{"phone": "593987654321"}'
    ```

    Monitore os logs em tempo real:

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

## Próximos passos

* [Validação de entrada/saída](/pt/guias/funcoes/validacao) — schemas Zod, coerção de tipos e formato de erros
* [Funções multi-tool](/pt/guias/funcoes/multi-tool) — agrupe múltiplas ferramentas em um único deploy com `app()`
