Most AI agents today are still authenticating with a raw API key copied into an env file months ago — which means no real identity, no proper audit trail, and no clean way to revoke access for one service without breaking everything else.
This video shows you how to fix that with Clerk’s Machine-to-Machine (M2M) tokens.
Clerk M2M gives each service its own machine identity, so your AI agents, dashboards, cron jobs, webhook workers, and backend services can securely talk to each other without relying on one shared secret. That means better security, better visibility, and way more control as your systems start running autonomously.
In this video, I will build two separate apps in one repo — a Next.js dashboard with a protected API and a separate AI agent service that authenticates itself using Clerk M2M tokens. You’ll see the full lifecycle: setup, token creation, verification, protected API access, and revocation.
We’ll cover:
âś… Why API keys break down for AI agents and multi-service systems
âś… What Clerk Machine-to-Machine tokens are and why they matter
âś… Setting up machine identities inside Clerk
âś… Connecting a Next.js dashboard app and a Node.js agent service
âś… Generating M2M tokens and passing them in API requests
âś… Verifying tokens on a protected backend route
âś… Revoking compromised tokens instantly
âś… Opaque tokens vs JWTs and when to use each one
âś… Real-world use cases for AI agents, cron jobs, webhook workers, billing services, and more
If you’re building AI agents that call your APIs, this is one of those security layers you really don’t want to skip.