- An OpenAI account and API key. You can create one here.
- An Auth0 account and the following settings and resources configured:
- An application for CIBA with the following settings:
- Application Type:
Web Application - Grant Type:
CIBA(orurn:openid:params:grant-type:ciba)
- Application Type:
- An API with the following settings:
- Name:
Sample Stock API - Identifier:
sample-stock-api - Permissions:
stock:trade
- Name:
- Push Notifications using Auth0 Guardian must be
enabled - A test user enrolled in Guardian MFA.
- An application for CIBA with the following settings:
Copy the .env.example file to .env and fill in the values for the following variables, using the settings obtained from the prerequisites:
# Auth0
AUTH0_DOMAIN="{yourDomain}"
# M2M Client for CIBA
AUTH0_CLIENT_ID="{yourClientId}"
AUTH0_CLIENT_SECRET="{yourClientSecret}"
# API
STOCK_API_URL=http://an-api-url
STOCK_API_AUDIENCE=sample-stock-api
# OpenAI
OPENAI_API_KEY="openai-api-key"-
Install dependencies.
npm install # or bun install -
Update your user id in the sample src/index.ts provided.
const { text } = await generateText({
model: openai("gpt-4o-mini"),
system: "You are an assistant. Invoke the tool if needed, then respond with a past-tense confirmation.",
prompt: userPrompt,
// pass an Auth0 user id. For example, 'auth0|100000000000000000000' or 'google-oauth2|100000000000000000000'
tools: { buy: buy({ userId: "<authenticated-user-id>" }) },
stopWhen: stepCountIs(3), // tool call + result + final assistant message
});-
Running the example
npm start # or bun start
Apache-2.0
