---
title: "Connect an ad account with an API key"
description: "PubNio API ads.connectApiKeyAccount: connect an ad account with an API key. Request fields, examples in five clients, errors, and idempotency."
---

> Documentation Index
> Fetch the complete documentation index at: https://pubnio.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect an ad account with an API key

Connect an ad account with an API key with [`POST /api/v1/ads/accounts/connect/api-key`](https://pubnio.com/api/v1/docs#tag/ads/POST/api/v1/ads/accounts/connect/api-key). Requires a signed-in workspace owner, in the web app or the CLI; API keys are not accepted and MCP cannot call it.

## Request

Verifies the provider API key, seals it, and creates the ad account in one call. Select the returned account explicitly before syncing or spending.

| Body field    | Type           | Required |
| ------------- | -------------- | -------- |
| `workspaceId` | UUID           | Yes      |
| `provider`    | `"openai_ads"` | Yes      |
| `apiKey`      | string         | Yes      |
| `accountId`   | UUID           | No       |
| `profileId`   | UUID           | No       |

## Response

- HTTP 200: `AdApiKeyConnectResult` with `provider`, `accountId`, `status`.

The [OpenAPI document](https://pubnio.com/api/v1/openapi) has each field's type.

## Examples

### TypeScript

```ts
const connected = await workspace.ads.connectApiKey({
  provider: "openai_ads",
  apiKey: process.env.OPENAI_ADS_KEY ?? "",
});
```

Create this client with a signed-in person's `accessToken`, not an `apiKey`.

### Python

The Python SDK authenticates with a workspace API key, which this operation does not accept, so it has no method for it.

### cURL

```sh
curl -X POST "https://pubnio.com/api/v1/ads/accounts/connect/api-key" \
  -H "Authorization: Bearer $PUBNIO_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"workspaceId":"'"$WORKSPACE_ID"'","provider":"openai_ads","apiKey":"YOUR_OPENAI_ADS_KEY"}'
```

### CLI

```sh
pnio ads connect-api-key-account --workspace-id "$WORKSPACE_ID" --provider openai_ads --api-key "$OPENAI_ADS_KEY"
```

### MCP execute

```js
async () => {
  const response = await codemode.request({
    method: "POST",
    path: "/api/v1/ads/accounts/connect/api-key",
    body: {
      workspaceId: codemode.workspaceId,
      provider: "openai_ads",
      apiKey: "YOUR_OPENAI_ADS_KEY",
    },
  });
  return response.data;
};
```

## Errors

It declares no problem of its own.

It declares the problems [every Ads operation](https://pubnio.com/docs/reference/#ads) and [most operations](https://pubnio.com/docs/reference/#shared-problems) declare.

## Idempotency

No key, so a retried `POST` is not deduplicated. Read the current state before you retry.

## Limits

- API keys and MCP cannot call it. A signed-in person runs it from the CLI after `pnio auth login` or in the web app.

## Related

- [Ads operations](https://pubnio.com/docs/reference/#ads)

Source: https://pubnio.com/docs/reference/ads-connect-api-key-account/index.mdx
