> For the complete documentation index, see [llms.txt](https://docs.slingdata.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.slingdata.io/connections/api-connections/openai-ads.md).

# OpenAI Ads

Connect & Ingest data from OpenAI Ads

OpenAI Ads is an advertising platform from OpenAI. The Sling OpenAI Ads connector extracts data from the OpenAI Ads Advertiser API. It supports the ad account, campaigns, ad groups, ads, and daily performance insights at the account, campaign, ad group, and ad level.

{% hint style="success" %}
**CLI Pro Required**: APIs require a [CLI Pro token](/sling-cli/cli-pro.md) or [Platform Plan](/sling-platform/platform.md).
{% endhint %}

## Setup

The following credentials and inputs are accepted:

**Secrets:**

* `api_key` **(required)** -> Your OpenAI Ads API key

**Inputs:**

* `anchor_date` (optional) -> The start date of the first insights sync (default: 1 year ago). Format: `YYYY-MM-DD`

### Getting Your API Key

1. Log in to OpenAI Ads Manager.
2. Go to **Settings** > **API keys**.
3. Create an API key and copy it.

See the [API overview](https://developers.openai.com/ads/api-overview) for more details.

### Using `sling conns`

Here are examples of setting a connection named `OPENAI_ADS`. We must provide the `type=api` property:

{% code overflow="wrap" %}

```bash
sling conns set OPENAI_ADS type=api spec=openai-ads secrets='{ api_key: "${OPENAI_ADS_API_KEY}" }'
```

{% endcode %}

### Environment Variable

See [here](https://docs.slingdata.io/connections/api-connections/pages/eAdVs2BHCgdr6RS8GoJC#dot-env-file-.env.sling) to learn more about the `.env.sling` file.

{% code overflow="wrap" %}

```bash
export OPENAI_ADS='{ type: api, spec: openai-ads, secrets: { api_key: "your_api_key" } }'
```

{% endcode %}

### Sling Env File YAML

See [here](https://docs.slingdata.io/connections/api-connections/pages/eAdVs2BHCgdr6RS8GoJC#sling-env-file-env.yaml) to learn more about the sling `env.yaml` file.

```yaml
connections:
  OPENAI_ADS:
    type: api
    spec: openai-ads
    secrets:
      api_key: ${OPENAI_ADS_API_KEY}
```

**With anchor date for historical insights:**

```yaml
connections:
  OPENAI_ADS:
    type: api
    spec: openai-ads
    secrets:
      api_key: ${OPENAI_ADS_API_KEY}
    inputs:
      anchor_date: "2025-01-01"
```

## Replication

Here is an example replication configuration to sync OpenAI Ads data to a PostgreSQL database:

```yaml
source: OPENAI_ADS
target: MY_POSTGRES

defaults:
  mode: incremental
  object: openai_ads.{stream_name}

streams:
  # sync all endpoints
  '*':
```

**Sync only campaign data and daily insights:**

```yaml
source: OPENAI_ADS
target: MY_POSTGRES

defaults:
  object: openai_ads.{stream_name}

streams:
  campaigns:
  ad_groups:
  ads:
  campaign_insights_daily:
  ad_insights_daily:
```

## Endpoints

### Entities

| Endpoint     | Description                                | Incremental |
| ------------ | ------------------------------------------ | ----------- |
| `ad_account` | The ad account that belongs to the API key | No          |
| `campaigns`  | All campaigns in the ad account            | No          |
| `ad_groups`  | Ad groups for each campaign                | No (child)  |
| `ads`        | Ads for each ad group                      | No (child)  |

### Daily Insights

| Endpoint                  | Description                               | Incremental |
| ------------------------- | ----------------------------------------- | ----------- |
| `account_insights_daily`  | Daily performance at the ad account level | Yes         |
| `campaign_insights_daily` | Daily performance for each campaign       | Yes (child) |
| `ad_group_insights_daily` | Daily performance for each ad group       | Yes (child) |
| `ad_insights_daily`       | Daily performance for each ad             | Yes (child) |

Each insights row has the metrics `impressions`, `clicks`, `spend`, `ctr`, `cpc`, and `cpm`. The row also has the time range (`start_time`, `end_time`) and the `timezone` of the ad account.

## Incremental Sync

The insights endpoints sync by date:

* **First run:** Sling fetches the days from `anchor_date` (default: 1 year ago) up to yesterday.
* **Next runs:** Sling reads the highest `start_time` from the target table. It fetches the days from that date up to yesterday. Sling merges the rows on the entity id and `start_time`, so the overlap does not make duplicates.

The entity endpoints (`ad_account`, `campaigns`, `ad_groups`, `ads`) always run as full refresh. The child endpoints use the ids that the parent endpoints return. Run the parent and child endpoints in the same replication.

## Rate Limiting

The connector sends up to 8 requests per second with 3 concurrent requests. It retries with exponential backoff on 429 (rate limit) responses. It retries with linear backoff on 5xx responses.

If you are facing issues connecting, please reach out to us at <support@slingdata.io>, on [discord](https://discord.gg/q5xtaSNDvp) or open a Github Issue [here](https://github.com/slingdata-io/sling-cli/issues).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.slingdata.io/connections/api-connections/openai-ads.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
