SDK

AI21 offers Python and TypeScript libraries that simplify the process of using our LLM’s API.

Get an API key

Before you can start using the SDK, you'll need to obtain your API key from AI21 Studio.

Python SDK

Python library GitHub repository

Installation

Install ai21 Python SDK with your favorite package manager

pip install ai21

Example usage

import os

from ai21 import AI21Client
from ai21.models.chat import ChatMessage


client = AI21Client(api_key=os.getenv('AI21_API_KEY'))  # or pass it in directly

response = client.chat.completions.create(
    model='jamba-large',
    messages=[ChatMessage(role='user', content='Hello, please provide a brief explanation of what AI21 does, in 100 words or less')]
)

print(response)

TypeScript SDK

TypeScript library GitHub repository .

Installation

Install ai21 Typescript SDK with your favorite package manager

npm install ai21

Usage Example

import { AI21 } from 'ai21';

const client = new AI21({
  apiKey: process.env.AI21_API_KEY, // or pass it in directly
});

const response = await client.chat.completions.create({
  model: 'jamba-large',
  messages: [{ role: 'user', content: 'Hello, please provide a brief explanation of what AI21 does, in 100 words or less"' }],
});

console.log(response);