> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ai21.com/llms.txt
> Use this file to discover all available pages before exploring further.

# SDK

> AI21 offers Python and TypeScript libraries that simplify the process of using our LLMs' API.

## Get an API key

Before you can start using the SDK, you'll need to obtain your API key from [AI21 Studio](https://studio.ai21.com/v2?tab=maestro).\
See the full guide here: [**Create an API Key**](https://docs.ai21.com/docs/create-api-key)**.**

### Installation

Install ai21 Python SDK with your favorite package manager.

<CodeGroup>
  ```shell Shell theme={"system"}
  pip install ai21
  ```
</CodeGroup>

### Authentication

There are two ways to authenticate with the SDK:\
\
**Option 1: Pass the API key directly**

```python theme={"system"}
from ai21 import AI21Client

client = AI21Client(api_key="your_api_key")
```

**Option 2: Use an environment variabl**e

Set the variable in your terminal:

```shellscript theme={"system"}
export AI21_API_KEY="your_api_key"
```

Then in your Python code, you can initialize the client without explicitly passing the key:

```python theme={"system"}
client = AI21Client()
```

<Note>
  For details on how authentication works at the HTTP level, see the [API Refrence Autentication](https://docs.ai21.com/reference/authentication).
</Note>

### Example usage

This example demonstrates how to initialize the AI21 Python SDK client and send a simple chat message using the `jamba-mini` model.

```python theme={"system"}
from ai21 import AI21Client
from ai21.models.chat import ChatMessage

client = AI21Client(
    # defaults to os.environ.get('AI21_API_KEY')
    api_key='your_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",
)
print(chat_completions.choices[0].message.content)
```

## Python SDK

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

<CardGroup cols={2}>
  <Card title="Python library GitHub repository" icon="github" iconType="solid" horizontal href="https://github.com/AI21Labs/ai21-python" />
</CardGroup>
