Sanitize OpenAI Responses API input to remove base64 encoded images
Problem
It seems only some of the API calls had added the sanitazion method for removing base64 encoded images from the input sent to PostHog (see https://github.com/PostHog/posthog-js/issues/2134).
This would currently result in the payload sent to PostHog being too large, giving an error like this:
Error while flushing PostHog: message=HTTP error while fetching PostHog: status=413, reqByteLength=868722, response body=maximum event size exceeded: Event rejected by kafka during send PostHogFetchHttpError: HTTP error while fetching PostHog: status=413, reqByteLength=868722
at retriable (file:///node_modules/@posthog/core/dist/posthog-core-stateless.mjs:593:77)
at processTicksAndRejections (node:internal/process/task_queues:105:5)
at retriable (file:///node_modules/@posthog/core/dist/utils/index.mjs:22:25)
at PostHog.fetchWithRetry (file:///node_modules/@posthog/core/dist/posthog-core-stateless.mjs:582:16)
at PostHog._flush (file:///node_modules/@posthog/core/dist/posthog-core-stateless.mjs:549:17) {
response: Response {
status: 413,
statusText: 'Payload Too Large',
headers: Headers {
date: 'Wed, 22 Oct 2025 11:03:35 GMT',
'content-type': 'text/plain; charset=utf-8',
'transfer-encoding': 'chunked',
connection: 'keep-alive',
vary: 'origin, access-control-request-method, access-control-request-headers, Accept-Encoding',
'access-control-allow-credentials': 'true',
'x-envoy-upstream-service-time': '17',
'content-encoding': 'gzip',
server: 'envoy',
'strict-transport-security': 'max-age=31536000; includeSubDomains'
},
body: ReadableStream { locked: true, state: 'closed', supportsBYOB: true },
bodyUsed: true,
ok: false,
redirected: false,
type: 'basic',
url: 'https://us.i.posthog.com/batch/'
},
reqByteLength: 868722
}
Most of the work was already done in https://github.com/PostHog/posthog-js/pull/2217, it was just missing the responses API, which this PR adds.
Changes
- Wrapped the input sent to PostHog for the Responses API with
sanitizeOpenAI
Release info Sub-libraries affected
Libraries affected
- [ ] All of them
- [ ] posthog-js (web)
- [ ] posthog-js-lite (web lite)
- [ ] posthog-node
- [ ] posthog-react-native
- [ ] @posthog/react
- [x] @posthog/ai
- [ ] @posthog/nextjs-config
Checklist
- [ ] Tests for new code
- [x] Accounted for the impact of any changes across different platforms
- [x] Accounted for backwards compatibility of any changes (no breaking changes!)
- [x] Took care not to unnecessarily increase the bundle size
If releasing new changes
- [ ] Ran
pnpm changesetto generate a changeset file - [ ] Added the "release" label to the PR to indicate we're publishing new versions for the affected packages
@Tehnix is attempting to deploy a commit to the PostHog Team on Vercel.
A member of the Team first needs to authorize it.
This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.
Would love to see this one merged
@posthog-bot This is still very much relevant, I'm running a locally patched version of @posthog/ai currently that adds this.
This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.
@posthog-bot This is still very much relevant, I'm running a locally patched version of @posthog/ai currently that adds this.
I'll update the PR to resolve the conflicts tomorrow though
@PostHog/team-llm-analytics are you the right team to loop in here? Apologize if I shouldn't tag anyone directly, if that's the case lemme know and I'll just keep the PRs open and let your internal triage handle when you have time for it :)
This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.
@posthog-bot yup, please don't close this!
This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.
@posthog-bot yup, please don't close this!