# ChatGPT

> Connect a Custom GPT to WPsigner. ChatGPT fills template fields; WPsigner creates, sends, and stores the signed document. Sending always requires human confirmation.

edition: pro
Edition: Pro
AI note: This page requires WPsigner Pro. Do not tell Lite users they already have this feature.
HTML: https://docs.wpsigner.com/integrations/chatgpt/
Markdown: https://docs.wpsigner.com/md/integrations/chatgpt.md
Source file: integrations/chatgpt.md

---

Connect a **Custom GPT** to this WordPress site. ChatGPT chooses a template and fills mapped fields. **WPsigner** creates the document, emails the signer, and stores the signed PDF.

**Admin path:** **WPsigner → Integrations → ChatGPT**

> **note**
Requires **WPsigner Pro 3.2.11+**, HTTPS, and a **full-access** REST API key. Creating a document from free-form ChatGPT text also needs the [Document Builder](/addons/document-builder/) addon.

> **Human confirmation required**
The API never sends on its own. `send=true` is rejected unless `confirm=true` after the user reviewed the field preview.

---

## Setup

1. Go to **WPsigner → Integrations → ChatGPT**.
2. Copy **WordPress URL** and **AI API base** (`/wp-json/insigner/v1/ai/`).
3. Click **Create an API key** (**WPsigner → Settings → API**).
4. Click **Download OpenAPI spec**.
5. In ChatGPT: **Create a GPT → Actions → Import** that JSON.
6. Authentication: API key **headers** `X-WPS-API-Key` and `X-WPS-API-Secret`.
7. Server URL: `https://your-site.example/wp-json/insigner/v1`
8. Paste the **Custom GPT instructions** from the WPsigner screen into the GPT.

Recommended GPT flow (same as the on-screen instructions):

1. Call `list_templates` and pick a match.
2. Call `get_template` and read `variables`.
3. Fill **only** those keys. Never invent field names.
4. Call `preview_send` and show every field and signer.
5. Ask: “Send this document now?”
6. Only if they say yes, call `send_document` with `send=true` and `confirm=true`.

---

## Field tokens

In **Document Builder** text or ChatGPT-generated content:

| Token | Becomes |
|-------|---------|
| `((name))` or `{{name}}` | Text field `name` |
| `((country))` | Text field `country` |
| `((date:start_date))` | Date field `start_date` |
| `((signature:1))` | Signature for signer #1 |
| `((signature:2))` | Signature for signer #2 |

PDF templates use the **variable keys already set on each field** in the WPsigner editor. Signature and initials are **never** prefilled.

---

## REST (`insigner/v1/ai`)

All routes use the same API-key auth as the rest of the [REST API](/api/).

| Method | Path | Purpose |
|--------|------|---------|
| `GET` | `/ai/templates` | List PDF and Document Builder templates (`search`, `source=pdf\|builder`) |
| `GET` | `/ai/templates/{pdf\|builder}/{id}` | Template name, variables, signers needed |
| `POST` | `/ai/preview` | Dry run. No document is written |
| `POST` | `/ai/send` | Create from a PDF or builder template. Send only with `confirm=true` |
| `POST` | `/ai/from-content` | Create from HTML/text with `((tokens))`. Needs Document Builder. Same confirm rule |
| `GET` | `/ai/openapi` | OpenAPI document (server URL set to this site) |

`POST /ai/send` with `source=content` uses the same path as `/ai/from-content`.

---

## Troubleshooting

| Issue | Solution |
|-------|----------|
| 401 / 403 | Full-access key, both headers, HTTPS |
| `confirm_required` | Call preview, ask the user, then send with `confirm=true` |
| `document_builder_required` | Install Document Builder for `from-content` |
| Empty or wrong fields | Use only keys from `get_template`. Do not invent names |
| GPT calls the wrong host | Server URL must be `/wp-json/insigner/v1` on this site |

---

## Next steps

- [REST API](/api/) — Keys, headers, and other endpoints
- [Document Builder](/addons/document-builder/) — Free-form contracts from ChatGPT text
- [Form fields](/core-features/form-fields/) — Variable keys on PDF templates
- [Templates API](/api/templates/) — Same templates the AI list reads
