# AGENTS.md: integrating Outlevo

Instructions for coding agents adding Outlevo to an app. The API reference is https://api.outlevo.com/v1/openapi.json; the working examples are in https://developers.outlevo.com/llms.txt (short) and https://developers.outlevo.com/llms-full.txt (everything).

## First: decide which integration this is

Outlevo is used in two ways, and they differ in where the key lives and who ever sees Outlevo. Decide which one this is before writing anything.

1. **Outlevo works for your own company (the usual case).** Your product finds, researches and emails its *own* prospects through one Outlevo workspace: yours. One live key for the whole installation, in a server env var or your platform's admin settings; never a key per user, per customer or per account. Your users and customers never see Outlevo: no "Connect Outlevo", no Outlevo key field, no Outlevo name in your customer-facing screens, help, emails or privacy page. The usual shape: your app pushes the companies it found (`external_id` = your id, `attributes` = what you know about them), Outlevo qualifies them, finds the person, writes and sends, and webhooks bring replies and meetings back to your admin screens.
2. **Your users bring their own Outlevo workspace.** Each of your customers has an Outlevo account and pastes their own key into your app, which then works on their workspace. Build this only when the product's owner asks for exactly that.

When the request is ambiguous, it is case 1: "use Outlevo to find our customers", "add Outlevo outbound to our admin" are case 1. Every key acts on one workspace, and in case 1 that workspace is yours; a feature documented "with the workspace's key" (ads, audiences) does not make it case 2.

Outlevo gives your product no access to your customers' ad accounts, CRMs or mailboxes. If your product itself needs your customers' Google Ads, Meta or another platform (to exclude bot IPs from their campaigns, to send their conversions), integrate that platform directly with your own OAuth app. Outlevo's platform access covers Outlevo workspaces only.

In case 1, when the product's owner wants to work from their own admin panel (chat, what needs a person, campaigns, replies), follow https://developers.outlevo.com/quickstarts/admin-console.md. It says which screens to build and what stays in app.outlevo.com.

## Always

- Call Outlevo from the server only. Keys live in server env vars (`OUTLEVO_KEY`, `OUTLEVO_WEBHOOK_SECRET`), never in frontend bundles, `VITE_`/`NEXT_PUBLIC_` variables, or git. A live key used from a browser is refused.
- Send `Idempotency-Key` (a fresh UUID per operation, reused on retry) on every POST, PUT and PATCH.
- Retry only 429 (honour `Retry-After`), 502, 503 and connection errors, with backoff. Do not retry other 4xx: read `error.fix`.
- Quote before spending: metered calls answer `{ credit_estimate }` without `?confirm=true`. Show the estimate to a person or keep it within a budget you were given before confirming.
- Treat 202 `{ job_id }` as "started": poll `GET /v1/jobs/{id}` from a background job, or wait for the webhook. Never block a web request on it.
- Verify every webhook: HMAC-SHA256 over `"<t>.<raw body>"`, accept if any `v1` matches, reject when |now − t| > 300 s, dedupe on `Outlevo-Event-Id`, answer 2xx fast and do the work in a queue.
- Page through lists with `next_cursor`; never assume one call returns everything.
- Store your own id on each company as `external_id`, and your data as `attributes`. On 409 `COMPANY_EXISTS`, use `error.details.company_id` instead of creating again.
- For features your users drive (adding accounts, launching, reading replies), prefer the chat-first endpoint `POST /v1/assistant/messages`: one call in plain language, and the assistant does the work with the key's scopes. Render its `cards`; run a `confirm` card's `calls` only after the user presses Confirm; open `form` and `launch` cards in app.outlevo.com; show `choices` as buttons plus a free-text box. With React, `<OutlevoAssistant />` does all of this.
- In TypeScript/JavaScript, use `@outlevo/sdk` (`npm install https://developers.outlevo.com/outlevo-sdk-0.4.0.tgz`; it adds idempotency keys, retries, paging and webhook verification); in other languages call the REST API.
- Develop against a test key (sandbox: fake data, no credits). Switch to a live key only on the server, with the scopes the code uses.

## Never

- Never run a `confirm` card's calls without the user's click, and never ask the user for a Smartlead key or a CSV in a chat: those `form` cards open in app.outlevo.com.
- Never try to approve, start or send through the API, and never ask for a key that could: those steps are done by people in the portal, and no key can do them. To launch, call `POST /v1/campaigns/{id}/launch-request` (MCP `request_launch`) and give the person its `approval_url`: a signed-in owner or admin approves there. Never say a campaign is sending until `get_campaign` (or `GET /v1/campaigns/{id}`) says it is active.
- Never invent merge tags. Messages may use `{{first_name}}`, `{{last_name}}`, `{{email}}`, `{{company_name}}`, `{{website}}`, `{{job_title}}` and the company attributes listed in the approved outbound policy's `merge_fields`. Never write a merge field's value yourself: write the `{{tag}}` and Outlevo fills it per lead.
- To make Outlevo's emails use your data properly, declare each field as an object with a `description`, `kind` (`text` or `url`) and `use` (`optional`, `first_email`, `every_email`) rather than a bare key; `language: "en-GB"` for UK and Irish audiences. If drafting answers `DRAFT_MERGE_FIELD_MISSING`, draft again or make the field's description plainer; do not paste the value into the emails. MCP: `get_outbound_policy` reads them, `draft_outbound_policy` proposes a version a person approves.
- Never send mail to Outlevo leads from the app's own pipeline at the same time as an Outlevo campaign.
- Never log the key, the webhook secret, contacts' email addresses or reply text in plain logs.

## Ads

- `/v1/ads/*`, `/v1/ad-campaigns/*` and the ad tools act on the key's own workspace: its ad accounts and the ad campaigns Outlevo runs for it. Never use them to reach your customers' ad accounts, and never ask your customers for an Outlevo key to do so: integrate Google Ads, Meta and the rest directly with your own OAuth app.
- For the workspace's own ads, the key has the Ads preset and "Acts as me", made by its owner. Outlevo holds the platform access for these accounts, so no OAuth client or developer token of yours is involved. Guide: https://developers.outlevo.com/ads.html
- Connecting an ad account is done by a person signed in at app.outlevo.com (Audiences, Ad campaigns); no API or key can start it, so link there. Then read the connection and pick the account. Work with connections by id from `GET /v1/ads/connections`, and only do what its `capabilities` list.
- IP exclusions: always pass your own `owner`; never remove entries you did not add.
- `ads:manage` spends the workspace's ad budget (approving ads, launching, caps). Use it only for what the person asked in your app.

## Approval gates (people, in the portal)

Nothing goes out until all of these hold:

1. An ICP version is approved.
2. An admin connected Smartlead.
3. Mailboxes are warmed up with daily caps, and SPF, DKIM and DMARC pass.
4. A sales approver approved an `outbound_policy` with templates, a footer (postal address and opt-out line), caps, the `merge_fields` the messages use (keys, or objects with description, kind and use) and optionally `language`. Code may draft it (`POST /v1/policies`, scope `org:write`, a key with "Acts as me" from an owner, admin or approver); only a person approves it.
5. The campaign's messages passed Outlevo's automatic check, or Outlevo's AI reviewer cleared or corrected the ones it flagged (within minutes; what it can't clear safely comes back to the person with what to change).
6. For an organization's first campaign, a person approved the exact messages.
7. An owner, admin or sales approver started the campaign (or an owner or admin approved its launch request at the link `request_launch` returned).
8. Outlevo enabled outbound sending (and contact discovery, if used) for the country after legal review.

If the code needs one of these, stop and tell the person what to do in the portal (app.outlevo.com).

## Roles a key acts with

- A key without "Acts as me" acts as a developer: reads, companies, contacts, signals, evidence, revenue-action proposals and webhooks.
- Campaign writes and handoff decisions need a key with "Acts as me" made by a member with the right role (rep or above for campaigns). Only owners and admins create keys; live keys need a recent second factor, scopes and spend caps.
