Skip to main content

Why using this feature

  • Secure: Protects sensitive actions with trusted-device approval.
  • Flexible: Lets users approve requests anytime.
  • Controlled: Keeps humans in charge of critical tasks.
import { Auth0AI } from "@auth0/ai-langchain";

// Create Auth0AI client
const auth0AI = new Auth0AI();

// Define async user confirmation flow for buying stocks
const buyStockAuthorizer = auth0AI.withAsyncUserConfirmation({
  // Identify the user
  userID: (params: { userID: string }, ctx) => params.userID,
  // Message shown to user for confirmation
  bindingMessage: async ({ qty, ticker }) =>
    `Confirm the purchase of ${qty} ${ticker}`,
  // Details of the authorization request
  authorizationDetails: async ({ qty, ticker }) => [
    { type: "trade_authorization", qty, ticker, action: "buy" }
  ],
  // Target API and required scopes
  audience: process.env["AUDIENCE"],
  scopes: ["stock:trade"]
});

How it works

Generative AI apps and agents often need to act on events that happen asynchronously—for example:
  • Buy tickets when they become available.
  • Approve a purchase only after prices drop.
  • Trigger workflows when a system alert fires.
Asynchronous Authorization ensures the agent pauses for user consent before executing the action, keeping automation safe, transparent, and user-controlled. This process relies on a decoupled authentication flow where the user provides consent on a trusted device, such as their mobile phone, separate from the device where the agent was initially engaged.

Use cases

AI agents often need to perform actions that are long-running, are executed at a later time, or involve sensitive operations. For example:
  • Transactional approvals: An agent arranging a business trip might find a flight and hotel, but needs the user’s final approval to complete the purchase.
  • Accessing sensitive data: An agent might need to access a protected user’s health records to answer a query.
  • Executing high-privilege tasks: A DevOps agent might need permission to deploy a new version of an application to a production environment.
In these scenarios, the agent needs the user to approve an action at a later time. Asynchronous authorization allows the agent to initiate this request and let the user approve it at their convenience, creating a more seamless and secure user experience. This decoupled mechanism is also ideal for human-in-the-loop interactions, such as approving a stock purchase through a chatbot or completing a financial transaction with a banking agent.

Get started

To begin using Auth0 for calling your APIs in your GenAI applications, refer to the following resources: