Skip to main content
This notebook covers how to get started with AI21 chat models. Note that different chat models support different parameters. See the AI21 documentation to learn more about the parameters in your chosen model. See all AI21’s LangChain components.

Integration details

Model features

Setup

Credentials

We’ll need to get an AI21 API key and set the AI21_API_KEY environment variable:
To enable automated tracing of your model calls, set your LangSmith API key:

Installation

!pip install -qU langchain-ai21

Instantiation

Now we can instantiate our model object and generate chat completions:

Invocation

Chaining

We can chain our model with a prompt template like so:

Tool Calls / Function Calling

This example shows how to use tool calling with AI21 models:

API reference

For detailed documentation of all ChatAI21 features and configurations head to the API reference: python.langchain.com/api_reference/ai21/chat_models/langchain_ai21.chat_models.ChatAI21.html