With Node.js/Bun/Deno
In this guide, you'll learn how to use LlamaIndex with Node.js, Bun, and Deno.
Adding environment variables
By default, LlamaIndex uses OpenAI provider, which requires an API key. You can set the OPENAI_API_KEY
environment variable to authenticate with OpenAI.
export OPENAI_API_KEY=your-api-key
Or you can use a .env
file:
echo "OPENAI_API_KEY=your-api-key" > .env
node --env-file .env your-script.js
Do not commit the api key to git repository.
For more information, see the How to read environment variables from Node.js.
Performance Optimization
By the default, we are using js-tiktoken
for tokenization. You can install gpt-tokenizer
which is then automatically used by LlamaIndex to get a 60x speedup for tokenization:
npm i gpt-tokenizer
pnpm add gpt-tokenizer
yarn add gpt-tokenizer
bun add gpt-tokenizer
Note: This only works for Node.js
TypeScript support
Getting Started with LlamaIndex.TS in TypeScript
Edit on GitHub
Last updated on