Secure OpenAI Ads CAPI Implementation: API Keys, Server Boundaries, and Common Leaks
The most common OpenAI Ads CAPI mistake is calling the API from browser-side JavaScript. Here's how to check your own site in two minutes, the correct server-only pattern, and what to do if a key already leaked.
Unlike client-side pixel IDs, which are public by design, your OpenAI Ads Conversions API (CAPI) access token is a private administrative secret.
If an engineer hardcodes a CAPI token into frontend JavaScript bundles or commits it to a repository, third parties can read the credential and transmit fabricated conversion events into your ad account.
Security also applies to customer data hygiene. Transmitting raw customer emails, cleartext phone numbers, or unhashed addresses violates privacy frameworks like GDPR and CCPA.
Securing your server-side CAPI implementation requires strict separation between browser and server environments, automated credential management, and SHA-256 data hashing.
The architectural boundary: browser versus server
The OpenAI Ads measurement pixel is engineered for the browser. It initializes using a public Pixel ID and transmits engagement telemetry as visitors interact with page elements.
The Conversions API operates under a completely different architecture. CAPI requests require an Authorization: Bearer <API-KEY> HTTP header carrying a secret token that grants write access to your event stream.
Browser (Client actions)
│
▼ DOM event executes (purchase, form submit)
Application Backend (Server infrastructure)
│
▼ POST https://bzr.openai.com/v1/events?pid=<PIXEL-ID>
│ Authorization: Bearer <API-KEY>
OpenAI Ads Ingestion Endpoint
The browser must never communicate directly with the CAPI endpoint. Purchases and lead submissions should process on your application server, with the backend dispatching the CAPI call over an isolated HTTPS connection.
Testing your site for credential exposure
Inspect your live site to confirm that private API tokens remain unexposed:
- Open your site in an incognito window, open browser developer tools (F12 or right-click Inspect), and navigate to the Network tab.
- Complete a test transaction or submit a contact form.
- Filter the network request log for
bzr.openai.com. - Inspect outbound requests directed to
bzr.openai.com/v1/events. If you observe calls containing anAuthorization: Bearer ...header originating from the browser, your API key is exposed in client-side code. - In the developer tools Sources tab, search bundled scripts for the string
Beareror references to your CAPI endpoint to ensure tokens are not embedded in static assets.
If a credential appears in client assets, rotate the key immediately within OpenAI Ads Manager.
Credential security protocols
Isolate your API tokens following standard production security practices:
Store credentials in server environment variables or a dedicated secrets manager (AWS Secrets Manager, Google Secret Manager, HashiCorp Vault). Avoid storing keys in committed application configuration files.
Exclude secrets from source control. Verify that .env files and local test scripts appear in .gitignore. If a token is committed to a repository, treat it as compromised and rotate it immediately.
Enforce least privilege access. Restrict token access to the specific backend service responsible for dispatching conversion webhooks.
Separate public identifiers from private secrets. While your Pixel ID is public and visible in page source code, the API token must remain private to server infrastructure.
Customer data privacy and SHA-256 hashing
When attaching customer parameters to CAPI payloads to improve match quality, privacy regulations require hashing sensitive fields prior to transmission:
Normalize data before hashing: strip whitespace, convert strings to lowercase, and remove non-numeric characters from phone numbers.
Compute SHA-256 digests over the normalized strings using UTF-8 encoding.
Never send unhashed emails, phone numbers, or physical street addresses in payload parameters.
Example Node.js normalization and hashing routine:
const crypto = require('crypto');
function hashData(val) {
if (!val) return null;
const clean = val.trim().toLowerCase();
return crypto.createHash('sha256').update(clean, 'utf8').digest('hex');
}
Detailed hashing requirements are covered in our guide to sending hashed user data.
Logging and data retention hygiene
Avoid recording full HTTP request payloads in standard application logs. Logging unscrubbed bodies can expose customer order data in logging tools with broader access permissions and longer retention periods than your core database.
Log operational metadata (HTTP response codes, event IDs, timestamps) while omitting raw user details.
Credential rotation procedure
If an API key is exposed in client code or committed to a repository, execute this rotation sequence:
- Generate a new Conversions API token in the conversions tab of OpenAI Ads Manager.
- Update your production environment variables and secret stores with the new credential.
- Invalidate or delete the exposed key in Ads Manager.
- Verify server logs to confirm outgoing CAPI requests succeed using the new token.
- Re-inspect the live site's network activity to confirm that no client-side scripts attempt to use the old credential.
Establishing strict server boundaries and verified secret isolation ensures your conversion data remains dependable and compliant.
You can also audit live storefronts quickly with OpenAI Ads Pixel Helper, which raises an immediate error banner if any client script sends a request straight to /v1/events.
Shopify merchants running these tracking patterns can deploy the Theme App Embed, sandboxed Web Pixel, _oppref cart bridge, and AES-GCM-256 encrypted Conversions API pipeline automatically using our free Y OpenAI Ads Pixel ChatGPT Ads app.
Need ChatGPT tracking installed?
Configured, tested, documented.