Skip to main content

Provider-specific Swarmauri import package for AI21 Studio Jamba chat completions with sync, async, streaming, batch, and usage workflows.

Project description

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_llm_ai21 Discord

Swarmauri AI21 LLM

swarmauri_llm_ai21 provides the AI21StudioModel import path for Swarmauri applications that use AI21 Studio Jamba chat models. The package re-exports the maintained implementation from swarmauri_standard, giving projects a provider-specific dependency while preserving Swarmauri conversation, message, usage, streaming, and batch workflows.

Why Swarmauri AI21 LLM?

Use this package when you want to install only the AI21-facing LLM provider surface for a Swarmauri application. AI21StudioModel formats Swarmauri conversations for AI21 Studio chat completions, sends bearer-token authenticated HTTP requests, supports sync and async calls, streams token deltas, records usage data when available, and keeps model selection inside the Swarmauri LLMBase interface.

FAQ

Q: Which AI21 API does this adapter call?

A: The adapter posts to https://api.ai21.com/studio/v1/chat/completions, AI21 Studio's chat completions endpoint used by Jamba chat models.

Q: Which model names are configured?

A: The current allowed model list is jamba-large, jamba-mini, jamba-large-1.7, and jamba-mini-1.7. The default model name is jamba-large.

Q: Does this package contain a separate AI21 implementation?

A: No. It re-exports AI21StudioModel from swarmauri_standard.llms.AI21StudioModel so applications can depend on the provider package while using the shared implementation.

Q: What credential is required?

A: Pass an AI21 Studio API key with AI21StudioModel(api_key="..."). The repository tests look for AI21STUDIO_API_KEY when running live provider checks.

Features

  • Provider-specific import: from swarmauri_llm_ai21 import AI21StudioModel.
  • Swarmauri Conversation, HumanMessage, SystemMessage, and AgentMessage integration.
  • Sync predict() and async apredict() chat completion calls.
  • Sync stream() and async astream() token streaming.
  • Sync batch() and async abatch() helpers for multiple conversations.
  • Usage metadata mapping to Swarmauri UsageData when provider usage data is returned.
  • Retry handling for rate-limit and overloaded-provider status codes.
  • Python 3.10, 3.11, 3.12, 3.13, and 3.14 support.

Prerequisites

  • An AI21 Studio account and API key.
  • Network access to api.ai21.com.
  • Swarmauri conversations built from Swarmauri message classes.

Installation

Install with uv:

uv add swarmauri_llm_ai21

Install with pip:

pip install swarmauri_llm_ai21

Usage

Run a single chat completion:

import os

from swarmauri_llm_ai21 import AI21StudioModel
from swarmauri_standard.conversations.Conversation import Conversation
from swarmauri_standard.messages.HumanMessage import HumanMessage
from swarmauri_standard.messages.SystemMessage import SystemMessage

conversation = Conversation()
conversation.add_message(SystemMessage(content="Answer with concise technical prose."))
conversation.add_message(HumanMessage(content="What is a Swarmauri component?"))

model = AI21StudioModel(
    api_key=os.environ["AI21STUDIO_API_KEY"],
    name="jamba-mini",
)
result = model.predict(conversation=conversation, temperature=0.3, max_tokens=256)

print(result.get_last().content)

Stream a response:

import os

from swarmauri_llm_ai21 import AI21StudioModel
from swarmauri_standard.conversations.Conversation import Conversation
from swarmauri_standard.messages.HumanMessage import HumanMessage

conversation = Conversation()
conversation.add_message(HumanMessage(content="Write a short release note."))

model = AI21StudioModel(api_key=os.environ["AI21STUDIO_API_KEY"])

for token in model.stream(conversation=conversation, max_tokens=160):
    print(token, end="")

Use the async API:

import os
import asyncio

from swarmauri_llm_ai21 import AI21StudioModel
from swarmauri_standard.conversations.Conversation import Conversation
from swarmauri_standard.messages.HumanMessage import HumanMessage


async def main() -> None:
    conversation = Conversation()
    conversation.add_message(HumanMessage(content="Summarize AI21 Jamba in one line."))

    model = AI21StudioModel(api_key=os.environ["AI21STUDIO_API_KEY"])
    result = await model.apredict(conversation=conversation)

    print(result.get_last().content)


asyncio.run(main())

Related Packages

LLM provider packages:

Foundational packages:

Best Practices

  • Read the API key from environment variables or a secret manager.
  • Set name explicitly so deployments do not change behavior when defaults change.
  • Use async methods for high-concurrency applications.
  • Keep prompts and system messages in Swarmauri Conversation objects for provider portability.
  • Capture UsageData for cost and latency monitoring where provider responses include token usage.

License

Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

swarmauri_llm_ai21-0.11.0.dev1.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

swarmauri_llm_ai21-0.11.0.dev1-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file swarmauri_llm_ai21-0.11.0.dev1.tar.gz.

File metadata

  • Download URL: swarmauri_llm_ai21-0.11.0.dev1.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_llm_ai21-0.11.0.dev1.tar.gz
Algorithm Hash digest
SHA256 99dafb85343e9e7e433c21a0dbd5005cb6d6156545d0f0741578f1b0b804076b
MD5 eb3465766c7d07daadf7592f3cc164e8
BLAKE2b-256 7e5487beb150894569527920480ef257b5318cc673942d285da2eb51cea0fe15

See more details on using hashes here.

File details

Details for the file swarmauri_llm_ai21-0.11.0.dev1-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_llm_ai21-0.11.0.dev1-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_llm_ai21-0.11.0.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 ef2e7c1d616352cbda5e8f4ba1d3ba413779862692fad0d25415974400e10792
MD5 8313bbadd9e0847365a869009a357b3d
BLAKE2b-256 ca4609362ed9163aa0049babb095f550f12f5fbc9f59978022fbdc21b70477f4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page