Skip to main content

Unofficial Python SDK for the OpenAI Ads Advertiser API.

Project description

Unofficial OpenAI Ads SDK

Unofficial, not affiliated with OpenAI. Created and maintained by Ilya Baklanov.

TypeScript and Python SDKs for advertisers using the OpenAI Ads Advertiser API. Handwritten clients, typed models, pagination, retries, uploads, insights, and CPM/CPC lifecycle coverage.

Official API docs: developers.openai.com/ads/api-overview

npm install unofficial-openai-ads-sdk
pip install unofficial-openai-ads-sdk
import { OpenAIAds } from "unofficial-openai-ads-sdk";
const ads = new OpenAIAds({ apiKey: process.env.OPENAI_ADS_API_KEY });
const campaign = await ads.campaigns.create({
  name: "Spring launch",
  status: "paused",
  budget: { lifetime_spend_limit_micros: 100_000_000 },
  targeting: { locations: { countries: ["US"] } },
  bidding_type: "clicks",
});
console.log(campaign.id);

Terminal quickstart for the Unofficial OpenAI Ads SDK

What it does What it does not do
Campaigns, ad groups, ads, uploads, ad account, and insights. It is not an official OpenAI package or endorsed integration.
Typed TypeScript and Python clients with strict request validation. It does not run in browsers with advertiser API keys.
Pagination, timeouts, typed errors, request IDs, and retry handling. It does not manage pixels, Conversions API, billing, or creative policy review.
CPM and CPC creation paths. It does not guarantee recently changed API behavior will stay stable.

Python Quickstart

import os
from openai_ads import OpenAIAds

client = OpenAIAds(api_key=os.environ["OPENAI_ADS_API_KEY"])

campaign = client.campaigns.create(
    name="Spring launch",
    status="paused",
    budget={"lifetime_spend_limit_micros": 100_000_000},
    targeting={"locations": {"countries": ["US"]}},
    bidding_type="clicks",
)

print(campaign.id)

Package Names

  • TypeScript: unofficial-openai-ads-sdk
  • Python: unofficial-openai-ads-sdk, imported as openai_ads

Supported API Surface

  • Campaigns
  • Ad groups
  • Ads
  • Uploads
  • Ad account
  • Insights

The SDK models the current public OpenAI Ads API and supports CPC creation with billing_event_type = "click" for CPC ad groups and bidding_type = "clicks" for net-new CPC campaigns.

Reliability

  • Retries 408, 409, 429, and 5xx with exponential backoff and jitter.
  • Honors Retry-After.
  • Does not retry mutating requests by default unless an idempotency key or explicit retry option is provided.
  • Parses unknown response fields without failing, while keeping request validation strict.

Development

npm install
npm run build
npm run test

uv sync --all-extras --dev
uv run pytest
uv run ruff check .
uv run pyright

Live API integration tests are opt-in:

OPENAI_ADS_API_KEY=... npm run test -w packages/typescript -- test/live-api.test.ts
OPENAI_ADS_API_KEY=... uv run pytest python/tests/test_live_api.py

Mutating live tests must also set OPENAI_ADS_LIVE_MUTATE=1.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

unofficial_openai_ads_sdk-0.1.1.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

unofficial_openai_ads_sdk-0.1.1-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file unofficial_openai_ads_sdk-0.1.1.tar.gz.

File metadata

  • Download URL: unofficial_openai_ads_sdk-0.1.1.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for unofficial_openai_ads_sdk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ae0949884ea945078f1ce67e2f90f91fce1ca5dbef393339af64f51de8f2f59d
MD5 3b5d3a1b17e4235d0a72777df1560b80
BLAKE2b-256 fa91609ef2ddfecf28efea19b2560d31234f738dbe22c37e5cf2983f109e4194

See more details on using hashes here.

File details

Details for the file unofficial_openai_ads_sdk-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: unofficial_openai_ads_sdk-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for unofficial_openai_ads_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f4000cfaeaf0fda89104937904fc2af58f7f90a15f404c239b61349b422bf464
MD5 7223e89ba7696d57e3c323e26465696c
BLAKE2b-256 d67bb15e8914d59827080aebca1e51228034eecca367696b8668c747ad520e70

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page