# Setting up AI

> Switch AI on, choose Lagotto's key or your own Anthropic or OpenAI key, pick a model, test the connection and see what AI has cost.

AI drafts replies, translates and summarizes tickets in your workspace. It is off until an administrator (an owner or admin) sets it up under **Settings → AI**. The page has three tabs: **Settings**, **Usage** and **Credits**.

## Switching AI on

1. Go to **Settings → AI**.
2. Turn on **Use AI in this workspace**.
3. Under **Whose key**, choose **Ours** or **Your own** (see below).
4. Press **Save**.

Two more settings on the same page:

- **Draft a reply when a customer writes**: on, a draft is written each time a customer's message needs a reply. Off, a draft is only written when an agent presses **Draft with AI** on the ticket. See [AI drafts](https://www.lagottolabs.ai/support/ai/ai-drafts.md).
- **Instructions for drafts**: your tone and policies, in plain words, such as "Refunds within 30 days are always fine; anything older goes to a manager." They win over the default writing style on every draft.

Translation, memories, your knowledge base, source control and production data are capabilities, switched on separately: see [Turning capabilities on and off](https://www.lagottolabs.ai/support/integrations/capabilities.md).

## Whose key

### Ours

AI runs on Claude, on Lagotto's account. Each run is paid from your prepaid [AI credits](https://www.lagottolabs.ai/support/billing/ai-credits.md) at the model's list price, with no markup. You need credits before AI can run.

Under **Model**, leave **Default** or choose another. Each choice shows its price per million tokens in and out.

### Your own

Your Anthropic or OpenAI account bills you directly. Lagotto charges nothing for AI, and no credits are used.

1. Choose **Your own**.
2. Under **Provider**, choose **Anthropic (Claude)** or **OpenAI**.
3. Paste your key into **API key**.
4. Optionally, type the provider's model ID under **Model**. Leave it blank for the default, shown in the empty field.
5. Press **Save**.

How the key is kept:

- It is stored encrypted and never shown again. The page shows only its last four characters: "A key ending …abcd is saved."
- To keep the saved key, leave **API key** blank when you save. To replace it, paste a new one.
- **Remove the saved key** deletes it and switches the workspace back to Lagotto's key.
- Every change to these settings is recorded in the [audit log](https://www.lagottolabs.ai/support/people-and-security/audit-log.md), including whether the key changed, but never the key itself.

## Testing your key

Once your own key is saved, **Test connection** appears at the top of the page. It sends one tiny request on your key and says "Connected." with the provider and model that answered, or "The test didn't work:" with the reason, such as "The API key was rejected (401)." Your provider bills that request like any other.

On Lagotto's key there is no test: there is nothing of yours to check, and a test would cost credits.

## Why AI might not run

When AI can't run, the reason shows at the top of **Settings → AI** and in the **AI draft** panel on every ticket:

- **"AI is switched off for this workspace."** Turn on **Use AI in this workspace** and save.
- **"No API key is saved."** Paste your key, or choose **Ours**.
- **"This workspace is out of AI credits."** Buy credits on **Settings → Billing**, or switch to your own key. See [AI credits](https://www.lagottolabs.ai/support/billing/ai-credits.md).
- **"AI on our key isn't available yet."** Lagotto's key can't be used right now. Use your own key in the meantime, or [talk to us](https://www.lagottolabs.ai/contact/new).
- **"This workspace is suspended."** [Talk to us](https://www.lagottolabs.ai/contact/new).

A draft can also fail on the provider's side, for example when your key has been revoked. The ticket's AI panel shows the reason, and so does the **Usage** tab. A temporary outage at the provider is retried automatically.

## Usage

**Settings → AI → Usage** shows what AI has done:

- **Runs this month**, **Tokens this month** and **Cost this month**, for the calendar month in your workspace's time zone.
- **Recent runs**: what each was (draft, summary, translation or fix), the ticket, whether it succeeded, the model, tokens, cost and when. Runs on your own key are marked "your key". A failed run shows why.

Costs are worked out at the list prices Lagotto knows. On Lagotto's key, that is what comes out of your credits. On your own key it is only an estimate, and a model Lagotto has no price for, such as any OpenAI model, shows $0.00: your provider's bill is the real figure.

**Settings → AI → Credits** shows your credit balance and every credit added and spent. See [AI credits](https://www.lagottolabs.ai/support/billing/ai-credits.md).
