---
name: agent-edit
description: BYOK Anthropic key + LLM rewrites in the in-browser editor.
---

# Agent edit

Anchorify ships an in-browser editor for every share you own. The
**Agent edit** feature lets you rewrite the whole document with a
single Anthropic LLM call — "tighten this", "translate to
Spanish", "rephrase the intro for a non-technical audience" — and
review the result side-by-side with the current version before
keeping it.

Anchorify does not pay for the inference. You bring your own
Anthropic API key, we store it encrypted at rest, every rewrite
hits Anthropic on your tab.

## Connect a key

1. Open `/dashboard/settings`. The Workspace-features grid has
   an **Agent edit** card showing `Not set` until you connect a
   key.
2. Click **Manage →** to land on `/dashboard/agent-key`. (You
   can also click the JIT "Connect a key →" prompt that appears
   at the bottom of the editor pane whenever you open the editor
   without a key on file.)
3. Paste your Anthropic API key — anything starting with
   `sk-ant-`. Hit **Save key**.
4. The key is encrypted at rest with AES-256-GCM keyed off the
   server's `ANTHROPIC_KEY_ENC_SECRET` env var. It is never
   logged, never returned via any API endpoint, and never
   transmitted in plaintext after the initial save.

Get a key at <https://console.anthropic.com/settings/keys>.

The Settings-hub card flips to `Connected` once the key is on
file. To rotate a key, save a new one (the old encrypted blob is
overwritten). To remove the key entirely, hit **Remove stored
key** on `/dashboard/agent-key`.

## Run a rewrite

In the editor pane on any share you own:

1. Edit-mode requires `share.update` permission. Org admins,
   share editors, and project editors all qualify.
2. With a key connected, the editor renders a prompt textarea
   above the diff strip. Type the instruction in plain English.
3. Hit **Run agent**. Anchorify sends the full current document
   body plus your prompt to Anthropic, blocks on the response,
   and renders the rewrite next to the current version.
4. Review the diff. Accept to write the rewrite as a new
   version (the diff lands in `/dashboard/shares/:id/versions`);
   reject to throw it away.

## API surface

For agent-driven flows outside the browser editor, use the
`/api/v1/agent-edit` endpoint directly. Auth is per-user cookie
session OR per-user CLI bearer token; the legacy operator
bearer is intentionally rejected because the BYOK key is
per-user.

```bash
curl -X POST https://anchorify.io/api/v1/agent-edit \
  -H "authorization: Bearer $ANCHORIFY_TOKEN" \
  -H "content-type: application/json" \
  -d '{
    "share_id": "abc12345",
    "prompt": "Tighten this to fit a 2-minute read."
  }'
```

The response is `{ "content": "<rewritten markdown>" }`. You
own the round-trip — Anchorify does not apply the rewrite for
you. To persist, follow up with a normal share update against
`POST /api/v1/shares/:id` carrying the new content.

The BYOK key state itself is exposed for tooling:

- `GET /api/v1/me/anthropic-key` → `{ "hasKey": boolean }`
- `POST /api/v1/me/anthropic-key` body `{ "key": "sk-ant-..." }` → `204`
- `DELETE /api/v1/me/anthropic-key` → `204`

The cleartext key is never returned by `GET`. Tools that need
to verify "do I still have a key on file" can rely on
`hasKey`; tools that need to operate as the user have to
re-prompt the operator for the key value.

## Cost

Anchorify makes no claim on your Anthropic spend. A single
agent rewrite of a typical 2-page markdown share with Claude
Sonnet costs under a cent at current rates. Set your
Anthropic key's spend limit on the Anthropic console if you
want a hard ceiling.

## Limits

- Whole-document rewrites only — no inline selection / partial
  rewrites yet.
- One prompt per request — no multi-turn conversations.
- The rewrite is synchronous and blocks the editor pane until
  Anthropic responds. Expect 3–15s for a typical 2-page share.
- Rate-limited by Anthropic's own per-key tier; Anchorify does
  not add a separate rate-limit on top.
