{"id":147,"library":"ai21","title":"AI21 Python SDK","description":"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.","status":"active","version":"4.3.0","language":"python","source_language":"en","source_url":"https://github.com/AI21Labs/ai21-python","tags":["ai21","jamba","llm","python","chat-completions"],"install":[{"cmd":"pip install ai21","lang":"bash","label":"Python"}],"dependencies":[{"reason":"HTTP client. Installed automatically.","package":"httpx","optional":false}],"imports":[{"wrong":"from ai21 import AI21Client","symbol":"AI21Client","correct":"from ai21 import AI21Client"},{"wrong":"from ai21.models.chat import ChatMessage","symbol":"ChatMessage","correct":"from ai21 import ChatMessage"}],"quickstart":{"code":"# pip install ai21\nfrom ai21 import AI21Client\nfrom ai21.models.chat import ChatMessage\nimport os\n\nclient = AI21Client()  # reads AI21_API_KEY env var\n\nresponse = client.chat.completions.create(\n    model='jamba-large',\n    messages=[\n        ChatMessage(content='You are a helpful assistant.', role='system'),\n        ChatMessage(content='Explain large language models briefly.', role='user')\n    ],\n    max_tokens=150,\n    temperature=0.7\n)\nprint(response.choices[0].message.content)","lang":"python","description":"Minimal AI21 Jamba chat completion using ai21 SDK 4.x."},"warnings":[{"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.","message":"Two ChatMessage classes exist: ai21.models.chat.ChatMessage (Jamba, uses content=) and ai21.models.ChatMessage (J2/legacy, uses text= and RoleType). Mixing them causes TypeError.","severity":"breaking","affected_versions":">= 2.0"},{"fix":"For Jamba: client.chat.completions.create(messages=[...]). For J2: client.chat.create(system=..., messages=[...]).","message":"Old 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.","severity":"breaking","affected_versions":">= 2.0"},{"fix":"Use Jamba models: 'jamba-large', 'jamba-mini'. Use content= not text=. Use string roles not RoleType enum.","message":"LLMs 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.","severity":"gotcha","affected_versions":"all"},{"fix":"export AI21_API_KEY=your_key or pass api_key= to AI21Client().","message":"API key env var is AI21_API_KEY. SDK reads it automatically if not passed explicitly to AI21Client().","severity":"gotcha","affected_versions":"all"},{"fix":"Migrate to jamba-large or jamba-mini for new projects.","message":"J2 Jurassic models (j2-ultra, j2-mid, j2-light) are legacy. Jamba is the current model family. New features only on Jamba.","severity":"deprecated","affected_versions":"all"}],"env_vars":null,"search_vec":"'2026':29 '4.3.0':27 'access':12 'ai21':1,8,57 'api':10,34,40,44 'chat':16,38,62 'chat-complet':61 'chatmessag':47 'complet':17,24,39,63 'current':25,52 'differ':46 'distinct':33 'j2':21,53 'j2/jurassic':43 'jamba':14,37,49,58 'jurass':22 'lab':9 'legaci':20,42,56 'llm':59 'mar':28 'model':15,23,50,54 'modern':36 'offici':4 'provid':11 'python':2,5,60 'sdk':3,6,30 'signatur':48 'stream':18 'surfac':35 'two':32 'version':26","created_at":"2026-03-24T04:12:05.060548+00:00","updated_at":"2026-04-15T19:22:14.215237+00:00","problems":null,"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":0,"quickstart_tag":"stale","pypi_latest":"4.3.0","cli_name":"","cli_version":null,"type":"library","homepage":"https://www.ai21.com","github":null,"docs":null,"changelog":null,"pypi":"https://pypi.org/project/ai21/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["llm-agents","ai-ml","http-networking"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-30","last_verified":"2026-06-30","next_check":"2026-07-30","install_tag":"verified"}}