# AI — providers and generation

> **TL;DR for agents:** `POST /api/provider-configs` to attach a key; `GET /api/ai/providers` to list configured providers; `POST /api/ai/generate` to call the routed model. Keys are stored encrypted at rest.

## Attach a provider key

Scope: `settings:write`. Currently supported `provider`: `openai`, `anthropic`, `aitunnel`, `hydraai`, `ldmai`. Key is encrypted server-side immediately.

```bash
curl -s -X POST "https://api.live-direct-marketing.online/api/provider-configs" \
  -H "Authorization: Bearer $LDM_KEY" -H "Content-Type: application/json" \
  -d '{"provider":"openai","apiKey":"sk-...","model":"gpt-4o-mini"}'
```

## List configured providers

Scope: `ai:read`. Returns providers with `hasKey: true|false` (the stored key itself never leaves the server).

```bash
curl -s "https://api.live-direct-marketing.online/api/ai/providers" \
  -H "Authorization: Bearer $LDM_KEY"
```

## Generate copy

Scope: `ai:write`. Uses the default routed provider unless overridden.

```bash
curl -s -X POST "https://api.live-direct-marketing.online/api/ai/generate" \
  -H "Authorization: Bearer $LDM_KEY" -H "Content-Type: application/json" \
  -d '{
    "prompt":"Write a 2-sentence reply that thanks the prospect and books a 15-min call",
    "context":{"company":"Acme","industry":"SaaS"}
  }'
```
