---
sidebar_label: AI21 Labs
description: "Deploy AI21 Labs' Jamba models for enterprise text generation with task-specific optimization and control"
---

# AI21 Labs

Use the [AI21 Labs API](https://docs.ai21.com/reference) to call Jamba models such as `jamba-mini` and `jamba-large`.

## API Key

To use AI21 Labs, you need to set the `AI21_API_KEY` environment variable, or specify the `apiKey` in the provider configuration.

Example of setting the environment variable:

```sh
export AI21_API_KEY=your_api_key_here
```

## Model Selection

You can specify which AI21 model to use in your configuration. The public aliases are:

1. `jamba-mini`
2. `jamba-large`

The provider also recognizes the versioned IDs `jamba-mini-2`, `jamba-mini-2-2026-01`,
`jamba-large-1.7`, and `jamba-large-1.7-2025-07`.

To compare the two models:

```yaml
providers:
  - ai21:jamba-mini
  - ai21:jamba-large
```

## Options

The provider accepts these options:

- `temperature`: Controls the randomness of the output.
- `top_p`: Controls nucleus sampling, affecting the randomness of the output.
- `max_tokens`: The maximum length of the generated text.
- `response_format`: Set to `{ type: 'json_object' }` for JSON output or `{ type: 'text' }` for text output.
- `apiKeyEnvar`: An environment variable that contains the API key.
- `apiBaseUrl`: The base URL of the AI21 API.

## Example Configuration

```yaml
providers:
  - id: ai21:jamba-mini
    config:
      apiKey: your_api_key_here
      temperature: 0.1
      top_p: 1
      max_tokens: 1024
      response_format: { type: 'json_object' }
```

## Cost

Promptfoo estimates cost using separate input and output rates. Check [AI21's pricing](https://www.ai21.com/pricing) and set your own rates if needed:

```yaml
providers:
  - id: ai21:jamba-large
    config:
      inputCost: 0.000002 # Example: $2 per million input tokens
      outputCost: 0.000008 # Example: $8 per million output tokens
```

`inputCost` and `outputCost` are in USD per token. Use `cost` to apply the same rate to both.

## Supported environment variables

These AI21-related environment variables are supported:

| Variable            | Description                                                        |
| ------------------- | ------------------------------------------------------------------ |
| `AI21_API_BASE_URL` | The base URL (protocol + hostname + port) to use for the AI21 API. |
| `AI21_API_KEY`      | AI21 API key.                                                      |
