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

# Autenticação

> Como a plataforma protege suas funções com runtime tokens, como usar X-Jelou-Token e como tornar funções públicas.

Toda função implantada está protegida por padrão com um **runtime token**. Requisições sem token válido recebem `401 Unauthorized`.

## Início rápido

<Steps>
  <Step title="Implante sua função">
    ```bash theme={null}
    jelou functions deploy
    # ✓ Deployed
    # ▸ URL: https://minha-funcao.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...
    ```

    O primeiro deploy gera automaticamente um runtime token.

    <Warning>
      **Salve o token imediatamente.** Ele não será exibido novamente. Se perdê-lo, crie um novo com `jelou tokens create`.
    </Warning>
  </Step>

  <Step title="Chame com o token">
    ```bash theme={null}
    curl -X POST https://minha-funcao.fn.jelou.ai \
      -H "Content-Type: application/json" \
      -H "X-Jelou-Token: jfn_rt_abc123..." \
      -d '{"query": "test"}'
    ```

    Resposta bem-sucedida:

    ```json theme={null}
    { "results": [] }
    ```

    Sem token ou com token inválido:

    ```json theme={null}
    { "error": "Unauthorized", "message": "Missing or invalid X-Jelou-Token header" }
    ```
  </Step>
</Steps>

## Como funciona

1. No primeiro deploy, a plataforma gera um runtime token (prefixo `jfn_rt_`)
2. Cada requisição deve incluir esse token no header `X-Jelou-Token`
3. Se o token for válido, a requisição chega ao handler. Caso contrário, retorna `401`

## Rotas sem autenticação

As rotas `/__health` e `/openapi.json` nunca requerem token. Os triggers cron também não — a plataforma os autentica automaticamente.

## Exemplos de uso

<Tabs>
  <Tab title="curl">
    ```bash theme={null}
    curl -X POST https://minha-funcao.fn.jelou.ai \
      -H "Content-Type: application/json" \
      -H "X-Jelou-Token: jfn_rt_abc123..." \
      -d '{"telefone": "5511987654321"}'
    ```
  </Tab>

  <Tab title="Node.js">
    ```javascript theme={null}
    const res = await fetch("https://minha-funcao.fn.jelou.ai", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "X-Jelou-Token": process.env.JELOU_FUNCTION_TOKEN,
      },
      body: JSON.stringify({ telefone: "5511987654321" }),
    });
    const data = await res.json();
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    import requests
    import os

    res = requests.post(
        "https://minha-funcao.fn.jelou.ai",
        headers={
            "Content-Type": "application/json",
            "X-Jelou-Token": os.environ["JELOU_FUNCTION_TOKEN"],
        },
        json={"telefone": "5511987654321"},
    )
    data = res.json()
    ```
  </Tab>
</Tabs>

<Warning>
  A plataforma não valida nada — seu código é responsável.
</Warning>
