LlamaIndex RAG chat app with Azure OpenAI and Azure AI Search (JavaScript)
This solution creates a ChatGPT-like, Retrieval Augmented Generation (RAG) agentic application, over your own documents, powered by Llamaindex (TypeScript). It uses Azure OpenAI Service to access GPT models and embedding, and Azure AI Search for data indexing and retrieval.
Learn more about developing AI apps using Azure AI Services.
Important Security Notice
This template, the application code and configuration it contains, has been built to showcase Microsoft Azure specific services and tools. We strongly advise our customers not to make this code part of their production environments without implementing or enabling additional security features. See our productionizing guide for tips, and consult the Azure OpenAI Landing Zone reference architecture for more best practices.
Table of Contents

The repo includes sample data so it's ready to try end to end. In this sample application we use one of Paul Graham's essays, What I Worked On, and the experience allows you to ask questions about this essay.
Architecture Diagram

Azure account requirements
IMPORTANT: In order to deploy and run this example, you'll need:
- Azure account. If you're new to Azure, get an Azure account for free and you'll get some free Azure credits to get started.
- Azure account permissions:
- Your Azure account must have
Microsoft.Authorization/roleAssignments/write permissions, such as Role Based Access Control Administrator, User Access Administrator, or Owner. If you don't have subscription-level permissions, you must be granted RBAC for an existing resource group and deploy to that existing group.
- Your Azure account also needs
Microsoft.Resources/deployments/write permissions on the subscription level.
Cost estimation
Pricing varies per region and usage, so it isn't possible to predict exact costs for your usage.
However, you can try the Azure pricing calculator for the resources below.
- Azure Container Apps: Consumption plan with 1 CPU core, 2.0 GB RAM. Pricing with Pay-as-You-Go. Pricing
- Azure OpenAI: Standard tier, gpt-4o-mini and text-embedding-3-large models. Pricing per 1K tokens used. Pricing
- Azure AI Search: Standard tier, 1 replica, free level of semantic search. Pricing per hour. Pricing
- Azure Blob Storage: Standard tier with ZRS (Zone-redundant storage). Pricing per storage and read operations. Pricing
- Azure Monitor: Pay-as-you-go tier. Costs based on data ingested. Pricing
To reduce costs, you can switch to free SKUs for various services, but those SKUs have limitations.
To try out the example at no cost refer Running application at no cost.
To avoid unnecessary costs, remember to take down your app if it's no longer in use,
either by deleting the resource group in the Portal or running azd down.
Getting Started
You have a few options for setting up this project.
The easiest way to get started is GitHub Codespaces, since it will setup all the tools for you,
but you can also set it up locally if desired.
GitHub Codespaces
You can run this repo virtually by using GitHub Codespaces, which will open a web-based VS Code in your browser:
Once the codespace opens (this may take several minutes), open a terminal window.
VS Code Dev Containers
A related option is VS Code Dev Containers, which will open the project in your local VS Code using the Dev Containers extension:
-
Start Docker Desktop (install it if not already installed)
-
Open the project:
-
In the VS Code window that opens, once the project files show up (this may take several minutes), open a terminal window.
Local environment
- Install the required tools:
- Create a new folder and switch to it in the terminal.
- Run this command to download the project code:
azd init -t llama-index-vector-search-javascript
Note
This command will initialize a git repository, so you do not need to clone this repository.
Deploying
The steps below will provision Azure resources and deploy the application code to Azure Container Apps.
Login to your Azure account:
For GitHub Codespaces users, if the previous command fails, try:
azd auth login --use-device-code
Create a new azd environment:
Enter a name that will be used for the resource group.
This will create a new folder in the .azure folder, and set it as the active environment for any calls to azd going forward.
Provision the infrastructure needed to run the application.
Important
This application specifically requires some environment variables to be available during the packaging phase. This is why we need to provision the infra first before packaging and deploying the app. In most cases, simply running 'azd up' will package, provision and deploy your apps.
Package and deploy the app to Azure:
Note
This will provision Azure resources and deploy this sample to those resources, including building the search index based on the files found in the ./data folder.
After the application has been successfully deployed you will see a URL printed to the console. Click that URL to interact with the application in your browser.
It will look like the following:

Note
It may take 5-10 minutes after you see 'SUCCESS' for the application to be fully deployed.
Important
Beware that the resources created by this command will incur immediate costs, primarily from the AI Search resource. These resources may accrue costs even if you interrupt the command before it is fully executed. You can run azd down or delete the resources manually to avoid unnecessary spending.
You will be prompted to select two locations, one for the majority of resources and one for the OpenAI resource, which is currently a short list. That location list is based on the OpenAI model availability table and may become outdated as availability changes.
Deploying again
If you've only changed the Next.js app code in the app folder, then you don't need to re-provision the Azure resources. You can just run:
If you've changed the infrastructure files (infra folder or azure.yaml), then you'll need to re-provision the Azure resources. You can do that by running:
Authentication
Every API route (/api/chat, /api/chat/upload, /api/chat/config, /api/chat/config/llamacloud, /api/files/*) checks the caller before it reads files, touches the index, or calls Azure OpenAI. The AUTH_MODE environment variable controls the check:
AUTH_MODE |
Behavior |
| unset |
npm run dev allows anonymous access so local development keeps working. npm start and the container image reject every API request with 401. |
easyauth |
Requires the X-MS-CLIENT-PRINCIPAL-ID header that Azure Container Apps built-in authentication sets for signed-in users. Only set this when built-in authentication is enabled and requires sign-in. Container Apps strips that header from client requests only when built-in authentication is on. |
anonymous |
No authentication. Don't use this on a public endpoint. It's only for local testing or when another gateway authenticates every request. |
Turn on sign-in for your deployment
A fresh azd up deploys an app whose API returns 401 until you turn on sign-in:
-
In the Azure portal, open the container app in the rg-<env-name> resource group.
-
Go to Settings > Authentication > Add identity provider, pick Microsoft, and let it create a new app registration. Keep Require authentication and HTTP 302 Found redirect.