What you’ll learn
- Async Authorization: Use CIBA to let AI agents get user consent securely in the background.
- User Approvals: Add Auth0 AI SDK for clear, human-in-the-loop authorization.
Before you start
Before you start
Before getting started, make sure you have completed the following steps:
1
Create an Auth0 Account
To continue with this quickstart, you need to have an Auth0 account.
2
Create an Auth0 Application
Go to your Auth0 Dashboard to create a new Auth0 Application.
- Navigate to Applications > Applications in the left sidebar.
- Click the Create Application button in the top right.
- In the pop-up select Regular Web Applications and click Create.
- Once the Application is created, switch to the Settings tab.
- Scroll down to the Application URIs section.
- Set Allowed Callback URLs as:
http://localhost:3000/auth/callback - Set Allowed Logout URLs as:
http://localhost:3000 - Click Save in the bottom right to save your changes.
3
OpenAI Platform
Set up an OpenAI account and API key.
Next.js
Node.js
Getting started using AI
To get started quickly:Then, integrate Auth0 AI docs into your preferred AI tool:
- VS Code
- Cursor
- Claude Code
- Claude
or Follow manual steps
1
Install dependencies
In the root directory of your project, install the following dependencies:
@auth0/ai-vercel: Auth0 AI SDK for AI SDK built for AI agents powered by the AI SDK.ai: Core AI SDK module that interacts with various AI model providers.@ai-sdk/openai: OpenAI provider for the AI SDK.@ai-sdk/react: React UI components for the AI SDK.zod: TypeScript-first schema validation library.
2
Update the environment file
Copy the
.env.example file to .env.local and update the variables with your Auth0 credentials. You can find your Auth0 domain, client ID, and client secret in the application you created in the Auth0 Dashboard.3
Set up HITL approvals
Integrate the Auth0 AI SDK into your application to secure your async AI agent workflow. For this quickstart, we will use a blocking request flow. In real use cases, often an asynchronous flow is preferred.This will intercept the tool call to initiate a CIBA request:
Next, add the following code to
Configure the Auth0 AI SDK
To require asynchronous authorization for your tool, the tool needs to be wrapped with the Async authorizer,withAsyncAuthorization(). Let’s create a helper function to wrap the tool with the Async authorizer.Create a file at src/lib/auth0-ai.ts and instantiate a new Auth0 AI SDK client:src/lib/auth0-ai.ts
- The CIBA request includes the user ID that will approve the request.
- Auth0 sends the user a mobile push notification. The AI agent polls the
/tokenendpoint for a user response. - The mobile application retrieves the
bindingMessagecontaining the consent details, in this case, the details of the product to purchase. - The user responds to the request:
- If the request is approved, the tool execution will continue.
- If the request is rejected, the tool execution will not continue.


src/lib/auth0.ts:src/lib/auth0.ts
Require async authorization for your tool
In this example, we wrap a tool that buys products on the user’s behalf. When the user approves the transaction, the Auth0 AI SDK retrieves an access token to call the shop’s API. Upon completing the CIBA flow, the AI agent responds with a message confirming the purchase.The Auth0 AI SDK returns an error response if the user denies the transaction.Now, create and wrap the tool with the Async authorizer. Create a filesrc/lib/tools/shop-online.ts and add the following code:src/lib/tools/shop-online.ts
4
Update environment variables
You need to obtain an API Key from OpenAI or another provider to use an LLM.If you want to use an API, it must be registered with Auth0 and have a valid audience.Update the
.env.local file with the following variables:.env.local
5
Integrate the tool
Call the tool from your AI app to make purchases. Update the
src/app/api/chat/route.ts file with the following code:src/app/api/chat/route.ts
6
Test the application
Start the application with
npm run dev. Then, navigate to http://localhost:3000.You can ask the AI agent to buy a product, for example, “Buy an XYZ phone.” Now, look for a push notification from the Auth0 Guardian app or your custom app integrated with the Auth0 Guardian SDK on your mobile device. Once you approve the notification, you should see the tool being executed and a response from the agent.