Skip to main content

Setup & Prerequisites

There are a few prerequisites to getting started with integrating LLMs into your application:

  • LLM API Key - To generate messages using an LLM, you will need to have an API Key for the LLM you are using.

Install the required AI packages to your application:

npm install @microsoft/teams.apps @microsoft/teams.ai @microsoft/teams.openai

For development, you may also want to install the DevTools plugin:

npm install @microsoft/teams.dev --save-dev
  • In your application, you should include your keys in a secure way. We recommend putting it in an .env file at the root level of your project
my-app/
|── appPackage/ # Teams app package files
├── src/
│ └── index.ts # Main application code
|── .env # Environment variables

Azure OpenAI​

You will need to deploy a model in Azure OpenAI. View the resource creation guide for more information on how to do this.

Once you have deployed a model, include the following key/values in your .env file:

AZURE_OPENAI_API_KEY=your-azure-openai-api-key
AZURE_OPENAI_MODEL_DEPLOYMENT_NAME=your-azure-openai-model
AZURE_OPENAI_ENDPOINT=your-azure-openai-endpoint
AZURE_OPENAI_API_VERSION=your-azure-openai-api-version
info

The AZURE_OPENAI_API_VERSION is different from the model version. This is a common point of confusion. Look for the API Version here

OpenAI​

You will need to create an OpenAI account and get an API key. View the OpenAI Quickstart Guide for how to do this.

Once you have your API key, include the following key/values in your .env file:

OPENAI_API_KEY=sk-your-openai-api-key
note

Automatic Environment Variable Loading: The OpenAI model automatically reads environment variables when options are not explicitly provided. You can pass values explicitly as constructor parameters if needed for advanced configurations.

// Automatic (recommended) - uses environment variables
const model = new OpenAIChatModel({
model: 'gpt-4o',
});

// Explicit (for advanced use cases)
const model = new OpenAIChatModel({
apiKey: 'your-api-key',
model: 'gpt-4o',
endpoint: 'your-endpoint', // Azure only
apiVersion: 'your-api-version', // Azure only
baseUrl: 'your-base-url', // Custom base URL
organization: 'your-org-id', // Optional
project: 'your-project-id', // Optional
});

Environment variables automatically loaded:

  • OPENAI_API_KEY or AZURE_OPENAI_API_KEY
  • AZURE_OPENAI_ENDPOINT (Azure only)
  • OPENAI_API_VERSION (Azure only)