Get an API key

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

Installation

Install ai21 Python SDK with your favorite package manager.
pip install ai21

Example usage

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

client = AI21Client(
    # defaults to os.environ.get('AI21_API_KEY')
    api_key='my_api_key',
)

system = "You're a support engineer in a SaaS company"
messages = [
    ChatMessage(content=system, role="system"),
    ChatMessage(content="Hello, I need help with a signup process.", role="user"),
]

chat_completions = client.chat.completions.create(
    messages=messages,
    model="jamba-mini",
)

Python SDK

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