API change notifier with GitHub approval
An AI agent that works out which API customers a merged pull request breaks, drafts a note to each of them, and sends nothing until someone merges a docs PR. Uses a hosted GitHub webhook endpoint and a webhook waiter.
In this guide, you run an AI agent, built by Chukwuka Ikeh, that starts when a merged pull request changes your OpenAPI spec. It finds the breaking changes, checks your request logs for the customers who still make those calls, and puts a migration guide entry plus a note to each of them in a docs PR. Merging the docs PR sends the notes, and closing it sends nothing. The demo company is Murmurly, a made-up speech-to-text API with six customers and 90 days of seeded request logs.
The guide has 3 parts:
- Set up the project: clone the example, push it to a repo of your own, add your keys and start dev.
- Connect GitHub: point a repo webhook at the hosted
githubendpoint. - Run the demo: merge a spec change, review the docs PR, and merge it to send the notes.
The full code is in jackbridger/api-change-notifier.
Prerequisites
- A Trigger.dev project
- Node.js 22.18 or later, and oasdiff on your PATH (
brew install oasdiff, or a binary from its releases) - A GitHub account where you can create a repo
- A Claude API key and a Resend API key
Set up the project
1. Clone and install
git clone https://github.com/jackbridger/api-change-notifier.git
cd api-change-notifier
npm install
cp .env.example .env2. Push it to a repo of your own
The agent watches the repo that holds the spec and the migration guide, so create an empty GitHub repo and push the project to it. Replace YOUR_GITHUB_USERNAME with your GitHub username.
git remote set-url origin https://github.com/YOUR_GITHUB_USERNAME/api-change-notifier.git
git push -u origin mainThen create a fine-grained token for that repo with read and write access to Contents and Pull requests.
3. Fill in .env
TRIGGER_PROJECT_REF: your project's ref, from the project settings page in the dashboardGITHUB_TOKEN: the token from step 2ANTHROPIC_API_KEYandRESEND_API_KEY: your API keysEMAIL_FROM:onboarding@resend.devworks for testing
4. Seed the request logs and start dev
npm run seed
npm run devpnpm run seed
pnpm run devyarn seed
yarn devbun run seed
bun run devThe seed prints Wrote N requests from 6 customers to data/usage.db, where N depends on the day you run it. Once dev is running, the github endpoint appears on the Webhooks page of your Development environment.
Connect GitHub
1. Copy the endpoint's URL and secret
In the dashboard, open the github endpoint and go to its Settings tab. Choose Generate secret and copy it, then copy the Webhook URL from the same tab.
2. Add the webhook on GitHub
In your GitHub repo, go to Settings > Webhooks > Add webhook. Paste the URL and the secret, and set Content type to application/json. Choose Let me select individual events, untick Pushes and tick Pull requests.

GitHub's first delivery, a ping, shows as FILTERED on the endpoint's Deliveries tab. That's expected, because only merged pull requests get through.
Run the demo
1. Merge a spec change
The seeded calls end on the day you ran npm run seed, so if that was a few days ago, run it again and restart dev. Then:
git checkout -b move-word-timings
cp demo/openapi.next.yaml openapi.yaml
git commit -am "Move word timings into the transcript"
git push -u origin move-word-timingsOpen a PR for the branch and merge it. The change removes GET /v1/transcripts/{id}/words, renames speaker_labels to diarization and replaces page with a cursor. In the seeded logs, three customers break and three don't.
2. Review the docs PR
The merged PR gets a comment naming the three customers, and a PR titled Migration guide: ... opens with the guide entry and every note in its description. In the dashboard you can follow on-pull-request-merged, api-change-notifier and analyze-api-change, whose trace shows each model and tool call.

3. Merge it to send the notes
Merge the docs PR. The waiting run resumes, sends the three notes and comments on the original PR with who got one. The notes go to Resend's delivered+...@resend.dev test addresses, so you can see them in the Resend dashboard without emailing anyone.

How it works
A webhook task on the hosted endpoint starts the notifier. GitHub has no separate event for a merge, so the filter matches closed with merged set to true.
export const onPullRequestMerged = ({
id: "on-pull-request-merged",
endpoint: github, // webhooks.endpoint.define({ id: "github", source: webhooks.github() })
filter:
"header.x-github-event == 'pull_request' && event.action == 'closed' && event.pull_request.merged == true && event.pull_request.base.ref == event.repository.default_branch",
: async ({ event }) => {
const { pull_request: pr, repository } = MergedPullRequest.parse(event);
if (pr.head.ref.startsWith(BRANCH_PREFIX)) return; // one of the agent's own docs PRs
if (!(await findChangedFile(repository.full_name, pr.number, config.specPath))) return; // spec unchanged
await apiChangeNotifier.trigger(
{ repo: repository.full_name, prNumber: pr.number },
{ idempotencyKey: "notifier", tags: [`pr:${pr.number}`] } // a retry won't start a second notifier
);
},
});The notifier runs oasdiff changelog on the spec before and after the pull request's changes, then hands the breaking changes to an AI SDK agent with two tools over the request logs, findCallers and getRecentRequests. A removed field only breaks the customers who send it, so the agent writes a note only for customers a tool returned, and never sees an email address.
Then it waits for the docs PR on a webhook waiter. The waiter is created before the docs PR exists, so it matches the branch name the notifier picks up front:
const waiter = await ..create(github, {
: {
"header.x-github-event": "pull_request",
"event.action": "closed", // merged or not; checks `merged` after waking
"event.repository.full_name": repo,
"event.pull_request.head.ref": branch, // the PR number doesn't exist yet
"event.pull_request.head.repo.full_name": repo, // not a fork's branch with the same name
},
: config.approvalTimeout, // 7d by default
: "docs-pr-closed",
});
// opens the docs PR and comments on the merged one, then:
const closed = await ..wait(waiter); // suspended, no computeAfter a merge, batchTriggerAndWait starts one send-migration-note run per customer. Each looks up the address in your records and passes Resend an idempotency key, so a retry can't email anyone twice.
Under trigger dev the run isn't checkpointed, so your dev process stays alive for the whole wait. Deployed, the run is suspended and uses no compute. In both, the wait doesn't count toward maxDuration.
Next steps
- Deploy with
npm run seed && npm run deploy, then addGITHUB_TOKEN,ANTHROPIC_API_KEY,RESEND_API_KEYandEMAIL_FROM(on your own verified domain) to Production. Production has its owngithubendpoint, so generate its secret and point the repo's webhook at its URL. - Point the queries in
src/lib/usage.tsat your own request logs. The agent needs the customer, method, route template, parameter and field names, client and time of each call, never their values. The docs PR shows each affected customer's name and note, and the comment on the merged PR names them, so use a private repo once the logs are real. - Webhook waiters: pause a run until a matching webhook arrives
- Filters: decide which deliveries start a run
- GitHub webhooks: set up the GitHub source
- LLM observability: model and tool call spans from the AI SDK
Was this page helpful?
Last updated
Edit on GitHub