@coloop-ai/openai-ads-sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Genie Technology Limited
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,177 @@
1
+ # @coloop-ai/openai-ads-sdk
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@coloop-ai/openai-ads-sdk.svg)](https://www.npmjs.com/package/@coloop-ai/openai-ads-sdk)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@coloop-ai/openai-ads-sdk.svg)](https://www.npmjs.com/package/@coloop-ai/openai-ads-sdk)
5
+ [![License: MIT](https://img.shields.io/npm/l/@coloop-ai/openai-ads-sdk.svg)](https://github.com/Genei-Ltd/openai-ads-sdk/blob/main/LICENSE)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-6.0-blue?logo=typescript)](https://www.typescriptlang.org/)
7
+
8
+ Type-safe TypeScript SDK for the OpenAI Ads API.
9
+
10
+ This package is maintained by CoLoop. It is not an official OpenAI SDK. It
11
+ requires Node.js 18 or newer.
12
+
13
+ ## Install
14
+
15
+ ```zsh
16
+ pnpm add @coloop-ai/openai-ads-sdk
17
+ ```
18
+
19
+ ## Quick start
20
+
21
+ ```ts
22
+ import { OpenAIAds } from '@coloop-ai/openai-ads-sdk'
23
+
24
+ const ads = new OpenAIAds({
25
+ apiKey: process.env.OPENAI_ADS_API_KEY!,
26
+ adAccountId: 'ad-account-id',
27
+ })
28
+
29
+ const campaigns = await ads.campaigns.list({ limit: 100 })
30
+ const campaign = await ads.campaigns.get('campaign-id')
31
+ ```
32
+
33
+ Methods accept typed query objects and request bodies. They return the parsed
34
+ response body. Query, request, and response fields use the names defined by the
35
+ API, including snake_case names.
36
+
37
+ ## Authentication
38
+
39
+ Create a client with exactly one credential:
40
+
41
+ - `apiKey` for an OpenAI Ads API key
42
+ - `accessToken` for an Ads OAuth access token
43
+
44
+ A credential can be a string or a function. The SDK resolves a credential
45
+ function before every request, which allows the application to refresh OAuth
46
+ tokens outside the SDK.
47
+
48
+ ```ts
49
+ const ads = new OpenAIAds({
50
+ accessToken: async () => getAdsAccessToken(),
51
+ adAccountId: 'ad-account-id',
52
+ })
53
+ ```
54
+
55
+ `adAccountId` sets the `OpenAI-Ad-Account` request header. The header is
56
+ required for OAuth access tokens and shared API keys. An advertiser API key may
57
+ omit it. A request can override the client value with
58
+ `{ adAccountId: 'another-account-id' }`.
59
+
60
+ Most methods accept either credential. The following methods require a
61
+ specific credential:
62
+
63
+ | Credential | Methods |
64
+ | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
65
+ | OAuth access token | `adAccountCreationSessions.create`, `oauth.getMe` |
66
+ | API key | `businessAgentTools.list`, `apiKeys.create`, `conversions.apiKeys.create`, `conversions.events.list`, `partnerData.uploads.create`, `partnerData.uploads.get` |
67
+
68
+ ## Request options
69
+
70
+ Pass supported request options as the final argument:
71
+
72
+ | Option | Effect |
73
+ | ---------------- | ------------------------------------------------- |
74
+ | `adAccountId` | Overrides the client account for one request. |
75
+ | `signal` | Cancels the request with an `AbortSignal`. |
76
+ | `timeoutMs` | Overrides the client timeout for one request. |
77
+ | `idempotencyKey` | Sets `Idempotency-Key` where the API supports it. |
78
+
79
+ ```ts
80
+ await ads.campaigns.get('campaign-id', {}, { timeoutMs: 10_000 })
81
+ ```
82
+
83
+ Set `timeoutMs` on the client to apply one timeout to every request. A timeout
84
+ must be a positive integer. The SDK does not set a timeout by default, retry
85
+ failed requests, or auto-paginate list responses.
86
+
87
+ The TypeScript signature requires an idempotency key when the API requires one:
88
+
89
+ ```ts
90
+ await ads.customAudiences.addMembers('audience-id', body, {
91
+ idempotencyKey: crypto.randomUUID(),
92
+ })
93
+ ```
94
+
95
+ ## File uploads
96
+
97
+ `uploadBlob` accepts a `Blob` or `File` and sends multipart form data:
98
+
99
+ ```ts
100
+ await ads.files.uploadBlob({
101
+ file: new Blob([bytes]),
102
+ purpose: 'custom_audience',
103
+ })
104
+ ```
105
+
106
+ `uploadImage` accepts either an image URL or a `Blob` or `File`:
107
+
108
+ ```ts
109
+ await ads.files.uploadImage({ image_url: 'https://example.com/image.png' })
110
+ await ads.files.uploadImage({ file: imageBlob })
111
+ ```
112
+
113
+ ## Errors
114
+
115
+ ```ts
116
+ import { OpenAIAdsApiError } from '@coloop-ai/openai-ads-sdk'
117
+
118
+ try {
119
+ await ads.campaigns.get('campaign-id')
120
+ } catch (error) {
121
+ if (error instanceof OpenAIAdsApiError) {
122
+ console.error(error.status, error.code, error.message)
123
+ }
124
+ }
125
+ ```
126
+
127
+ | Error | Cause |
128
+ | ----------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
129
+ | `OpenAIAdsApiError` | An API response with a status outside 200-299. Includes `status`, `code`, `param`, `type`, `payload`, `response`, and a request summary. |
130
+ | `OpenAIAdsTimeoutError` | The client or request timeout elapsed. Includes `timeoutMs` and a request summary. |
131
+ | `OpenAIAdsConfigurationError` | The client configuration is invalid, or the method requires a different credential type. |
132
+ | Native fetch or `AbortSignal` error | The network request failed, or the caller cancelled it. The SDK preserves the original error. |
133
+
134
+ ## API
135
+
136
+ The client groups methods by API resource:
137
+
138
+ | Resource | Methods |
139
+ | ----------------------------- | -------------------------------------------------------------------------------------------- |
140
+ | `campaigns` | `list`, `create`, `get`, `update`, `activate`, `pause`, `archive` |
141
+ | `customAudiences` | `list`, `create`, `get`, `archive`, `addMembers`, `removeMembers`, `replaceMembers`, `merge` |
142
+ | `customAudiences.operations` | `get` |
143
+ | `businessAgentTools` | `list` |
144
+ | `businessAgents` | `list`, `create`, `get`, `update`, `preview`, `publish` |
145
+ | `leadForms` | `list`, `create`, `get`, `update`, `publish`, `archive` |
146
+ | `leadForms.testSubmissions` | `create` |
147
+ | `apiKeys` | `create` |
148
+ | `adAccount` | `get`, `updateBrand`, `updateNegativeKeywords`, `activate`, `pause` |
149
+ | `adAccount.spendLimitWindows` | `list`, `create`, `update`, `delete` |
150
+ | `adAccounts` | `list` |
151
+ | `adAccountCreationSessions` | `create` |
152
+ | `oauth` | `getMe` |
153
+ | `insights` | `adAccount`, `campaign`, `adGroup`, `ad` |
154
+ | `geo` | `search` |
155
+ | `leadSync.subscriptions` | `create`, `list`, `get`, `delete` |
156
+ | `conversions.apiKeys` | `create` |
157
+ | `conversions.eventSettings` | `create`, `list` |
158
+ | `conversions.pixels` | `create`, `list` |
159
+ | `conversions.events` | `list` |
160
+ | `conversions.insights` | `query` |
161
+ | `adGroups` | `list`, `create`, `get`, `update`, `activate`, `pause`, `archive` |
162
+ | `ads` | `list`, `create`, `get`, `update`, `preview`, `activate`, `pause`, `archive` |
163
+ | `files` | `uploadBlob`, `uploadImage` |
164
+ | `productFeeds` | `archive`, `create`, `list` |
165
+ | `productFeeds.uploads` | `list` |
166
+ | `productFeeds.products` | `query`, `patch` |
167
+ | `productFeeds.sftpAccess` | `get`, `createOrReplace`, `activate`, `pause` |
168
+ | `partnerData.uploads` | `create`, `get` |
169
+
170
+ ## Raw client
171
+
172
+ Import `@coloop-ai/openai-ads-sdk/raw` for low-level operations and API types.
173
+ Raw operations return result objects instead of only response bodies.
174
+
175
+ ## License
176
+
177
+ MIT License. See [LICENSE](./LICENSE).