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

# Autenticação

> Como autenticar requisições na API do JuriChat.

A API do JuriChat utiliza autenticação baseada em API Key.

Para acessar endpoints protegidos, envie sua chave utilizando o header `x-jurichat-api-key` em todas as requisições.

<Info>
  Cada API Key possui permissões vinculadas ao ambiente e à conta responsável pela integração.
</Info>

## Header de autenticação

```http theme={null}
x-jurichat-api-key: SUA_API_KEY
```

## Exemplo de requisição

<Tabs>
  <Tab title="cURL">
    ```bash theme={null}
    curl --request GET \
      --url https://api.jurichat.com \
      --header 'x-jurichat-api-key: SUA_API_KEY'
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    const response = await fetch("https://api.jurichat.com", {
      method: "GET",
      headers: {
        "x-jurichat-api-key": "SUA_API_KEY"
      }
    })

    const data = await response.json()
    ```
  </Tab>

  <Tab title="Node.js">
    ```javascript theme={null}
    import axios from "axios"

    const response = await axios.get(
      "https://api.jurichat.com",
      {
        headers: {
          "x-jurichat-api-key": "SUA_API_KEY"
        }
      }
    )

    console.log(response.data)
    ```
  </Tab>
</Tabs>

## Como obter sua API Key

<Steps>
  <Step title="Acesse o painel">
    Entre na plataforma do JuriChat utilizando sua conta.
  </Step>

  <Step title="Abra as configurações">
    Navegue até a área de integrações.
  </Step>

  <Step title="Gere sua chave">
    Crie uma nova API Key para sua aplicação.
  </Step>

  <Step title="Armazene com segurança">
    Guarde sua chave em um ambiente seguro e nunca exponha no frontend.
  </Step>
</Steps>

## Exemplo de resposta autenticada

<ResponseExample>
  ```json theme={null}
  {
    "data": {
      "id": "usr_123",
      "name": "John Doe",
      "email": "john@company.com"
    }
  }
  ```
</ResponseExample>

## Erros de autenticação

<Tabs>
  <Tab title="API Key ausente">
    ```json theme={null}
    {
      "message": "Acesso não autorizado",
      "statusCode": 401,
      "code": "UNAUTHORIZED"
    }
    ```
  </Tab>

  <Tab title="API Key inválida">
    ```json theme={null}
    {
      "message": "API key inválida",
      "statusCode": 401,
      "code": "INVALID_API_KEY"
    }
    ```
  </Tab>
</Tabs>

## Boas práticas

<CardGroup cols={2}>
  <Card title="Use variáveis de ambiente" icon="lock">
    Nunca salve sua API Key diretamente no código-fonte da aplicação.
  </Card>

  <Card title="Não exponha no frontend" icon="triangle-exclamation">
    Requisições autenticadas devem ser feitas apenas pelo backend.
  </Card>

  <Card title="Rotacione suas chaves" icon="arrows-rotate">
    Atualize periodicamente suas chaves de acesso.
  </Card>
</CardGroup>

<Warning>
  O compartilhamento indevido da sua API Key pode comprometer a segurança da sua integração.
</Warning>
