Registry / llm-agents / ai21

ai21

JSON →
library4.3.0pypypi✓ verified 47d ago

Official Python SDK for AI21 Labs API. Provides access to Jamba models (chat completions, streaming) and legacy J2 Jurassic models (completions). Current version: 4.3.0 (Mar 2026). SDK has two distinct API surfaces — modern Jamba chat completions API and legacy J2/Jurassic API — with different ChatMessage signatures. Jamba models are current; J2 models are legacy.

llm-agentsai-mlhttp-networking
pip install ai21
Install & Compatibility
Where this runs
tested against v4.3.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.925 runs
installs and imports cleanly · install 0.0s · import 1.055s · 33MB
glibc
py 3.103.925 runs
installs and imports cleanly · install 4.0s · import 0.982s · 33MB
31MB installed
● package 31MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

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

Minimal AI21 Jamba chat completion using ai21 SDK 4.x.

# pip install ai21 from ai21 import AI21Client from ai21.models.chat import ChatMessage import os client = AI21Client() # reads AI21_API_KEY env var response = client.chat.completions.create( model='jamba-large', messages=[ ChatMessage(content='You are a helpful assistant.', role='system'), ChatMessage(content='Explain large language models briefly.', role='user') ], max_tokens=150, temperature=0.7 ) print(response.choices[0].message.content)
Debug
Known issues
breakingTwo ChatMessage classes exist: ai21.models.chat.ChatMessage (Jamba, uses content=) and ai21.models.ChatMessage (J2/legacy, uses text= and RoleType). Mixing them causes TypeError.
fix
For Jamba models use: from ai21.models.chat import ChatMessage with content= and string roles. For J2 legacy: from ai21.models import ChatMessage with text= and RoleType.
affects: >= 2.0
breakingOld J2/Jurassic API uses client.chat.create() with system= as separate param. New Jamba API uses client.chat.completions.create() with system message inside messages list. Completely different method name.
fix
For Jamba: client.chat.completions.create(messages=[...]). For J2: client.chat.create(system=..., messages=[...]).
affects: >= 2.0
gotchaLLMs trained pre-2024 have no knowledge of Jamba models. Will generate J2 Jurassic patterns (model='j2-ultra', RoleType, text= parameter) which are legacy and will be deprecated.
fix
Use Jamba models: 'jamba-large', 'jamba-mini'. Use content= not text=. Use string roles not RoleType enum.
affects: all
gotchaAPI key env var is AI21_API_KEY. SDK reads it automatically if not passed explicitly to AI21Client().
fix
export AI21_API_KEY=your_key or pass api_key= to AI21Client().
affects: all
deprecatedJ2 Jurassic models (j2-ultra, j2-mid, j2-light) are legacy. Jamba is the current model family. New features only on Jamba.
fix
Migrate to jamba-large or jamba-mini for new projects.
affects: all
Upgrade
Version history
4.3.0latest on PyPI
Audit
Dependencies
httpxrequiredHTTP client. Installed automatically.
Agent activity
103 hits · last 30 days
node
20
seranking-bot
4
Amazon
2
petalbot
2
ahrefsbot
2
bytedance
2
amazonbot
1
Google (AI)
1
OpenAI (training)
1
Resources