AI21

Use AI21 Studio models with PraisonAI Agents

Point an Agent at AI21 Studio by setting your credentials and naming the model.

Diagram

AI21 Studio with PraisonAI

📝 Agent

🔧 litellm

🌐 AI21 API

✅ Response

Quick Start

  1. Install
    bash
    pip install "praisonaiagents[llm]"
  2. Set credentials
    bash
    export AI21_API_KEY=your-ai21-key
  3. Run an agent
    python
    from praisonaiagents import Agent
    
    agent = Agent(
        instructions="You are a helpful assistant",
        model="ai21/j2-ultra",
    )
    
    agent.start("Hello!")

How it works

The ai21/ prefix tells PraisonAI to route the request through litellm to AI21 Studio, which reads AI21_API_KEY from your environment. See Provider Auto-Detection for how model strings are resolved.

Diagram
AI21 APIlitellmAgentUserAI21 APIlitellmAgentUseragent.start(“Hello!”)model=”ai21/…”Request with your credentialsModel replyResponse

Common Patterns

Pick a different model

Keep the ai21/ prefix and swap the rest for any model your AI21 Studio account offers.

python
from praisonaiagents import Agent

agent = Agent(
    instructions="You are a helpful assistant",
    model="ai21/j2-ultra",
)

Tune the response with a config dict

Pass a dict to set temperature, token limits, or other options.

python
from praisonaiagents import Agent

agent = Agent(
    instructions="You write short, friendly answers",
    model={
        "model": "ai21/j2-ultra",
        "temperature": 0.3,
        "max_tokens": 500,
    },
)

agent.start("Give me three tips for better sleep.")

Best Practices

Prefer the shortest form

Start with model="ai21/j2-ultra" and nothing else. Add a config dict only when you need to tune temperature or limits.

Set the provider key once via env

Export AI21_API_KEY in your shell or .env file. Keep keys out of your code.

Keep model= canonical

Always use model=. The older llm= name still works but prints a deprecation warning. See Model Parameter.

Related