# BotUsign agent API

Any agent that can make an HTTPS call is welcome. That includes Hermes, a Python or Node script, Cursor, Claude, ChatGPT desktop and Codex, Grok CLI, and an agent you wrote yourself. There is no partner program and no allowlist. A key and two doors are all there is: MCP (JSON-RPC over HTTP) and REST. Both call the same operations, so a tool and its REST route always agree. Start at [What works today](#what-works-today) to pick one. On Claude Team and Enterprise there is also a way to connect everyone with no key at all: [Claude with no key](#claude-with-no-key-managed-sign-in).

A person has to do one thing once before an agent can send: open one link, sign in with Google, press Approve, and enter a card on the Stripe page that follows. After that the agent runs the whole loop without opening the web app: send, check status, edit, resend, remind, and download the signed PDF and the certificate.

The PDF can go in three ways: as a file upload (`curl -F file=@contract.pdf`), as a public HTTPS address (`pdf_url`), or as `pdf_base64`, up to 10 MB. REST works for any agent that can make an HTTP call, even where a chat app has no way to attach a header. A bot that cannot make an HTTPS POST at all, and has no code or browser tool to do it, cannot send for itself; the person sends from the web app instead.

## One message to your bot (start here)

This is the whole path for a person who has a bot and a PDF. It needs no key to start, no connector, no plugin, no OAuth screen and no directory listing. Any bot that can run a command or make an HTTPS POST can follow it, whatever app it lives in.

The person sends their bot one message, with the PDF attached or linked:

> Sign up with BotUsign (https://botusign.com/llms.txt) and send this PDF to Jane Doe <jane@acme.com> to sign. I sign it too, after her.

What happens, and what the bot does:

1. **Sign-up.** The bot starts its own sign-up: `POST https://botusign.com/api/v1/agent/signup` with `{"agent_name":"<its name>"}`. No key. It keeps `device_code` to itself.
2. **One link, one approval.** The bot gives the person `verification_url` and says to open it. The person signs in with Google, presses Approve, and (a new organization has no plan yet) enters a card on the Stripe page that follows. That is the only time the person leaves the chat. They land back on a "done" page.
3. **The key.** The bot polls `POST /api/v1/agent/signup/poll` every 3 seconds with `{"device_code":"…"}`. When `status` is `approved` the reply carries `api_key` once. Then it calls `GET /api/v1/billing` every few seconds until `plan` is `org` (usually within seconds of the card page).
4. **Create and send.** One call: the file, who signs, and whether the person signs too.

```bash
curl -s -X POST https://botusign.com/api/v1/envelopes \
  -H "Authorization: Bearer $BOTUSIGN_KEY" -H "Idempotency-Key: services-agreement-jane" \
  -F file=@contract.pdf -F title="Services Agreement" \
  -F 'to=Jane Doe <jane@acme.com>' -F sender_signs=true
```

5. **Tell the person.** `envelope.awaiting` says who signs first. Jane gets an email with her own signing link, from the person who approved the bot. When she has signed, the person is emailed "Your turn to sign: Services Agreement" with their own link. When the last person has signed, both of them are emailed the finished agreement with the signed PDF and the certificate (signing history) attached, plus a download link that works for 30 days. The bot can also read the result with `GET /api/v1/envelopes/{id}` and `GET /api/v1/envelopes/{id}/documents`.

Notes on the send call:

- `to` is one or more people as `Name <email>`, separated by commas or new lines. Everyone in `to` signs at the same time. Use the JSON form (below) for a signing order, roles or fields.
- `sender_signs=true` adds the person behind the key (the one who pressed Approve) as the last signer, so they sign after everyone named. `sender_signs=first` makes them sign before everyone. Leave it out when the person only sends. If the person's own email is already in the list, they are not added twice.
- The PDF is the `file` part (the names `pdf` and `document` also work). If the bot can only reach the file by address, send `-F pdf_url=https://…/contract.pdf` instead: a public HTTPS address that answers with a PDF, up to 10 MB and three redirects. Addresses on a private network or with a login in them are refused (`400 invalid_pdf_url`). A JSON body with `pdf_base64` works too.
- JSON equivalent: `{"title":"Services Agreement","pdf_url":"https://…","recipients":[{"name":"Jane Doe","email":"jane@acme.com"}],"sender_signs":true}`. MCP `create_envelope` takes the same arguments (`pdf_url` or `pdf_base64`, `sender_signs`).
- Fields are placed for you, by the printed names and roles in the signature blocks, then in document order. `analyze_document` shows where before sending, and `get_fields`, `update_field`, `add_field` and `remove_field` fix a field that landed wrong. See [Placing signature fields without coordinates](#placing-signature-fields-without-coordinates).
- A bot that already holds a key skips steps 1 to 3. A bot that cannot make an HTTPS POST (no code tool, no browser tool) cannot do any of this; the person sends from the web app at https://botusign.com/app/new.
## What works today

| Client | Works today | How |
| --- | --- | --- |
| Any agent that can make an HTTPS call (Hermes, a script, your own agent) | Yes | REST at `https://botusign.com/api/v1`, or MCP at `POST https://botusign.com/api/mcp`, with `Authorization: Bearer bsk_live_...`. No SDK is needed. See [Connect with a key](#connect-with-a-key-about-a-minute). |
| Claude custom connector | Yes | Customize, Connectors, Add custom connector. URL `https://botusign.com/api/mcp`, authentication No sign in, Request headers: name `Authorization`, value `Bearer bsk_live_...`. Claude describes Request headers as a beta. If your account does not show it, use REST. |
| ChatGPT desktop app and Codex | Yes | A `~/.codex/config.toml` entry that sends the key as a header. See [Codex and the ChatGPT desktop app](#codex-and-the-chatgpt-desktop-app). |
| Grok CLI | Yes | `grok mcp add --transport http botusign https://botusign.com/api/mcp --header "Authorization: Bearer $BOTUSIGN_KEY"`. |
### Codex and the ChatGPT desktop app

Both read `~/.codex/config.toml`. Set `BOTUSIGN_AUTHORIZATION` in the environment that starts them to the full header value (`Bearer bsk_live_...`), then add:

```toml
[mcp_servers.botusign]
url = "https://botusign.com/api/mcp"

[mcp_servers.botusign.env_http_headers]
Authorization = "BOTUSIGN_AUTHORIZATION"
```

Restart the app or start a new Codex session. `/mcp` lists `botusign`. Ask it to call `get_billing`. Keep the key out of the file.

- Base URL (today): `https://botusign.com`
- MCP endpoint: `POST /api/mcp`
- REST base: `/api/v1`
- Plan: **Org**, $1,200 per month for the whole organization, for up to 250 people and with 50,000 new agent envelopes included each month, then $0.10 each. It includes MCP and REST, webhooks, templates, bulk calls of up to 500 rows, and [running the organization from the API](#run-the-organization) (members, API keys, audit log).
- The plan is read on every request. A key can always reach the billing and usage calls; every other call stops working the moment the organization has no active plan (`403 plan_required`, with an `upgrade` field that says how to start one).
- Pricing rules are in [Billing and rounds](#billing-and-rounds). Buying a plan over the API is in [Billing over the API](#billing-over-the-api).

## Sign up as an agent

You do not need an account or a key to begin. Start the sign-up yourself, show one link to a person, and poll. That one link is all a person has to open: they sign in with Google, press Approve (step 2), and, if the organization has no plan yet, are taken straight to Stripe's page to enter a card once (step 4). The agent never signs in with Google and never handles a card. After that the agent needs nothing from the website. The reply to your last poll carries your API key.

```bash
export BOTUSIGN=https://botusign.com
```

**1. Start.** No key. `agent_name` is 1 to 80 characters and is what the person sees. `org_name` (2 to 120) is optional.

```bash
curl -s $BOTUSIGN/api/v1/agent/signup -H "Content-Type: application/json" \
  -d '{"agent_name":"Contracts agent","org_name":"Acme Co"}'
```

```json
{
  "signup_id": "uuid",
  "device_code": "…43 characters, secret",
  "user_code": "BSGN-7KQ2",
  "verification_url": "https://botusign.com/agent/approve?code=BSGN-7KQ2",
  "expires_in": 900,
  "interval": 3,
  "instructions": "A person has to approve this once. Show them …"
}
```

**2. Get it approved.** Show the person `verification_url` (the `user_code` is for reading aloud). Or, if you drive a browser that is already signed in to Google, open the address yourself and press Approve. The page says "The agent <agent_name> wants to sign up with BotUsign", lets the person choose an organization (a new one, or one where they are an owner or admin), and has Approve and Deny. If they are signed out they are sent through Google first and brought back. After Approve, a new organization goes straight to Stripe's page for the card and comes back to a "done" page; an organization that already has a plan sees "done" at once. Keep `device_code` to yourself: it is the only thing that collects the key.

**3. Poll** every `interval` seconds (3) until `status` is not `pending`.

```bash
curl -s $BOTUSIGN/api/v1/agent/signup/poll -H "Content-Type: application/json" \
  -d '{"device_code":"<device_code>"}'
```

| `status` | Meaning |
| --- | --- |
| `pending` | Nobody has decided yet. Keep polling. |
| `approved` | Approved. This one reply carries `api_key`. Store it now. |
| `consumed` | The key was already handed over. It is never shown again. |
| `denied` | The person said no. Stop. |
| `expired` | Nobody approved within 15 minutes (or the key was not collected within 15 minutes of approval). Start again. |

An unknown `device_code` is `404 invalid_device_code`. Two polls at the same moment cannot both get a key: one gets `approved`, the other `consumed`.

```json
{
  "status": "approved",
  "api_key": "bsk_live_…",
  "key_id": "uuid",
  "org": { "id": "uuid", "name": "Acme Co" },
  "plan": {
    "plan": "none",
    "status": "none",
    "trial_ends_at": null,
    "…": "the rest of GET /api/v1/billing"
  },
  "next_steps": ["Store api_key now. …"]
}
```

The key is created in the name of the person who approved. It is named after `agent_name`, is shown once, and only its SHA-256 is stored. If you lose it, start again, or ask a person to make another under Settings, API and MCP.

**4. Wait for the plan.** A new organization has no plan, and until it has one only the billing and usage calls work (everything else is `403 plan_required`). The person normally pays on the Stripe page that follows Approve, so just call `GET /api/v1/billing` every few seconds until `plan` is `org`. If they closed that page, or an approval was made before the card step existed, ask for a checkout link and give it to them:

```bash
curl -s -X POST $BOTUSIGN/api/v1/billing/checkout \
  -H "Authorization: Bearer $BOTUSIGN_KEY" -H "Content-Type: application/json" \
  -d '{"plan":"org"}'
```

The reply carries `checkout_url`. The person enters a card once on the Stripe page, and the plan usually turns on within seconds. Poll `GET /api/v1/billing` until `plan` is `org`. Stripe tells BotUsign when the payment completes; while that message is on its way, BotUsign also asks Stripe directly each time you call `GET /api/v1/billing`, so a late message does not keep the plan off. Until `plan` is `org`, every other call answers `403 plan_required`. If it is still `none` after two minutes, tell the person to write `support@botusign.com` and do not start a second checkout.

**5. Send.** The rest of this page applies. Add an `Idempotency-Key` header so a retry never sends twice.

```bash
curl -s -X POST $BOTUSIGN/api/v1/envelopes \
  -H "Authorization: Bearer $BOTUSIGN_KEY" -H "Content-Type: application/json" \
  -H "Idempotency-Key: enrollment-2291" \
  -d '{"title":"Services Agreement","pdf_base64":"JVBERi0x…","recipients":[{"name":"Ada Okafor","email":"ada@example.com","role":"signer","order":1}],"external_id":"enrollment-2291"}'
```

Limits on this flow: `POST /api/v1/agent/signup` allows 10 starts per 10 minutes per IP address. The poll allows 120 per minute per IP address and 60 per minute per `device_code`. Both answer `429 rate_limited` with `Retry-After`.

## Claude with no key: managed sign-in

For a Claude organization on the Team or Enterprise plan. An owner sets it up once. After that, every person who is in the Claude organization and is also a member of the BotUsign organization has BotUsign in Claude with no key to paste and no consent page, and Claude keeps them signed in by itself, so nobody authorizes again. Claude calls this Enterprise Managed Auth (managed authorization) and calls the issuer BotUsign relies on a trusted issuer: Claude signs a short-lived assertion that says who the person is, and BotUsign accepts it only from the issuer address you save.

1. In BotUsign, an owner or admin opens Settings, API and MCP, and finds Claude sign-in for your team. Copy the Tenant ID shown there.
2. In Claude, an owner opens Organization settings, Connectors, Add, Custom, Web, and adds `https://botusign.com/api/mcp`.
3. Open that connector. Under Authentication, press Set up on the Managed authorization row, and choose Claude-issued as the identity source. Paste the Tenant ID into Claude's Tenant ID field. Copy the Issuer URL Claude shows; it looks like `https://identity.anthropic.com/issuers/<id>`.
4. In BotUsign, paste that Issuer URL into Trusted issuer URL, tick "Let people in my Claude organization sign in this way", and press Save.
5. In Claude, press Run test, and when it passes, enable it. People in the Claude organization now have BotUsign as a connector that connects itself the first time they use it.

What to expect:

- BotUsign finds the person by the email address in the assertion (capitalization is ignored) among the members of the BotUsign organization. Someone who is in Claude but not yet a member is refused with `invalid_grant`; invite them under Settings, Team (or `invite_member`) and they connect on the next try. Claude's own user id is never used to find a person.
- The access token lasts 1 hour. It acts as that person, in that organization, with the same tools as a key, and their role still decides what the member, key and audit tools allow. Claude replaces the token before it ends without asking anyone. Removing the person from BotUsign, changing the issuer, or turning managed sign-in off stops it at once. People who signed in this way are listed under Connected apps as "Signed in by your trusted issuer".
- More than one BotUsign organization can save the same issuer URL. The Tenant ID from step 1 tells BotUsign which one an assertion is for, so always enter it in Claude.
- Claude describes Claude-issued assertions as a beta and shows the choice only to organizations that have it. If your organization does not show Claude-issued under Identity source, connect with a key instead (see [Connect with a key](#connect-with-a-key-about-a-minute)) or follow [One message to your bot](#one-message-to-your-bot-start-here).
- A `bsk_live_` key and the one-message sign-up work exactly as before, beside this.

For people who build a client, or whose identity provider issues the assertion: `POST https://botusign.com/api/oauth/token`, form-encoded, with `grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer`, `assertion`, `client_id`, `scope` and `resource` (the MCP endpoint; optional). The assertion is an Identity Assertion JWT Authorization Grant: `typ` `oauth-id-jag+jwt`, `ES256` or `RS256`, `iss` equal to the saved issuer URL, signed by a key in the `jwks_uri` of `<iss>/.well-known/openid-configuration` (whose `issuer` must equal `iss`), `aud` equal to `https://botusign.com`, a `client_id` claim equal to the request's `client_id`, `sub`, `email`, `iat`, `exp` (at most an hour after `iat`, 60 seconds of clock skew) and a `jti` that has not been used before. Claude's `client_id` is the address of its client metadata document, `https://claude.ai/oauth/mcp-oauth-client-metadata`. A check that does not pass answers `400 invalid_grant` with the reason. A good one answers `access_token`, `token_type`, `expires_in` and `scope`, and no refresh token. The authorization server document lists `urn:ietf:params:oauth:grant-type:jwt-bearer` under `grant_types_supported` and sets `client_id_metadata_document_supported`. The saved issuer can also be an identity provider's issuer URL.

## Connect from a chat app

An app that supports the standard MCP sign-in (OAuth 2.1) needs only this address:

```
https://botusign.com/api/mcp
```

BotUsign's sign-in server is live and passes BotUsign's own tests with a client that follows the standard. If an app's connector screen cannot finish the sign-in, use a key instead, or follow [One message to your bot](#one-message-to-your-bot-start-here), which needs no connector.

When an app does support it, there is no key to paste. The app finds the sign-in by itself, sends the person to BotUsign, and comes back with a token.

1. The person adds the address as a custom connector (in Claude or ChatGPT), or the app's directory entry points at it.
2. The app calls the endpoint with no credentials and gets `401` with `WWW-Authenticate: Bearer resource_metadata="https://botusign.com/.well-known/oauth-protected-resource/api/mcp"`.
3. The app reads that document, then the authorization server document, registers itself, and opens the authorization page in a browser.
4. The person signs in with Google if they are not already, chooses the organization (or creates a new one), and presses Allow. Deny sends the app `access_denied`.
5. The app swaps the code for an access token and calls the same endpoint with `Authorization: Bearer <token>`.

| Document or endpoint | Address |
| --- | --- |
| Protected resource (`resource` is the MCP endpoint) | `https://botusign.com/.well-known/oauth-protected-resource/api/mcp` (also at `/.well-known/oauth-protected-resource`) |
| Authorization server | `https://botusign.com/.well-known/oauth-authorization-server` (also at `/.well-known/openid-configuration`) |
| Authorization page | `https://botusign.com/oauth/authorize` |
| Token | `POST https://botusign.com/api/oauth/token` |
| Dynamic client registration (RFC 7591) | `POST https://botusign.com/api/oauth/register` |
| Revocation (RFC 7009) | `POST https://botusign.com/api/oauth/revoke` |

How it works: OAuth 2.1, authorization code with PKCE (`S256` is required; `plain` is refused), `redirect_uri` matched exactly (a loopback address may use any port), the `resource` parameter (RFC 8707) must be the MCP endpoint when sent, and the answer carries `iss` (RFC 9207). Clients register themselves with dynamic client registration; public clients (`token_endpoint_auth_method: none`) and confidential clients (`client_secret_basic`, `client_secret_post`) are both accepted. An app can instead use the https address of its own client metadata document as its `client_id`; BotUsign reads the document (up to 64 KB, redirect addresses listed in it, no shared secret) and treats the app as a public client. The one scope is `mcp`.

Tokens: the access token is `bso_…` and lasts 1 hour. The refresh token is `bsr_…`, lasts 30 days, and is replaced on every use; using an old one again disconnects the app. A token works only at `/api/mcp`, never on REST, and it acts as the person who signed in, in the organization they chose: the same 42 tools as a key, and their role in the organization still decides what the member, key and audit tools allow. Access is checked on every request, so removing the person from the organization or disconnecting the app stops it at once.

Disconnect any time under Settings, API and MCP, Connected apps (the person who connected it, or an owner or admin).

Every tool has a `title` and `annotations`. `readOnlyHint` is true for tools that only read. `destructiveHint` is true for tools that change or remove something that exists (void, update, archive, delete, revoke, remove, change a role). Tools that only add or send are neither. `openWorldHint` is true when the call reaches a person or service outside BotUsign, such as a signer's inbox. Directories and clients use these to decide which calls to confirm.

## Connect with a key (about a minute)

1. In the app, open Settings, API and MCP, name a key (for example "Contracts agent"), and copy it. It is shown once. Only its SHA-256 is stored. Owners and admins can create keys. Revoking takes effect on the next request.
2. Add the connector to the MCP client. Hermes, Cursor, and any agent that takes a server URL and request headers use these two values, in whatever config format the client reads (the JSON below is the common shape). An agent with no MCP support can skip this step and call REST with the same header:

```json
{
  "mcpServers": {
    "botusign": {
      "url": "https://botusign.com/api/mcp",
      "headers": { "Authorization": "Bearer bsk_live_..." }
    }
  }
}
```

3. Ask the client to list tools. An organization on the Org plan sees 42. An organization with no plan sees only 4: `get_billing`, `create_checkout_session`, `create_portal_session` and `get_usage`.
4. Optional, so the agent never has to poll: call `create_webhook` with a public HTTPS URL and keep the `signing_secret` it returns. See [Webhooks](#webhooks).

Streamable HTTP, stateless JSON responses, protocol versions 2025-06-18, 2025-03-26, 2024-11-05. `tools/call` results carry the JSON in `structuredContent` and in `content[0].text`. Failures set `isError: true` and the text is `{"error":{"code","message"}}`.

Raw call:

```bash
curl -s https://botusign.com/api/mcp \
  -H "Authorization: Bearer $BOTUSIGN_KEY" -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"list_envelopes","arguments":{"awaiting_signature":true}}}'
```

## Authentication

```
Authorization: Bearer bsk_live_<43 characters>
```

On `/api/mcp` the same header also takes an access token from the sign-in above (`Authorization: Bearer bso_…`). A missing, wrong or expired credential on `/api/mcp` answers `401` with `WWW-Authenticate: Bearer resource_metadata="…"` (and `error="invalid_token"` when one was sent), which is how a connector learns where to sign in. REST answers `401` with a plain `Bearer` challenge and takes keys only.

The session cookie is never read by the API, so a browser tab cannot call it on a user's behalf. Rate limits: 300 requests per minute per IP and 600 per minute per key (`429 rate_limited`, with `Retry-After`).

Signing links are intentionally not returned by any API call. BotUsign emails each signer their own single-use link. The one exception is a bulk call over REST while email delivery is not connected: see [Bulk](#bulk-send-to-a-list). An agent that needs the person to act uses `remind` or `resend_envelope`.

### Who the signer hears from

An envelope sent with a key is sent in the name of the person who created the key (or approved the agent's sign-up). The signer's email says "<that person's name> sent you "<title>" to sign", and their reply goes to that person's email address (`Reply-To`). The `From` address is always BotUsign's own sending address. If the person who made the key is no longer a member of the organization, the sender is the organization's name and there is no `Reply-To`. Reminders, resends and revisions sent with the same key keep the same sender.

### What each person receives

- **Each signer** gets an email with their own single-use link when it is their turn. If the order has steps, the next person is emailed when the one before finishes, and the email says who signed: "Your turn to sign: <title>".
- **The person who sent it** (the key's owner) is a signer when `sender_signs` is set, and gets that same "Your turn to sign" email, with their own link, when everyone before them has signed (with `"first"` they get an email titled `Sign "<title>"` as soon as it is sent). When the key's owner is not a signer they are told when the agreement is finished.
- **When the last person has signed**, every signer, every cc and the person who sent it gets one email, "Completed: <title>", with two PDFs attached: the signed agreement (`<title> - signed.pdf`) and the certificate with the signing history (`<title> - certificate.pdf`). Signers and cc also get a download link that works for 30 days; the person who sent it, when they are not a signer, gets a link to the agreement in the web app. A person who is both sender and signer gets one email, not two. If the two PDFs together are too large to attach (over about 17 MB), or the mail provider refuses the attachments, the email goes without them and keeps the link, so the agreement is never lost.

## The loop, as tools

| Step | Tool | REST | Needs |
| --- | --- | --- | --- |
| Send a PDF | `create_envelope` | `POST /api/v1/envelopes` with a `file` upload, `pdf_url` or `pdf_base64` | active plan |
| Send a draft | `send_envelope` | `POST /api/v1/envelopes/{id}/send` | active plan |
| Check status | `get_envelope` | `GET /api/v1/envelopes/{id}` | active plan |
| Find who has not signed | `list_envelopes` | `GET /api/v1/envelopes?awaiting_signature=true` | active plan |
| Edit and send again | `revise_envelope` | `PATCH /api/v1/envelopes/{id}` | active plan |
| Send again unchanged | `resend_envelope` | `POST /api/v1/envelopes/{id}/resend` | active plan |
| Nudge the signer | `remind` | `POST /api/v1/envelopes/{id}/remind` | active plan |
| Cancel | `void_envelope` | `POST /api/v1/envelopes/{id}/void` | active plan |
| Signed PDF and certificate links | `get_documents` | `GET /api/v1/envelopes/{id}/documents` | active plan |
| The PDF bytes themselves | (REST only) | `GET /api/v1/envelopes/{id}/documents/{signed\|certificate\|original}` | active plan |
| Proof | `get_evidence` | `GET /api/v1/envelopes/{id}/evidence` | active plan |
| Allowance and cost so far | `get_usage` | `GET /api/v1/usage` | any, also with no plan |
| Plan, allowance, what to do next | `get_billing` | `GET /api/v1/billing` | any, also with no plan |
| Get a link for a person to pay | `create_checkout_session` | `POST /api/v1/billing/checkout` | no plan needed |
| Get a link to update the card, see invoices, cancel | `create_portal_session` | `POST /api/v1/billing/portal` | after a paid plan exists |
| Hear about changes (no polling) | `create_webhook` | `POST /api/v1/webhooks` | active plan |
| List endpoints | `list_webhooks` | `GET /api/v1/webhooks` | active plan |
| Send a test event | `test_webhook` | `POST /api/v1/webhooks/{id}/test` | active plan |
| Remove an endpoint | `delete_webhook` | `DELETE /api/v1/webhooks/{id}` | active plan |
| Templates | `list_templates`, `get_template` | `GET /api/v1/templates`, `GET /api/v1/templates/{id}` | active plan |
| Fill a template | `create_envelope_from_template` | `POST /api/v1/envelopes` with `template_id` | active plan |
| Many at once | `bulk_send_from_template` | `POST /api/v1/templates/{id}/bulk` | active plan |
| See where fields would go, before sending | `analyze_document` | `POST /api/v1/documents/analyze` | active plan |
| See, move, add and remove fields on a draft | `get_fields`, `update_field`, `add_field`, `remove_field` | `GET`, `POST` `/api/v1/envelopes/{id}/fields`, `PATCH`, `DELETE` `/api/v1/envelopes/{id}/fields/{field_id}` | active plan |
| Make a template from a PDF | `create_template` | `POST /api/v1/templates` | active plan |
| Change a template | `update_template` | `PATCH /api/v1/templates/{id}` | active plan |
| Retire a template | `archive_template` | `DELETE /api/v1/templates/{id}` | active plan |
| Make a template from an envelope | `create_template_from_envelope` | `POST /api/v1/templates/from-envelope` | active plan |
| One PDF to a list of people | `bulk_create_envelopes` | `POST /api/v1/envelopes/bulk` | active plan |
| Progress of a bulk call | `get_batch` | `GET /api/v1/batches/{id}` | active plan |
| Nudge everyone still pending | `remind_batch` | `POST /api/v1/batches/{id}/remind` | active plan |
| Run the organization | `list_members`, `invite_member`, `set_member_role`, `remove_member`, `list_api_keys`, `create_api_key`, `revoke_api_key`, `get_audit_log` | `/api/v1/org/members`, `/api/v1/org/api-keys`, `/api/v1/org/audit` | active plan, key made by an owner or admin |

Every id is a UUID. Every tool returns JSON. Field names are snake_case. A key whose organization has no active plan gets `403 plan_required` on every tool except the billing and usage ones (see [Billing over the API](#billing-over-the-api)). The five tools that create or change an envelope (`create_envelope`, `create_envelope_from_template`, `send_envelope`, `revise_envelope`, `resend_envelope`) accept an idempotency key: see [Safe retries](#safe-retries-idempotency).

Every envelope response includes `available_actions`, the tools that make sense right now (for example `["get_envelope","remind","resend_envelope","revise_envelope","void_envelope"]`). An agent can follow it instead of memorizing the state machine.

### create_envelope

```json
{
  "title": "Services Agreement",
  "message": "Project 12 terms",
  "pdf_base64": "JVBERi0x...",
  "recipients": [
    { "name": "Ada Okafor", "email": "ada@example.com", "role": "signer", "order": 1 },
    { "name": "Hannah Lee", "email": "hannah@acme.example", "role": "signer", "order": 2 },
    { "name": "Legal", "email": "legal@acme.example", "role": "cc", "order": 3 }
  ],
  "fields": [
    { "recipient_index": 0, "type": "signature", "page": 2, "x": 0.1, "y": 0.78, "w": 0.3, "h": 0.07 }
  ],
  "expires_in_days": 30,
  "send": true,
  "external_id": "enrollment-2291",
  "metadata": { "project": "12", "source": "airtable" },
  "idempotency_key": "enrollment-2291"
}
```

- `external_id` (up to 200 characters) and `metadata` (up to 20 keys; keys up to 40 characters; values are strings up to 500) tie the envelope to your own records. Both come back on every envelope response, on `list_envelopes`, and inside `data.envelope` of every webhook, so a receiver never has to look the envelope up. `list_envelopes` can filter by `external_id`. An `external_id` is not required to be unique. Both are optional and `null` when not set. `revise_envelope` can replace them (`null` clears them; leave them out to keep them), and `create_envelope_from_template` takes them too.
- `idempotency_key` (or the `Idempotency-Key` header on REST) makes a retry safe: see [Safe retries](#safe-retries-idempotency).
- Send the PDF one of three ways: `pdf_base64`, `pdf_url` (a public HTTPS address that answers with a PDF; up to three redirects; private-network addresses and addresses with a login in them are `400 invalid_pdf_url`; one that does not answer, answers an error or is not a PDF is `422 invalid_pdf_url`), or on REST a `multipart/form-data` upload (see [Upload a file](#upload-a-file-with-curl)). Exactly one of `pdf_base64` and `pdf_url`.
- `sender_signs` (`true` or `"last"`, or `"first"`): the person behind the key signs too, without you knowing their email. `true` adds them as the last entry of `recipients` (the entries you listed keep their positions, so `recipient_index` in `fields` and `placements` still counts your own list) and gives them the next signing step after everyone else; `"first"` has them sign before everyone. They are emailed when it is their turn, and if their email is already in `recipients` they are not added twice. A key that belongs to no one (the person who made it has left) answers `400 invalid_request`.
- PDF up to 10 MB and 100 pages. The file must be a readable, unencrypted PDF (`422 invalid_pdf` otherwise). BotUsign rebuilds it page by page, which drops embedded scripts, document actions, and annotations, and the hash of the rebuilt file is what gets signed.
- Up to 20 recipients and 200 fields. `role` is one of `signer, applicant, vendor, customer, partner, employee, cc`. `cc` receives the finished copy and never signs.
- Field `type` is `signature, initials, date, text, checkbox`. Positions are fractions from 0 to 1 measured from the top left. Omit `fields` and BotUsign places them for you, in this order: text tags in the PDF (`{{sign}}`, `{{sign:2}}`), your `placements` (fields found by text in the PDF), the signature lines the document already has, then a signature and a date on the last page. The response's `placement` block says which and where. See [Placing signature fields without coordinates](#placing-signature-fields-without-coordinates).
- Equal `order` values sign in parallel. Different values sign one after another; the next signer is emailed when the previous one finishes.
- `send: false` makes a draft (not counted, not emailed). Send it later with `send_envelope`.

Returns (REST status 201):

```json
{
  "envelope": {
    "id": "uuid",
    "title": "Services Agreement",
    "status": "sent",
    "round": 1,
    "rounds_remaining": 199,
    "supersedes": null,
    "superseded_by": null,
    "available_actions": ["get_envelope", "remind", "resend_envelope", "revise_envelope", "void_envelope"],
    "created_at": "2026-11-02T20:00:00.000Z",
    "first_sent_at": "2026-11-02T20:00:01.000Z",
    "sent_at": "2026-11-02T20:00:01.000Z",
    "completed_at": null,
    "expires_at": "2026-12-02T20:00:01.000Z",
    "page_count": 2,
    "external_id": "enrollment-2291",
    "metadata": { "project": "12", "source": "airtable" },
    "awaiting": ["ada@example.com"],
    "recipients": [
      {
        "id": "uuid", "name": "Ada Okafor", "email": "ada@example.com", "role": "signer", "order": 1,
        "status": "sent", "notified_at": "…", "viewed_at": null, "consented_at": null, "signed_at": null,
        "declined_at": null, "reminder_count": 0
      }
    ]
  },
  "billing": {
    "counted_as": "included",
    "new_envelope_charged_usd": 0,
    "agent_envelopes_used": 1,
    "agent_envelopes_included": 100,
    "note": "Counted once at first send, inside the monthly allowance. Revisions, resends and reminders of this envelope are free."
  }
}
```

`billing.counted_as` is `none` (a draft), `included`, `overage`, or `unmetered_app_send` (sent from the web app).

`viewed_at` on each recipient is the first time that person opened their link. It is `null` until then, it does not move on later opens, and a revision (`revise_envelope`) resets it to `null` because everyone signs again. To learn it without polling, subscribe to `recipient.viewed` (see [Webhooks](#webhooks)).

#### Upload a file with curl

`POST /api/v1/envelopes` also takes `multipart/form-data`, so a shell never has to encode the PDF. The same rules apply, and the same errors come back.

```bash
curl -s -X POST https://botusign.com/api/v1/envelopes \
  -H "Authorization: Bearer $BOTUSIGN_KEY" -H "Idempotency-Key: services-agreement-jane" \
  -F file=@contract.pdf -F title="Services Agreement" \
  -F 'to=Jane Doe <jane@acme.com>, Bob Ray <bob@acme.com>' -F sender_signs=true
```

| Form field | Meaning |
| --- | --- |
| `file` | The PDF (`pdf` and `document` also work). Or send `pdf_url` instead. |
| `title` | Required. |
| `to` | People as `Name <email>`, separated by commas or new lines. They sign at the same time. A bare email uses the part before the `@` as the name. |
| `recipients` | The JSON array from the body above, for a signing order and roles. Send `recipients` or `to`, not both. |
| `sender_signs` | `true`, `last` or `first` (see above). |
| `message`, `external_id`, `idempotency_key`, `expires_in_days`, `send` | As in the JSON body. `send=false` makes a draft. |
| `metadata`, `fields`, `placements` | JSON text, as in the body above. |

### send_envelope

`{ "envelope_id": "uuid", "expires_in_days": 30, "idempotency_key": "…" }`. Sends a draft. Returns `{ "envelope", "billing" }`. This is the moment a new envelope is counted. Calling it on anything that is not a draft returns `409 invalid_state`, so a retry can never double count. If you would rather have the retry return the first response, send an idempotency key (see [Safe retries](#safe-retries-idempotency)).

### get_envelope

`{ "envelope_id": "uuid" }`. Returns the `envelope` object above plus `evidence`:

```json
{
  "evidence": {
    "document_sha256": "…",
    "completed_sha256": null,
    "audit_chain_valid": true,
    "audit_chain_head": "…",
    "events": 4,
    "email_deliveries": [{ "type": "recipient.sent", "at": "…", "to": "ada@example.com", "message_id": "provider-message-id" }]
  }
}
```

`email_deliveries` is the proof the email left BotUsign: provider message ids, per signer, for the first send, every resend, and every reminder.

### list_envelopes

`{ "status": "sent", "awaiting_signature": true, "external_id": "enrollment-2291", "limit": 50, "cursor": "…" }` (all optional, limit 1 to 100, default 50). REST takes the same names as query parameters. Returns `{ "envelopes": [ { id, title, status, round, rounds_remaining, sent_at, completed_at, expires_at, external_id, metadata, signers: [ { name, email, status, viewed_at } ] } ], "next_cursor": "…" | null }`.

Newest first. When `next_cursor` is not `null`, there is more: send it back as `cursor` with the same filters to get the next page. A cursor never repeats or skips an envelope, even if new ones arrive while you page. `next_cursor` is `null` on the last page. A cursor you did not get from this call is `400 invalid_cursor`. Example, every envelope for one of your records:

```bash
curl -s -H "Authorization: Bearer $BOTUSIGN_KEY" "$BOTUSIGN/api/v1/envelopes?external_id=enrollment-2291&limit=100"
curl -s -H "Authorization: Bearer $BOTUSIGN_KEY" "$BOTUSIGN/api/v1/envelopes?external_id=enrollment-2291&limit=100&cursor=$NEXT_CURSOR"
```

### revise_envelope

Edit a sent, viewed, expired, or declined envelope and send it again as the next round of the same envelope. The id does not change.

`PATCH /api/v1/envelopes/{id}` or tool `revise_envelope`. Send at least one of:

```json
{
  "envelope_id": "uuid",
  "title": "Services Agreement v2",
  "message": "Start date moved to Feb 2",
  "pdf_base64": "JVBERi0x...",
  "recipients": [
    { "name": "Ada Okafor", "email": "ada@example.com", "role": "signer", "order": 1 },
    { "name": "Hannah Lee", "email": "hannah@acme.example", "role": "signer", "order": 2 }
  ],
  "fields": [ { "recipient_index": 0, "type": "signature", "page": 2, "x": 0.1, "y": 0.78, "w": 0.3, "h": 0.07 } ],
  "expires_in_days": 30
}
```

- `recipients` is the complete new list. People are matched by email: someone who stays keeps their identity, someone new is added, someone missing is removed. Omit it to keep the current people.
- `fields` is the complete new field list. Omit it to keep the current fields (values go back to their prefill). If you replace the PDF or recipients and omit `fields`, missing signature fields are placed automatically.
- Everyone signs the new version again. Earlier signatures and consents are cleared, and every earlier link stops working: the signer sees "This agreement was updated" and is pointed to the new email. To keep signatures already collected, use `resend_envelope` instead.
- No arguments besides `envelope_id` returns `400 nothing_to_revise`. The same goes for sending only `external_id` or `metadata`: a revision sends the envelope to everyone again, so it needs a change to the title, message, PDF, recipients or fields. You can send `external_id` and `metadata` along with a real change: each replaces the stored value, `null` clears it, and leaving it out keeps it.
- `idempotency_key` (or the `Idempotency-Key` header) makes a retry apply once: see [Safe retries](#safe-retries-idempotency).
- The old and new documents, and the revision itself, are recorded in the audit log (`envelope.revised`).

Returns:

```json
{
  "new_envelope": false,
  "supersedes": null,
  "envelope": { "id": "same uuid", "round": 2, "rounds_remaining": 198, "status": "sent", "…": "…" },
  "billing": { "counted_as": "none", "new_envelope_charged_usd": 0, "round": 2, "rounds_remaining": 198, "note": "Revision 1 of 199 on the same envelope. Free. After 199, the next revise or resend creates a new envelope that counts as a new send." }
}
```

### resend_envelope

Send the same envelope again with fresh links and a new expiry, keeping signatures already collected. Works on sent, viewed, and expired envelopes (an expired envelope is revived).

`POST /api/v1/envelopes/{id}/resend` with `{ "expires_in_days": 30, "idempotency_key": "…" }` (both optional), or tool `resend_envelope`. Earlier links stop working. Only the people who have not signed are emailed, and only the group whose turn it is. Returns the same shape as `revise_envelope`.

`remind` is different: it re-emails the current signer without issuing new links or changing the round, and is rate limited to one per signer per hour.

### remind

`{ "envelope_id": "uuid", "email": "ada@example.com" }`. `email` is optional. Returns `{ "reminded": ["ada@example.com"], "skipped": [] }`. A signer reminded within the last hour appears in `skipped` with the reason. A signer who is not up yet is never emailed. `409 nothing_to_remind` when nobody is waiting. BotUsign also sends automatic reminders: the first after 48 hours, then every 48 hours, at most three. Reminders are free and do not change the round.

### void_envelope

`{ "envelope_id": "uuid", "reason": "Wrong project" }`. Signers who open their link afterward see that it is no longer active. A voided envelope is final.

### get_documents

`{ "envelope_id": "uuid" }`. Available once `status` is `completed`.

```json
{
  "status": "completed",
  "original": { "url": "https://…", "sha256": "…" },
  "signed_pdf": { "url": "https://…", "sha256": "…" },
  "certificate_pdf": { "url": "https://…" },
  "expires_in_seconds": 900
}
```

Links are signed, private, and expire in 15 minutes. Before completion, `signed_pdf` and `certificate_pdf` are `null`. Fetch the links right away; ask again for fresh ones later.

Clients that cannot follow a URL can fetch the bytes directly with the same API key:

```bash
curl -s -H "Authorization: Bearer $BOTUSIGN_KEY" -o signed.pdf       $BOTUSIGN/api/v1/envelopes/$ID/documents/signed
curl -s -H "Authorization: Bearer $BOTUSIGN_KEY" -o certificate.pdf  $BOTUSIGN/api/v1/envelopes/$ID/documents/certificate
curl -s -H "Authorization: Bearer $BOTUSIGN_KEY" -o original.pdf     $BOTUSIGN/api/v1/envelopes/$ID/documents/original
```

`signed` and `certificate` return `409 invalid_state` until the envelope is completed. Any other value returns `404`. The response is `application/pdf` with `Content-Disposition: attachment`.

### get_evidence

Full hash-chained audit log: `document` hashes, `audit_chain { valid, head, length }`, `recipients`, and `events [ { seq, at, type, recipient, ip, user_agent, meta, hash } ]`. Each event includes the previous event's hash, and the database refuses updates and deletes on the events table. Event types include `envelope.created`, `envelope.sent`, `envelope.revised`, `envelope.resent`, `recipient.sent`, `recipient.reminded`, `recipient.viewed`, `recipient.consented`, `recipient.signed`, `envelope.completed`.

### get_usage

`GET /api/v1/usage` or tool `get_usage`. No input.

```json
{
  "plan": "org",
  "senders": 1,
  "period": { "start": "2026-11-01T00:00:00.000Z", "end": "2026-12-01T00:00:00.000Z" },
  "agent_envelopes": {
    "used": 1, "included": 50000, "remaining": 49999,
    "over_allowance": 0, "overage_usd_so_far": 0, "overage_usd_per_envelope": 0.1
  },
  "app_envelopes_sent": 0,
  "rules": { "counted": "…", "free": "…" }
}
```

Check it before a large batch. `period` is the Stripe billing period when one is active, otherwise the UTC calendar month.

### Template tools

`list_templates` and `get_template` take `{}` and `{ "template_id": "uuid" }` and return roles and prefill keys:

```json
{
  "id": "uuid",
  "name": "Client agreement",
  "title": "Client Agreement",
  "pages": 2,
  "roles": [
    { "key": "client", "name": "Client", "role": "applicant", "order": 1 },
    { "key": "countersigner", "name": "Countersigner", "role": "signer", "order": 2 }
  ],
  "prefill_keys": ["client_name", "project", "start_date"]
}
```

`create_envelope_from_template`:

```json
{
  "template_id": "uuid",
  "recipients": {
    "client": { "name": "Ada Okafor", "email": "ada@example.com" },
    "countersigner": { "name": "Hannah Lee", "email": "hannah@acme.example" }
  },
  "prefill": { "client_name": "Ada Okafor", "project": "Project 12", "start_date": "2026-11-16" },
  "title": "Client agreement: Ada Okafor",
  "message": "Welcome. This takes a minute.",
  "expires_in_days": 30,
  "send": true
}
```

`recipients` needs every role key the template defines. `prefill` keys must exist on the template (`unknown_prefill` otherwise). It also takes `external_id`, `metadata` and `idempotency_key`, with the same meaning as on `create_envelope`. Returns `{ "envelope", "billing" }` (REST status 201). `bulk_send_from_template` takes `{ "template_id", "rows": [ { recipients, prefill?, title? } ] }` with up to 500 independent rows; a failed row does not stop the rest, and each successful row counts as a new envelope. Its full response, row keys and retry behaviour are in [Bulk](#bulk-send-to-a-list). To create, change or retire templates yourself, see [Templates](#templates).

## Placing signature fields without coordinates

You never have to measure a page. Leave out `fields` and BotUsign finds where each person signs. It uses the first of these that applies:

1. `fields` you give, exactly as sent (`placement.method` is `explicit`).
2. Text tags written in the PDF (`tags`).
3. `placements`: you name text that is in the PDF and what goes next to it (`anchors`).
4. The signature lines the document already has: a "Signature" label, a line of underscores, a rule, "Employee signature", "Date:" beside it (`detected`).
5. A signature and a date in free space on the last page (`default`).

Tags and `placements` can be mixed: a tag for the signatures and a placement for one extra initials box. Send `fields` or `placements`, not both.

If a field lands in the wrong place, you do not have to start over. Read the fields with `get_fields`, fix the ones that are off with `update_field`, `add_field` and `remove_field` while the agreement is still a draft, then send. See [Fix a field that landed wrong](#fix-a-field-that-landed-wrong).

### What the PDF needs

- A text PDF, not a scan. Reading blanks depends on the words in the file. A PDF that is only a picture of a page (a scan or a photo) has no words to read, so BotUsign can only use its standard position on the last page (`method: "default"`, with a note that the text could not be read). Export the document from the program that made it, or run it through OCR first. A quick check: if you can select and copy text in a PDF viewer, it is a text PDF.
- Up to 10 MB and 100 pages, not password protected. Otherwise the call fails with `422 invalid_pdf` (or `413 payload_too_large` over 10 MB) and nothing is created.
- Pages that are rotated are not read; nothing is placed on them automatically. Use `fields`, `placements` or `add_field` for those pages.
- Looking is free: `analyze_document` tells you what BotUsign sees in a PDF (`text_found`, `readable`, what it would place and why) before you create anything.

### How blanks are recognised

BotUsign looks for a blank where a person writes, and a short label that says what the blank is for. Both have to be there. A blank with no label is left alone, and so is a label with no blank, unless the label stands by itself with room to write.

A blank is any of these:

- A drawn rule (a thin line). A rule built from several pieces counts as one: a line broken into segments, a row of short dashes, or a line of dots, as long as the pieces sit end to end on the same height.
- Typed underscores, dots or dashes (`Signature: ____________`).
- An empty box.
- A label by itself with free space to its right or above it (`Signature`, then nothing).

A label is a short line made only of label words, such as `Signature`, `Sign`, `By:`, `Date`, `Initials`, `Name` and `Title`, together with a party word (`Employee signature`, `Landlord initials`, `Client`, `Company:`) or a person's name from `recipients` (`Ada Okafor signature`). Label and blank can be side by side or one above the other. Text that is part of a sentence is never a label, however many times it says "signature": a heading such as `SIGNATURES`, `The Contractor's signature is required below`, or a table header is skipped. `analyze_document` lists what it skipped in `ignored_text`, with the reason.

What each label becomes:

| Label | Field |
| --- | --- |
| `Signature`, `Sign here`, `By:`, a line above a printed name | signature |
| `Date`, `Dated`, a blank inside a sentence that sets the date ("as of ______ (the Effective Date)") | date |
| `Initials` | initials |
| `Name`, `Printed name`, `Title`, `Position` | no field of its own. They help work out whose signature block it is. Add a `text` field with `add_field` if the signer should type them. |

Whose blank it is: each signer gets one signature block. A signer is matched to a block by words from the signer's `name` or company in the block (`Acme Holdings LLC`, `Ada Okafor`), by `role` (`employee`, `vendor`, `customer`, `applicant` and `partner` match words like Employee, Contractor, Client, Participant and Partner), by `Party A` and `Party B`, and otherwise by the order in the document: the first block goes to the first signer. A date goes to the signer whose block it sits beside or under. A date that belongs to no block (an `Effective Date` line on page 1) goes to the first signer in the document. Initials go to the party named in their label, otherwise by their order along the row. If there are more signers than signature blocks, the rest get a signature in free space on the last page, and a note says so. `witness` and `notary` lines are never given to a signer.

Every detected field has `source: "detected"`, a `confidence` of `high`, `medium` or `low`, and a `why` that says in one sentence what it was taken for (`line beside "Signature"`, `typed blank under the caption "Employee"`). Treat `low` as a guess and check it.

### Text tags

Type a tag where the field should go. BotUsign puts the field there and covers the tag text with a white box in the copy people sign, so the tag never shows. The original upload is kept as sent.

| Tag | Field |
| --- | --- |
| `{{sign}}` or `{{sign:1}}` | signature for the first signer |
| `{{sign:2}}` | signature for the second signer (signers are counted in the order of `recipients`, ignoring `cc`) |
| `{{initial:2}}` | initials |
| `{{date:2}}` | date signed |
| `{{text:1:Start date}}` | text box labeled "Start date", filled by that signer |
| `{{text:1:Project\|key=project}}` | text box with a prefill key, for templates |
| `{{check:1:I agree}}` | checkbox |
| `{{sign:1\|required=false}}` | optional field |

`[[sign:2]]` works the same as `{{sign:2}}`. The short forms `/sn1/` (signature), `/in1/` (initials), `/ds1/` and `/dt1/` (date), `/tx1/` (text), `/ck1/` (checkbox) are also read, for documents that come from other tools. Tag type words are not case sensitive. A tag for signer 3 in an envelope with 2 signers is `422 invalid_tag`, and so is a tag that names a role (`{{sign:client}}`) on a one-off envelope: role names are for [templates](#templates). Tags on rotated pages are ignored.

### Anchors: `placements`

```json
{
  "title": "Offer letter",
  "pdf_base64": "JVBERi0x...",
  "recipients": [
    { "name": "Ada Okafor", "email": "ada@example.com" },
    { "name": "Hannah Lee", "email": "hannah@acme.example" }
  ],
  "placements": [
    { "recipient_index": 0, "type": "signature", "anchor": "Employee signature" },
    { "recipient_index": 0, "type": "date", "anchor": "Employee signature", "position": "right" },
    { "recipient_index": 1, "type": "signature", "anchor": "Employer signature", "occurrence": "last" }
  ]
}
```

- `anchor` is text that is in the PDF, matched ignoring case and extra spaces. If it is not found the call fails with `422 anchor_not_found` and `closest_matches` lists the nearest text with its page. Nothing is created.
- `occurrence`: `first` (default), `last`, or a number counted in reading order. `page` limits the search to one page.
- `position`: `right`, `below`, `above` or `on`. Leave it out and BotUsign picks the free side: to the right of a blank, above a line, otherwise the first free side. A field never lands on printed words.
- `offset_x` and `offset_y` nudge the field (fractions of the page; positive is right and down). `width` and `height` resize it. `required`, `label` and `key` work as on `fields`.
- `revise_envelope` takes `placements` too (the complete new field list). A revision with a new PDF and no `fields` places again from that PDF's tags or lines.

### See before you send: `analyze_document`

`POST /api/v1/documents/analyze` or tool `analyze_document` reads a PDF and changes nothing. It is free and does not count as an envelope. Send `pdf_base64` or an `envelope_id`, and optionally `recipients` (`[{ "name", "role" }]`) so "Employee" and "Employer" lines go to the right person.

```json
{
  "page_count": 2,
  "text_found": true,
  "readable": true,
  "method_if_sent_now": "detected",
  "suggested_for_recipients": 2,
  "placed": { "fields": 4, "signatures": 2, "dates": 2, "initials": 0, "text": 0, "checkboxes": 0, "by_source": { "detected": 4 }, "low_confidence": 0 },
  "ignored_text": [
    { "page": 2, "text": "The signatures of both parties appear below.", "reason": "part of a sentence, not a label" },
    { "page": 2, "text": "SIGNATURES", "reason": "a heading, not a label" }
  ],
  "notes": [],
  "pages": [
    {
      "page": 2,
      "width_pt": 612, "height_pt": 792, "rotation": 0,
      "text_blocks": [ { "text": "Employee signature", "x": 0.117, "y": 0.62, "w": 0.18, "h": 0.014 } ],
      "tags_found": [],
      "signature_lines": [ { "kind": "rule", "purpose": "signature", "label": "Employee signature", "confidence": "high", "why": "line above the caption \"Employee signature\"", "x": 0.12, "y": 0.6, "w": 0.3 } ],
      "suggested_fields": [ { "recipient_index": 0, "type": "signature", "x": 0.12, "y": 0.55, "w": 0.3, "h": 0.06, "source": "detected", "matched": "rule: Employee signature (page 2)", "confidence": "high", "why": "line above the caption \"Employee signature\"" } ]
    }
  ]
}
```

All coordinates are fractions of the page from the top left, the same as `fields`. `placed` counts what would be created, `signature_lines` lists every blank that was recognised (with `kind` `rule`, `underscores`, `box` or `label`, its `purpose`, and `confidence`), and `ignored_text` lists text that mentions a signature or date but was left alone, with the reason. If a blank you expected is not in `signature_lines`, it was not recognised: use a tag or an anchor, or add the field after creating the draft (see below). Text blocks are capped (150 per page, 600 per call); `notes` says when they were. Use the text blocks to choose anchors. `readable: false` or `text_found: false` means the PDF has no readable text (a scan).

### The `placement` block

`create_envelope` returns a `placement` block next to `envelope` (and `billing`), and so does `revise_envelope` when it placed fields, so you can check what was done:

```json
{
  "placement": {
    "method": "detected",
    "summary": { "fields": 2, "signatures": 1, "dates": 1, "initials": 0, "text": 0, "checkboxes": 0, "by_source": { "detected": 2 }, "low_confidence": 0 },
    "fields": [
      { "recipient_index": 0, "type": "signature", "page": 2, "x": 0.12, "y": 0.55, "w": 0.3, "h": 0.06, "required": true, "label": null, "key": null, "source": "detected", "matched": "rule: Employee signature (page 2)", "confidence": "high", "why": "line above the caption \"Employee signature\"" },
      { "recipient_index": 0, "type": "date", "page": 2, "x": 0.55, "y": 0.575, "w": 0.18, "h": 0.03, "required": true, "label": null, "key": null, "source": "detected", "matched": "date line: Date (page 2)", "confidence": "high", "why": "line beside \"Date\"" }
    ],
    "notes": []
  }
}
```

`method` is `explicit`, `tags`, `anchors`, `detected` or `default`; each field's `source` is `explicit`, `tag`, `anchor`, `detected` or `default`, with `matched` (the tag, text or line it came from) and sometimes a `note`. Detected fields also carry `confidence` and `why`. `summary` counts what was placed, so "1 signature, 1 date" is easy to check against what you expected; `low_confidence` is how many fields are guesses. `notes` says what could not be done, for example that signer 2 had no signature line and was placed in free space on the last page. If the method is `default`, BotUsign found nothing to go on and used the standard position; tell the person, or fix it with the field tools below. In the web app, a PDF uploaded without fields opens in the editor with the same placement already suggested.

### Fix a field that landed wrong

Create the envelope with `send: false`, look at the fields, fix what is off, then call `send_envelope`. Nothing is counted or emailed until the send.

| Step | Tool | REST |
| --- | --- | --- |
| List the fields | `get_fields` | `GET /api/v1/envelopes/{id}/fields` |
| Add one | `add_field` | `POST /api/v1/envelopes/{id}/fields` |
| Move, resize, retype or reassign one | `update_field` | `PATCH /api/v1/envelopes/{id}/fields/{field_id}` |
| Remove one | `remove_field` | `DELETE /api/v1/envelopes/{id}/fields/{field_id}` |

They need an active plan, like `create_envelope`. Positions are fractions of the page from the top left (`x`, `y` is the top left corner of the field, `w` and `h` its size), the same as `fields`. `get_fields` works on any agreement. The three that change fields work on a draft (`create_envelope` with `send: false`), and after sending you use `revise_envelope` (see the end of this section). An id from another organization is `404 not_found`, like every other envelope call.

**`get_fields`**: `GET /api/v1/envelopes/{id}/fields`, or tool `get_fields` with `{ "envelope_id": "…" }`. Works on any agreement, draft or sent.

```json
{
  "envelope_id": "4154091e-1e74-4237-abef-28efff50dabc",
  "status": "draft",
  "page_count": 2,
  "editable": true,
  "how_to_change": "Use add_field, update_field and remove_field, then send_envelope.",
  "recipients": [
    { "index": 0, "id": "06a94131-8646-4b08-a391-027d92964efa", "name": "Ada Okafor", "email": "ada@example.com", "role": "signer", "signs": true },
    { "index": 1, "id": "6f7a8f5d-9ff2-4521-88b4-31f12e74bb25", "name": "Hannah Lee", "email": "hannah@acme.example", "role": "signer", "signs": true }
  ],
  "fields": [
    {
      "id": "b4326b37-2401-4232-815f-678b972ab951",
      "type": "signature", "page": 1, "x": 0.1, "y": 0.7, "w": 0.3, "h": 0.06,
      "required": true, "label": null, "key": null, "value": null,
      "recipient_index": 0, "recipient_id": "06a94131-8646-4b08-a391-027d92964efa",
      "recipient_email": "ada@example.com", "recipient_name": "Ada Okafor"
    }
  ]
}
```

`signers_without_signature` (a list of emails) and a `note` appear when a signer has no signature field yet; BotUsign adds one for each of them at send, using the same detection. On a sent agreement `editable` is `false` and `how_to_change` says to use `revise_envelope`. `fields` there already has the shape `revise_envelope` takes, so you can edit that list and send it back whole.

**`add_field`**: `POST /api/v1/envelopes/{id}/fields` (status 201), or tool `add_field` with `envelope_id` added to the same body.

```json
{ "recipient_email": "ada@example.com", "type": "date", "page": 1, "x": 0.5, "y": 0.7 }
```

Whose field: `recipient_email` (any capitalization) or `recipient_id`, one of the two, and the person must be a signer (not `cc`). `type` is `signature`, `initials`, `date`, `text` or `checkbox`. `w` and `h` are optional; left out they are the usual size (signature 0.28 x 0.06, initials 0.1 x 0.05, date 0.18 x 0.035, text 0.28 x 0.035, checkbox 0.03 x 0.022). Also optional: `required` (default `true`), and for text fields `label`, `key` and `value` (starting text).

```json
{
  "field": {
    "id": "4664ea76-b816-4738-a08f-58d418cf15cb",
    "type": "date", "page": 1, "x": 0.5, "y": 0.7, "w": 0.18, "h": 0.035,
    "required": true, "label": null, "key": null, "value": null,
    "recipient_index": 0, "recipient_id": "06a94131-8646-4b08-a391-027d92964efa",
    "recipient_email": "ada@example.com", "recipient_name": "Ada Okafor"
  },
  "field_count": 3
}
```

**`update_field`**: `PATCH /api/v1/envelopes/{id}/fields/{field_id}`, or tool `update_field` with `envelope_id` and `field_id`. Send only what changes: `page`, `x`, `y`, `w`, `h`, `type`, `required`, `label`, `key`, `value`, and `recipient_email` or `recipient_id` to hand the field to another signer. This moves the signature to the second signer and widens it:

```json
{ "x": 0.12, "y": 0.62, "w": 0.35, "recipient_email": "hannah@acme.example" }
```

```json
{
  "field": {
    "id": "b4326b37-2401-4232-815f-678b972ab951",
    "type": "signature", "page": 1, "x": 0.12, "y": 0.62, "w": 0.35, "h": 0.06,
    "required": true, "label": null, "key": null, "value": null,
    "recipient_index": 1, "recipient_id": "6f7a8f5d-9ff2-4521-88b4-31f12e74bb25",
    "recipient_email": "hannah@acme.example", "recipient_name": "Hannah Lee"
  },
  "changed": ["x", "y", "w", "recipient"],
  "field_count": 3
}
```

An empty body is `400 nothing_to_update`. Starting text (`value`) belongs to `text` fields only: changing a field to another type clears it.

**`remove_field`**: `DELETE /api/v1/envelopes/{id}/fields/{field_id}` (no body), or tool `remove_field` with `{ "envelope_id": "…", "field_id": "…" }`.

```json
{
  "removed": true,
  "field_id": "4664ea76-b816-4738-a08f-58d418cf15cb",
  "field_count": 2,
  "signers_without_signature": ["ada@example.com"],
  "note": "These signers have no signature field now. BotUsign places one for each when you send."
}
```

The last two keys appear only when the removal left a signer without a signature field.

Errors:

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_field` | The field would run past the page edge (`x + w` or `y + h` over 1), or its page is not in the document, or `add_field` has neither `recipient_email` nor `recipient_id`, or that person is only copied. The message says which. |
| 400 | `nothing_to_update` | `update_field` with nothing to change. |
| 400 | `limit_reached` | 200 fields on the agreement already. |
| 404 | `not_found` | The agreement or the field is not in your organization, or the person is not on the agreement (the message lists the signers' emails). |
| 409 | `invalid_state` | The agreement was already sent, is completed, or is voided. |

**After sending.** Fields are edited one at a time only on a draft. Once an agreement is sent, the four write tools answer `409 invalid_state`: "This agreement was already sent, so its fields cannot be edited one at a time. To change them, call `revise_envelope` with the complete new fields list (`get_fields` returns the current list in that shape). A revision makes everyone sign again and uses one round: the first 199 on an envelope are free, and the one after that starts a new envelope." So call `get_fields`, change the list, and send it as `fields` to `revise_envelope`; everyone then signs again and the revision uses one round (see [Billing and rounds](#billing-and-rounds)). A completed or voided agreement cannot be changed at all.

Every edit is recorded in the audit log (`get_evidence`) as `envelope.fields_changed`, with `action` (`added`, `updated`, `removed`), the field, the person it belongs to, and for updates which properties changed.

## Templates

A template is a PDF, named roles ("Client", "Countersigner"), and fields per role. An organization with an active plan can create and manage them from the API.

`create_template` (`POST /api/v1/templates`, 201):

```json
{
  "name": "Client agreement",
  "title": "Client Agreement",
  "message": "Welcome. This takes a minute.",
  "pdf_base64": "JVBERi0x...",
  "roles": [
    { "key": "client", "name": "Client", "role": "applicant", "order": 1 },
    { "key": "countersigner", "name": "Countersigner", "role": "signer", "order": 2 }
  ]
}
```

- `roles`: 1 to 20, each with a `key` (lowercase letters, digits, underscores; unique), a `name`, a `role` label (`signer` by default) and an `order` (same number signs together). At least one role must sign; `cc` roles only get a copy.
- Fields come from, in order: `fields` (each has `role` plus the usual `type`, `page`, `x`, `y`, `w`, `h`), `placements` (like envelope placements but with `role` instead of `recipient_index`), tags written with role keys in the PDF, the signature lines the document has, then free space on the last page. Role tags look like `{{sign:client}}`, `{{date:client}}`, `{{text:client:Project|key=project}}`, `{{text:countersigner:Notes}}`. Numeric tags (`{{sign:2}}`) mean the role at that position. Tag text is covered in the stored copy.
- A text field with a `key` becomes a prefill key. `get_template` lists them as `prefill_keys`.
- Returns `{ "template": { id, name, title, message, pages, roles, prefill_keys, archived_at, created_at }, "placement": { method, fields, notes } }`.

`update_template` (`PATCH /api/v1/templates/{id}`) takes `template_id` and any of `name`, `title`, `message`, `pdf_base64`, `roles` (the complete new list, matched by `key`), `fields` or `placements`. A new PDF with tags re-places the fields; without tags the current fields stay. If you drop a role, send fields for what replaces it (`invalid_template` says which role is orphaned). Envelopes already sent keep the version they were sent with.

`archive_template` (`DELETE /api/v1/templates/{id}`) retires a template: it leaves `list_templates` (add `?include_archived=true` on REST to see it), `create_envelope_from_template` and bulk calls return `409 template_archived`, and envelopes already made from it are untouched. Repeating it changes nothing. The web app has the same Archive button.

`create_template_from_envelope` (`POST /api/v1/templates/from-envelope`, 201) turns a prepared envelope (draft or sent) into a template: `{ "envelope_id", "name", "roles": [ { "email", "key", "name?" } ] }`. Each recipient becomes a role; without `roles` the roles are named after the people.

The web app has "New template" under Templates for the same thing: upload a PDF, name the roles, and rename them later.

## Bulk: send to a list

Two tools, one result shape. `bulk_send_from_template` sends a template to many people. `bulk_create_envelopes` sends one PDF to a list, with no template. A call takes up to 500 rows (`422 limit_reached` over that).

```json
{
  "template_id": "uuid",
  "idempotency_key": "project-12-welcome",
  "rows": [
    {
      "recipients": { "client": { "name": "Ada Okafor", "email": "ada@example.com" }, "countersigner": { "name": "Hannah Lee", "email": "hannah@acme.example" } },
      "prefill": { "project": "Project 12" },
      "external_id": "enrollment-2291",
      "metadata": { "project": "12" }
    }
  ]
}
```

`bulk_create_envelopes` takes `title`, `message`, `pdf_base64`, `fields` or `placements` (applied to every row; omit both to place from tags or lines), `send` (default true; `false` makes drafts), `expires_in_days`, and either `rows` (`[{ "recipients": [ { "name", "email", "role?", "order?" } ], "external_id?", "metadata?" }]`) or `recipients_csv`. The PDF is read once; every row gets its own envelope.

### From a CSV

`recipients_csv` is CSV text with a header row. Required columns: `name` and `email` (for more people on one row use `name_1,email_1,name_2,email_2` and so on). Optional: `role`, `order` (`role_2`, `order_2` for the second person), `external_id`, and `meta_<key>` for metadata.

```
name,email,external_id,meta_project
Ada Okafor,ada@example.com,enrollment-2291,12
Grace Hopper,grace@example.com,enrollment-2292,12
```

A row that cannot be read (no email, a bad address) comes back as a failed row with the reason; the rest go out. With `rows` (JSON) the shape is checked first: a malformed email address answers `invalid_request` with the path (`rows.0.recipients.client.email`) and nothing is sent, so fix it and send the whole call again. A missing header or a missing `name` or `email` column is `400 invalid_csv` before anything is sent.

### The result

```json
{
  "batch_id": "uuid",
  "total": 3,
  "sent": 2,
  "failed": 1,
  "duplicate": 0,
  "rows": [
    { "row": 1, "status": "sent", "envelope_id": "uuid", "external_id": "enrollment-2291", "delivery": "email" },
    { "row": 2, "status": "sent", "envelope_id": "uuid", "external_id": "enrollment-2292", "delivery": "email" },
    { "row": 3, "status": "failed", "external_id": "enrollment-2293", "error": { "code": "invalid_recipient", "message": "Enter a valid email address." } }
  ]
}
```

- Rows go out one at a time, in order, and are independent: a failed row never stops the rest. The call returns `200` even when some rows failed, so read `rows`.
- `status` is `sent`, `draft` (when `send` is false), `failed`, or `duplicate`: a row whose `external_id` already belongs to a draft, an envelope out for signature, or a completed envelope in this organization is not sent again, and `envelope_id` points at the existing one. Voided, declined and expired envelopes do not count, so the same person can be sent again after one of those.
- Each sent row counts as a new envelope at first send, like any other. Check `get_usage` before a big batch.
- `delivery` is `email` when the signing email went out. Email being unavailable never fails a row: the envelope is created and sent, and the row says `delivery: "link"`. Over REST, that call's own response then carries `signing_links` on those rows (`[{ name, email, url }]`) with a `note`: pass them on yourself, because they are shown once, are never stored, and anyone holding one can sign as that person. Over MCP and in any replay, links are never returned; connect email and use `remind_batch` instead. Signers who were emailed never have a link in a response.
- `batch_id` names everything this call created. Keep it.

### Progress and reminders

`get_batch` (`GET /api/v1/batches/{batch_id}`) returns the live state:

```json
{
  "batch_id": "uuid",
  "total": 2,
  "by_status": { "sent": 1, "completed": 1 },
  "awaiting": 1,
  "completed": 1,
  "rows": [
    { "row": 1, "status": "sent", "envelope_id": "uuid", "external_id": "enrollment-2291", "envelope_status": "completed", "title": "…", "sent_at": "…", "completed_at": "…", "metadata": {}, "signers": [ { "name": "Ada Okafor", "email": "ada@example.com", "status": "signed", "viewed_at": "…", "signed_at": "…" } ] }
  ],
  "note": "…"
}
```

`rows` are the envelopes that were created, oldest first; a row that failed never created one, so only the bulk call's own response lists it (and `row` here counts created envelopes, not your original list positions). Match on `external_id`.

`remind_batch` (`POST /api/v1/batches/{batch_id}/remind`) nudges everyone who is expected to sign now: `{ "batch_id", "envelopes", "reminded", "skipped", "already_done", "rows": [ { "envelope_id", "external_id", "reminded": [emails], "skipped": [ { "email", "reason" } ] } ] }`. Finished envelopes are skipped, a person is reminded at most once an hour (the rest are `skipped` with `reminded in the last hour`), and reminders are free. The web app has the same list at Batches, with a "Remind everyone pending" button.

### Retrying a bulk call

Send `idempotency_key` on the call (REST: the `Idempotency-Key` header or the body field). Then:

- The same key and the same body returns the first response. Nothing is sent twice (`Idempotent-Replay: true` on REST, `idempotent_replay: true` on MCP).
- Every row also has a key. Give a row its own `idempotency_key`, or it uses `<call key>:<row number>` (`project-12-welcome:1`). A row that already went out under its key is returned as `sent` with `idempotent_replay: true` and is never sent again, even if the call itself crashed halfway and you repeat it with the same key. A row key reused with different content is a failed row (`idempotency_key_reuse`).
- A retry after a crash joins the same `batch_id`.
- Without a key, a retry sends everything again, except rows whose `external_id` already belongs to a live envelope, which are skipped as `duplicate`. Send a call key, and give every row an `external_id`.

## Run the organization

An agent can do what an owner does in Settings: manage people and keys and read the audit trail. These tools need an active plan and a key made by an owner or admin; a key made by a member gets `403 forbidden`, and so does a key whose creator has left the team. The Team and Billing pages in the web app work the same way.

| Tool | REST | Does |
| --- | --- | --- |
| `list_members` | `GET /api/v1/org/members` | Members (`id`, `name`, `email`, `role`) and `pending_invitations`. |
| `invite_member` | `POST /api/v1/org/members` `{ "email", "role": "admin" \| "member" }` for one person, or `{ "emails": [ ... ], "role" }` for 1 to 50 | Invites one person or many by email. One `email` answers as always (201). A list answers 200 with a result for every address (below). They join when they sign in to botusign.com with that address. `email_sent` says whether the invitation email went out. |
| `set_member_role` | `PATCH /api/v1/org/members/{id}` `{ "role" }` | Makes someone an admin or a member. The owner's role cannot change. |
| `remove_member` | `DELETE /api/v1/org/members/{id}` | Removes a member, or withdraws a pending invitation. The owner cannot be removed, and a key cannot remove the person it belongs to. |
| `list_api_keys` | `GET /api/v1/org/api-keys` | `id`, `name`, `prefix`, `created_at`, `last_used_at`, `revoked_at`. Never a secret. |
| `create_api_key` | `POST /api/v1/org/api-keys` `{ "name" }` | Returns the key's `secret` once (201). Store it right away; it cannot be shown again. The new key belongs to the same person as the key that made it. |
| `revoke_api_key` | `DELETE /api/v1/org/api-keys/{id}` | Stops a key working at once. Repeating it is safe (`already_revoked: true`). |
| `get_audit_log` | `GET /api/v1/org/audit?envelope_id=&since=&limit=&cursor=` | Every audit event across the organization, oldest first, 100 per page (up to 500). Each event has `envelope_id`, `title`, `seq`, `at`, `type`, `recipient`, `ip`, `user_agent`, `meta`, `prev_hash`, `hash`. Continue with `next_cursor` until it is `null`. |

**`invite_member`, one person or many.** Send `email` for one person, or `emails` for 1 to 50 addresses (`email` may also hold several addresses separated by commas, spaces or new lines). `role` is `admin` or `member` (default `member`) and applies to everyone in the call. Addresses are trimmed, lowercased and de-duplicated. Only owners and admins can invite: an API key acts as the person who created it, and an OAuth sign-in acts as the person who signed in. An organization can have up to 250 people, counting members and pending invitations. A list invites as many as fit, in the order given, and reports the rest as `member_limit`; it never goes over 250. Without a plan nothing is sent (`plan_required`).

One person, REST or MCP (`tools/call` with `name: "invite_member"` and these as `arguments`), answered with 201 on REST:

```json
{ "email": "ada@example.com", "role": "member" }
```

```json
{ "invited": true, "email": "ada@example.com", "role": "member", "email_sent": true, "note": "They join this organization when they sign in to botusign.com with that email." }
```

Many, the same call with `emails`:

```json
{ "emails": ["ada@example.com", "grace@example.com", "not-an-address"], "role": "member" }
```

Partial success is normal and answers 200. Read `skipped`; one bad address does not stop the rest:

```json
{
  "invited": [
    { "email": "ada@example.com", "role": "member", "email_sent": true, "note": "They join this organization when they sign in to botusign.com with that email." },
    { "email": "grace@example.com", "role": "member", "email_sent": true, "note": "They join this organization when they sign in to botusign.com with that email." }
  ],
  "skipped": [
    { "email": "not-an-address", "code": "invalid_email", "message": "That is not a valid email address." }
  ],
  "results": { "requested": 3, "invited": 2, "skipped": 1, "duplicates_ignored": 0 }
}
```

A skipped address has one of these `code`s: `invalid_email`, `already_member`, `already_invited` (a pending invitation exists, so no second email is sent), `member_limit`. If every address is invalid the call fails with 422 and `{ "error": { "code": "invalid_email", "message": "...", "skipped": [ ... ] } }`. More than 50 addresses is refused and nothing is sent. Over MCP the same bodies come back as the tool result.

On `set_member_role` and `remove_member`, the id in the URL is the member `id` from `list_members`, or the person's URL-encoded email. Over MCP send `member_id` or `email`. Treat `create_api_key` like a password: put the secret in a secret store, never in a message or log.

## Safe retries (idempotency)

A call that times out may or may not have worked. Send an idempotency key and retry with the same request: you get the first response back and nothing is created, emailed or counted a second time.

```bash
curl -s -X POST $BOTUSIGN/api/v1/envelopes \
  -H "Authorization: Bearer $BOTUSIGN_KEY" -H "Content-Type: application/json" \
  -H "Idempotency-Key: enrollment-2291" \
  -d @envelope.json
```

- REST: the `Idempotency-Key` header (a body field `idempotency_key` also works, and the header wins if both are sent). MCP: the `idempotency_key` argument. Up to 255 characters; longer is `400 invalid_idempotency_key`. Use something that belongs to the thing you are doing, such as your own record id, not a fresh random value on each retry.
- It works on `create_envelope`, `create_envelope_from_template`, `send_envelope`, `revise_envelope` and `resend_envelope` (REST: `POST /api/v1/envelopes`, `POST /api/v1/envelopes/{id}/send`, `PATCH /api/v1/envelopes/{id}`, `POST /api/v1/envelopes/{id}/resend`), and on `bulk_send_from_template` and `bulk_create_envelopes`, where every row has a key too (see [Bulk](#bulk-send-to-a-list)). Other calls are safe to repeat or have no side effects.
- The same key with the same request returns the stored response, status and body, exactly as the first time. REST adds the header `Idempotent-Replay: true`. MCP adds `"idempotent_replay": true` to the result. A retry never changes the allowance: a create-and-send with one key is one envelope and one count.
- The same key with a different request (any different field, or a different operation) is `422 idempotency_key_reuse`. Send a new key for a new request.
- If the first request is still running when the retry arrives, the retry gets `409 idempotency_in_progress` with `Retry-After: 2`. Wait and send the same request again.
- A request that failed (for example `422 invalid_pdf`, a validation error, or a server error) stores nothing and frees the key, so you can fix the request and use the same key.
- Keys belong to the organization and are kept for 48 hours.

## Billing over the API

These calls take the same API key and work even when the organization has no plan, which is the state of a new organization after [sign-up](#sign-up-as-an-agent). A person is only needed for the two things an agent cannot do alone: pay with a card, and manage one.

| Call | Tool | What it does |
| --- | --- | --- |
| `GET /api/v1/billing` | `get_billing` | The plan, status, allowance used, the plans on offer, and `next_steps`. |
| `POST /api/v1/billing/checkout` `{ "plan": "org" }` | `create_checkout_session` | Returns `checkout_url`. Give it to a person. They pay once and the plan usually turns on within seconds (see step 4 of [Sign up as an agent](#sign-up-as-an-agent) for a late confirmation). If the organization already paid, this call refuses with `409 already_subscribed` instead of starting a second charge. Org is the only plan on offer, so `plan` can be left out. |
| `POST /api/v1/billing/portal` | `create_portal_session` | Returns `portal_url`: update the card, see invoices, cancel. Needs a paid plan. |

`GET /api/v1/usage` (`get_usage`) also works with no plan.

```json
{
  "plan": "none",
  "status": "none",
  "trial_ends_at": null,
  "current_period_end": null,
  "seats": 0,
  "cancel_at_period_end": false,
  "allowance": {
    "period": { "start": "2026-11-01T00:00:00.000Z", "end": "2026-12-01T00:00:00.000Z" },
    "agent_envelopes": { "included": 0, "used": 0, "remaining": 0, "over_allowance": 0, "overage_usd_so_far": 0, "overage_usd_per_envelope": 0.1 },
    "app_envelopes_sent": 0
  },
  "checkout_available": true,
  "plans": [
    { "id": "org", "name": "Org", "price_usd": 1200, "per": "organization", "included_agent_envelopes": 50000 }
  ],
  "next_steps": ["To start, POST {\"plan\":\"org\"} to /api/v1/billing/checkout and give the checkout_url to a person. …"]
}
```

`plan` is the plan in force right now: `none` or `org`. `allowance.agent_envelopes.included` is 0 until a plan exists.

**Checkout.** `create_checkout_session` returns a Stripe Checkout link for the Org plan. Asking for it when the organization already has it is `409 already_subscribed` (use the portal to change what you pay). Any other plan name is `422 plan_not_available`. If checkout is not connected on this deployment the answer is `503 billing_not_configured`. `GET /api/v1/billing` shows `checkout_available`.

**Portal.** `409 no_billing_account` until the organization has paid. `503 billing_not_configured` when Stripe is not connected.

**What a refused call looks like.** With no plan, every other endpoint answers `403 plan_required`. The body always says how to fix it:

```json
{
  "error": { "code": "plan_required", "message": "…", "current_plan": "none", "required_plan": "org" },
  "upgrade": {
    "message": "This organization has no active plan yet. GET /api/v1/billing shows the plans. POST {\"plan\":\"org\"} to /api/v1/billing/checkout and give the checkout_url to a person, who enters a card once.",
    "required_plan": "org",
    "billing_endpoint": "/api/v1/billing",
    "checkout_endpoint": "/api/v1/billing/checkout"
  }
}
```

`required_plan` is always `org`. Over MCP the same JSON is the text of the error result, and a plan-less key sees only the four billing and usage tools in `tools/list`.

## Envelope states

`draft`, `sent`, `viewed`, `completed`, `declined`, `voided`, `expired`.

- `sent` becomes `viewed` the first time any signer opens it.
- `completed` happens when every signer has signed.
- `declined` happens when a signer declines. `voided` is the sender cancelling. `expired` happens when the deadline passes (default 30 days, up to 90).
- `completed` and `voided` are final. `sent`, `viewed`, `expired`, and `declined` can be revised; `sent`, `viewed`, and `expired` can be resent.

## Billing and rounds

BotUsign charges once for the initial send of a contract. Revisions and resends of that same contract are included, up to 199 revisions. A new contract is a new charge.

| | Org |
| --- | --- |
| Price | $1,200 per month for the organization, up to 250 people |
| Sends from the web app | Unlimited |
| New agent envelopes included each month | 50,000 for the organization |
| After the allowance | $0.10 per new envelope |
| Reminders | Free |
| Revise or resend the same envelope | 199 free, then a new envelope |
| Webhooks | Yes |
| Templates and bulk send | Yes (500 rows per bulk call) |
| Members, keys and audit log over the API | Yes |

- A new envelope is counted once, when it is first sent through the API or MCP (`create_envelope` with `send: true`, `send_envelope`, `create_envelope_from_template`, each bulk row). Drafts are never counted.
- `round` is the document version. Round 1 is the first send. Every `revise_envelope` or `resend_envelope` adds one round. A sender gets 199 free revisions after the original send, so one envelope runs through round 200 and `rounds_remaining` counts down from 199 to 0. Revisions and resends share the same 199.
- The 200th revision or resend (document version 201) creates a new envelope. When `rounds_remaining` is 0, the next revise or resend returns `new_envelope: true` with a new `envelope.id`, `supersedes` pointing at the old id, and a `billing` block that counts it as a new send. The old envelope is voided if it was still live, and its links stop working. The old envelope shows `superseded_by`.
- The allowance is one pool for the whole organization. 50,000 a month is more than 1,600 a day, so an organization that sends hundreds of packets a month never reaches it.
- Overage is added to the organization's next Stripe invoice as one $0.10 line per envelope. `get_usage` shows the running total.
- Billing is decided on the server for every request. Nothing the client sends changes the plan or the allowance.

## Webhooks

Webhooks are part of the plan, so an agent can hear about every step without polling. Register an endpoint with `create_webhook` (REST `POST /api/v1/webhooks`, body `{ "url": "https://…" }`) or under Settings, Webhooks. Endpoints must be public HTTPS URLs (private and internal addresses are refused, both when you save the URL and when BotUsign connects). Up to 5 endpoints per organization. `create_webhook` returns `signing_secret` once; store it. `list_webhooks` shows endpoints and the 20 most recent deliveries with status codes and errors, `test_webhook` sends a `webhook.test` event and reports the response status, and `delete_webhook` removes an endpoint.

Every event carries `data.envelope` with `id`, `title`, `status`, and your `external_id` and `metadata` (`null` when you set none), so a receiver can match the event to its own record without another call.

The six events an agent needs:

| Event | Fires when | Notable `data` |
| --- | --- | --- |
| `envelope.sent` | The envelope is first sent | `envelope`, `recipients` |
| `envelope.viewed` | The first time anyone opens it. Later opens do not fire again, until a revision sends the envelope back to `sent` | `envelope` |
| `recipient.viewed` | Each person opens their own link for the first time, one event per person. Later opens by the same person do not fire again, until a revision resets them | `envelope`, `recipient`, `viewedAt` |
| `recipient.signed` | Each signer finishes, one event per signer | `envelope`, `round`, `recipient`, `signed`, `signers`, `awaiting` (emails still to sign; empty on the last signature) |
| `envelope.declined` | A signer declines | `envelope`, `declinedBy` |
| `envelope.completed` | The last signer signs | `envelope`, `completedAt`, `recipients`, `documents` with 24 hour links to the signed PDF and certificate |

Also sent: `envelope.revised` and `envelope.resent` (with `round` and `recipients`), `envelope.voided` (with `reason`), `envelope.expired`, and `webhook.test`. For a two-person envelope an agent receives `envelope.sent`, `recipient.viewed` and `envelope.viewed` (the first person opening it), `recipient.signed` (`signed: 1`, `awaiting: ["second@…"]`), another `recipient.viewed` when the second person opens their link, `recipient.signed` (`signed: 2`, `awaiting: []`), then `envelope.completed`. Events are queued in that order, but each one is its own HTTP request, so a retry or a slow receiver can see them out of order. Use `signed` and `signers`, not arrival order, to know where the envelope stands.

`recipient.signed`:

```json
{
  "id": "event uuid",
  "type": "recipient.signed",
  "createdAt": "2026-11-02T20:03:00.000Z",
  "data": {
    "envelope": { "id": "uuid", "title": "Client agreement: Ada Okafor", "status": "viewed", "external_id": "enrollment-2291", "metadata": { "project": "12" } },
    "round": 1,
    "recipient": { "id": "uuid", "name": "Ada Okafor", "email": "ada@example.com", "role": "applicant", "order": 1, "status": "signed" },
    "signed": 1,
    "signers": 2,
    "awaiting": ["hannah@acme.example"]
  }
}
```

`recipient.viewed` (the first time Ada opens her link; `viewedAt` is the same moment as `viewed_at` on the recipient):

```json
{
  "id": "event uuid",
  "type": "recipient.viewed",
  "createdAt": "2026-11-02T20:02:00.000Z",
  "data": {
    "envelope": { "id": "uuid", "title": "Client agreement: Ada Okafor", "status": "viewed", "external_id": "enrollment-2291", "metadata": { "project": "12" } },
    "recipient": { "id": "uuid", "name": "Ada Okafor", "email": "ada@example.com", "role": "applicant", "order": 1, "status": "viewed" },
    "viewedAt": "2026-11-02T20:02:00.000Z"
  }
}
```

For an envelope with two parallel signers an agent receives `recipient.viewed` once for each, and `envelope.viewed` once, with the first. Both are queued in the same step, but they are separate requests: do not rely on arrival order.

Request headers:

```
POST <your url>
Content-Type: application/json
User-Agent: BotUsign-Webhooks/1
BotUsign-Event: envelope.completed
BotUsign-Delivery: <delivery uuid>
BotUsign-Signature: t=1762113600,v1=<hex>
```

`envelope.completed` body:

```json
{
  "id": "event uuid",
  "type": "envelope.completed",
  "createdAt": "2026-11-02T20:05:00.000Z",
  "data": {
    "envelope": { "id": "uuid", "title": "Client agreement: Ada Okafor", "status": "completed" },
    "completedAt": "2026-11-02T20:05:00.000Z",
    "recipients": [{ "id": "uuid", "name": "Ada Okafor", "email": "ada@example.com", "role": "applicant", "order": 1, "status": "signed" }],
    "documents": {
      "signedPdf": { "url": "https://…", "sha256": "…", "expiresInSeconds": 86400 },
      "certificatePdf": { "url": "https://…", "expiresInSeconds": 86400 }
    }
  }
}
```

`envelope.completed` carries 24-hour download links so an agent can file both PDFs the moment the last person signs.

Verify the signature before trusting a request:

```ts
import { createHmac, timingSafeEqual } from "node:crypto";

export function verify(secret: string, header: string, rawBody: string, toleranceSeconds = 300): boolean {
  const parts = Object.fromEntries(header.split(",").map((p) => p.split("=") as [string, string]));
  if (!parts.t || !parts.v1) return false;
  if (Math.abs(Date.now() / 1000 - Number(parts.t)) > toleranceSeconds) return false;
  const expected = createHmac("sha256", secret).update(`${parts.t}.${rawBody}`).digest();
  const given = Buffer.from(parts.v1, "hex");
  return given.length === expected.length && timingSafeEqual(given, expected);
}
```

Reply with any 2xx within 8 seconds. Anything else is retried after 1 minute, 5 minutes, 30 minutes, 2 hours, and 6 hours (six attempts in total), then marked failed. Delivery history, with status codes and errors, is on the Webhooks settings page. Use `BotUsign-Delivery` or the event `id` to de-duplicate: a retry sends the same payload and ids. Redirects are not followed.

## Errors

Every error is `{ "error": { "code": "…", "message": "…" } }`.

| Status | Code | Meaning |
| --- | --- | --- |
| 400 | `invalid_request` | Body failed validation; `issues` lists each path. Also `invalid_json`, `unsafe_url`, `nothing_to_revise`, `invalid_cursor`, `invalid_idempotency_key`. |
| 400 | `invalid_template`, `unknown_role`, `invalid_csv` | A template needs a name, 1 to 20 roles (at least one that signs), unique role keys, and fields on pages that exist; a field or placement names a role the template does not have; `recipients_csv` has no header row, no `name` or `email` column, or a bad `meta_` column. The message says which. |
| 401 | `unauthorized` | Missing, wrong, or revoked key. |
| 403 | `plan_required` | No active plan. The body has an `upgrade` field: see [Billing over the API](#billing-over-the-api). |
| 403 | `forbidden` | Org tools only: the key was made by a member (not an owner or admin) or by someone who has left, or the action would remove or demote the owner or the key's own person. Make a key as an owner or admin. |
| 404 | `not_found`, `invalid_device_code` | Unknown id, or it belongs to another organization. `invalid_device_code`: the sign-up poll does not know that `device_code`. |
| 409 | `invalid_state`, `nothing_to_remind`, `conflict` | The envelope is not in a state that allows this (for example resend on a completed envelope), or another change landed first. Read `available_actions` and retry. |
| 409 | `template_archived` | The template was archived and cannot start new envelopes. Use another template or create a new one. |
| 409 | `idempotency_in_progress` | A request with the same idempotency key is still running. Wait (`Retry-After`) and send the same request again. |
| 409 | `already_subscribed`, `no_billing_account` | Billing: the organization already has a plan (checkout cannot go to the same or a lower plan), or the portal has no billing account yet. |
| 413 | `payload_too_large` | Body over 16 MB or PDF over 10 MB. |
| 422 | `invalid_pdf` | The file is not an acceptable PDF. |
| 422 | `idempotency_key_reuse` | The idempotency key was already used for a different request. |
| 422 | `anchor_not_found`, `invalid_tag`, `invalid_placement` | Field placement could not be done as asked. `anchor_not_found` lists the closest text in the PDF (`closest_matches`); `invalid_tag` names the tag and page (a tag for signer 3 when there are 2 signers, a bad `key=`); `invalid_placement` says why (rotated page, a `cc` recipient with fields, a page that does not exist). Nothing was created. See [Placing signature fields without coordinates](#placing-signature-fields-without-coordinates). |
| 422 | `limit_reached` | More bulk rows than the plan allows in one call (500). |
| 429 | `rate_limited` | Slow down; see `Retry-After`. |
| 503 | `email_not_configured` | Email delivery for botusign.com is not connected or the sending domain is not verified yet. Do not retry. Sends from the web app still hand the sender the signing links. |
| 503 | `billing_not_configured` | Checkout or the billing portal is not connected on this deployment. A person can choose a plan in the web app. |

A signer who opens a link that a revision or resend replaced sees "This agreement was updated" (HTTP 410 from the signing API). That is expected; they use the newest email.

## Limits

PDF 10 MB, 100 pages. 20 recipients and 200 fields per envelope. Bulk send 500 rows per call; a recipients CSV up to 2 MB. Templates up to 20 roles. Title 160 characters, message 2,000. Signature image 200 KB. Expiry 1 to 90 days. 5 webhook endpoints. 199 free revisions or resends per envelope, then a new envelope. `external_id` 200 characters; `metadata` 20 keys, key 40 characters, value 500. Idempotency key 255 characters, kept 48 hours. `list_envelopes` returns up to 100 per page. Agent sign-up code valid 15 minutes.

## Smoke test

```bash
export BOTUSIGN=https://botusign.com
curl -s $BOTUSIGN/api/health
curl -s -H "Authorization: Bearer $BOTUSIGN_KEY" $BOTUSIGN/api/v1/usage
curl -s -H "Authorization: Bearer $BOTUSIGN_KEY" $BOTUSIGN/api/v1/billing
curl -s -H "Authorization: Bearer $BOTUSIGN_KEY" "$BOTUSIGN/api/v1/envelopes?awaiting_signature=true"
```

The agent skill that wraps these calls lives at https://botusign.com/skill.md.
