# Create an OpenAI Ads campaign from an agent

Creating an OpenAI Ads campaign takes two calls: `ads.validateCampaignPlan`, a dry run, then `ads.createCampaignPlan`, which leaves `status: paused` on the campaign, ad group, and ad. A signed-in workspace owner activates it in the web app; MCP refuses.

## What PubNio supports in an OpenAI plan

Beyond a name, an objective, and a budget, an OpenAI plan needs:

- A campaign budget of at least 1,000,000 micros, in the account's currency; below it the dry run answers `budget_below_minimum`.
- A campaign name of 3 to 1,000 characters; otherwise the dry run answers `name_length`.
- A `creative.headline` of 3 to 50 characters and a `creative.body` of up to 100; otherwise the dry run answers `headline_length` or `body_length`.
- `creative.destinationUrl` on every ad; without it the dry run answers `destination_required`.
- `creative.providerSettings.fileId` (one image) or at least four `fileIds`; the ad create is refused without either.

| Plan objective | OpenAI receives |
| --- | --- |
| awareness, reach, video_views | `reach` |
| traffic, engagement | `clicks` |
| conversions, leads, sales, app_promotion | `conversions` |

## Spend controls

- `ads.validateCampaignPlan` compiles the plan and checks account readiness, capabilities, budget, currency, and the spend policy without calling the provider.
- Activating a campaign takes `confirmation: "activate_spend"` from a signed-in workspace owner in the web app; an API key or an MCP session gets 403 `human_actor_required`.

## 1. Validate the plan (dry run)

```http
POST /api/v1/ads/campaigns/validate?workspaceId=3d9a1f20-7c4b-4e8a-9f61-2b5c8d7e0a14
Authorization: Bearer <token>
Content-Type: application/json

{
  "name": "Meeting notes app trial",
  "objective": "traffic",
  "budget": {
    "amountMinor": 2000,
    "currency": "USD",
    "kind": "daily"
  },
  "targets": [
    {
      "accountId": "7f3c2a10-5b4e-4d6f-8a9b-0c1d2e3f4a5b"
    }
  ],
  "adGroups": [
    {
      "name": "People asking about meeting notes",
      "ads": [
        {
          "name": "Notes that write themselves",
          "creative": {
            "headline": "Notes that write themselves",
            "body": "Record a call, get a summary and action items in your inbox.",
            "destinationUrl": "https://notes.example.com/trial",
            "providerSettings": {
              "fileId": "file_7Qx2mN8pL4"
            }
          }
        }
      ]
    }
  ]
}
```

A ready account gets 200 with `valid: true` and no issues. OpenAI's adapter checks every draft locally first.

## 2. Create it paused

Send the same plan with `Idempotency-Key: plan-openai-ads-1`: PubNio answers 202 `queued`, and `ads.getOperation` reports when every level exists paused. The same key with the same plan returns the same `planId`; with another plan it gets 400 `idempotency_conflict`.

## Limits

- Validation does not check the image: a plan without a `fileId` or four `fileIds` passes it, then fails at create.
- A plan with the objective `unknown` fails validation with `objective_unsupported`.

## Related

- [OpenAI Ads through PubNio](https://pubnio.com/ads/openai-ads)
- [All ad providers](https://pubnio.com/ads)
- API reference: [ads.createCampaignPlan](https://pubnio.com/docs/reference/ads-create-campaign-plan/)

