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

# Autenticacao

> Como autenticar requisicoes a API do Laudos.AI

# Autenticacao

Todas as requisicoes a API do Laudos.AI devem incluir uma API Key no header `Authorization`.

## API Keys

Gere sua API Key em [copilot.laudos.ai/settings/integrations](https://copilot.laudos.ai/settings/integrations).

```bash theme={null}
curl -X GET "https://copilot.laudos.ai/api/v1/reports" \
  -H "Authorization: Bearer sk_live_xxxxxxxxxxxxx"
```

<Warning>
  Nunca exponha sua API Key em codigo client-side ou repositorios publicos. Use variaveis de ambiente no servidor.
</Warning>

### Formato da Chave

```
sk_live_ + caracteres alfanumericos
```

Exemplo: `sk_live_SUA_CHAVE_AQUI`

### Permissoes

Cada API Key possui permissoes configuradas no momento da criacao:

| Permissao   | Descricao             |
| ----------- | --------------------- |
| `reports`   | Ler e escrever laudos |
| `templates` | Gerenciar templates   |
| `pacs`      | Enviar laudos ao PACS |

### Seguranca das Chaves

* Chaves sao armazenadas com hash SHA-256 (nao armazenamos o valor original)
* Apos gerada, a chave e exibida apenas uma vez
* Se perder sua chave, revogue-a e gere uma nova

***

## Exemplo de Uso

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://copilot.laudos.ai/api/v1/reports?limit=10" \
    -H "Authorization: Bearer sk_live_xxx"
  ```

  ```typescript TypeScript theme={null}
  const response = await fetch('https://copilot.laudos.ai/api/v1/reports?limit=10', {
    headers: {
      'Authorization': `Bearer ${process.env.LAUDOSAI_API_KEY}`,
    },
  });

  if (!response.ok) {
    throw new Error(`HTTP ${response.status}: ${response.statusText}`);
  }

  const { data } = await response.json();
  ```

  ```python Python theme={null}
  import os
  import requests

  response = requests.get(
      "https://copilot.laudos.ai/api/v1/reports",
      headers={"Authorization": f"Bearer {os.environ['LAUDOSAI_API_KEY']}"},
      params={"limit": 10}
  )
  response.raise_for_status()
  data = response.json()
  ```
</CodeGroup>

***

## Respostas de Erro

| Codigo | Descricao                                            |
| ------ | ---------------------------------------------------- |
| `401`  | API Key invalida, expirada ou ausente                |
| `403`  | Chave nao possui permissao para o recurso solicitado |
| `429`  | Rate limit excedido                                  |

```json theme={null}
{
  "error": "API key invalida"
}
```

***

## Boas Praticas

* Armazene chaves em variaveis de ambiente ou secrets managers (AWS Secrets Manager, HashiCorp Vault, Vercel Environment Variables)
* Use uma chave separada por ambiente (desenvolvimento, staging, producao)
* Revogue chaves que nao estao mais em uso
* Monitore o uso da API em **Configuracoes > Integracoes** na plataforma
