# Campaign Studio

Campaign Studio builds a campaign from one brief: a native landing page and next-steps page, three matching Meta ad templates, and three editable graphics. Find it in the workspace under **Funnels → Campaigns**, or explore the isolated browser demo at `/demo/campaigns`.

## Creating and reviewing

Enter the business, audience, offer, headline, customer context, offer details, next steps and button text. Choose an industry and a page design. Evidence is optional and should only contain real approved facts. Build my campaign saves all assets together, then opens the review screen.

The optional **Prepare with AI** action uses the workspace's configured OpenRouter text model and existing workspace rate limits. It prepares a brief and matching copy for review; it does not save automatically. Missing facts should produce a request for more information, not invented testimonials, prices or guarantees. The deterministic form path requires no AI key or provider call.

Saved campaigns keep their original brief and read the current linked funnel, ads and graphics. Edit funnel pages opens the existing editor, with its separate draft and publishing actions. Edit copy & artwork updates the ad template, its version history and matching graphic together; stale revisions preserve the unsaved edits and report the conflict. The assets also appear in their existing workspace libraries.

Download PNG renders the actual artwork locally at its configured size. Export campaign saves the current bundle as JSON. Ad variations get distinct `utm_content` values and share a campaign ID; links are shown after the funnel is published. Opt-in measurement and sales routing remain controlled in the existing funnel tools. Creating a campaign does not enable either setting.

The initial artwork uses three native layouts. The **AI images & ad setup** tab adds original image generation, reference images, result review, image application and paused Meta ad preparation. See [MCP and image-to-ad workflow](MCP.md). Long copy stays complete in the ad; graphic headlines, brand names and body excerpts are shortened to fit the graphic schema and can be edited before use. Ad templates need the existing account, budget, destination, media and approval workflow before provider launch.

## Connect an external agent

Create a key in **Settings → Developer API** with only `campaigns:read` and `campaigns:write`. Store it in the agent's server-side environment. Use the built-in MCP server over stdio or Streamable HTTP. Plain HTTP clients can use the same REST API. See [MCP connection instructions](MCP.md) for scoped image-generation and ad-preparation tools.

Base URL: `https://YOUR-DEPLOYMENT.convex.site/api/v1`.

- `GET /campaigns/schema`: exact JSON input schema, a fictional bakery example, and current page design IDs. Requires `campaigns:read`.
- `POST /campaigns`: `{brief, ads?}`. Uses the existing guided creator brief. Optional `ads` is exactly three objects with `headline`, `body`, `creativeBody` and `cta`. Without it, matching copy is composed from the supplied answers. Requires `campaigns:write` and `Idempotency-Key`.
- `GET /campaigns`: paginated summaries, using the existing `limit` and `cursor` contract.
- `GET /campaigns/{id}`: current native funnel, ad definitions, graphic definitions and review path, limited to the key's workspace.

```bash
curl "$HYPERCHAT_API_URL/campaigns/schema" \
  -H "Authorization: Bearer $HYPERCHAT_API_KEY"

# campaign.json must conform to the returned schema and contain real business facts.
curl "$HYPERCHAT_API_URL/campaigns" \
  -H "Authorization: Bearer $HYPERCHAT_API_KEY" \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: spring-campaign-001' \
  --data-binary @campaign.json
```

The response contains `id`, `funnelId`, `adTemplateIds`, `graphicIds`, `state: "draft"`, and a review path. Preserve the exact request body and idempotency key on a transport retry. Campaign creation remains deduplicated for that key even after the generic API receipt's 24-hour retention window. Reusing the key with a different brief fails. A different API key has a different request namespace.

Existing API limits apply: 64 KB HTTP body, 60 requests per key per minute, key expiration and revocation, workspace isolation and no browser CORS. Campaign inputs have a tighter 24,000-character storage limit. Publishing requires a separately granted `funnels:publish` scope and exact-revision confirmation. Image generation uses durable jobs in the existing worker. Ad preparation saves local paused drafts; it cannot activate provider ads, send messages or accept leads.

## Development validation

Verified locally: production build and TypeScript pass, all 72 unit tests and 322 backend tests pass, and the compiled browser acceptance passes with no page errors or POST requests. Captures and the acceptance report remain in the task worktree under `artifacts/campaign-studio/`.

- Unit tests: native documents, copy/graphic schemas, complete long-form copy, malformed inputs, contract and attributed links.
- Convex fixtures: atomic writes, concurrent retries, permanent deduplication, role/scope/tenant isolation, revocation, version conflicts, no outbound jobs, and mocked model responses.
- Browser acceptance: fictional demo creation, reload persistence, native page preview, ad edits, real PNG/JSON downloads, storage failure recovery, agent guide and 1440/390/320px fit.

Local fixtures do not certify a live customer model account or a live agent connection. This change adds a Convex table and functions; deploy the backend before exposing the connected interface. No deployment, paid AI call, customer campaign, lead submission, asset upload or release publication is performed by development checks.

## Reuse and results

[Brand kits, creative editing, duplication and attributed results](CAMPAIGN_REUSE.md) extend the creation workflow. Saved brands can supply identity and guidance at creation; existing campaigns keep their applied brand snapshot until a user explicitly reapplies a kit.
