Skip to main content

Get an API key

Before you can start using the SDK, you’ll need to obtain your API key from AI21 Studio.
See the full guide here: Create an API Key.

Installation

Install ai21 Python SDK with your favorite package manager.

Authentication

There are two ways to authenticate with the SDK:

Option 1: Pass the API key directly
Option 2: Use an environment variable Set the variable in your terminal:
Then in your Python code, you can initialize the client without explicitly passing the key:
For details on how authentication works at the HTTP level, see the API Refrence Autentication.

Example usage

This example demonstrates how to initialize the AI21 Python SDK client and send a simple chat message using the jamba-mini model.

Python SDK

For more examples and detailed usage, check out our Python library GitHub repository.

Python library GitHub repository