Pi Agent: Installation & Authentication

Last updated: 2026-08-31

Sharp tools make good work. This lesson gets your Pi Agent development environment up and running in 5 minutes.


1. Requirements

Item Minimum Recommended
Python 3.9+ 3.11+
pip Latest Latest
OS Windows / macOS / Linux Any
RAM 512MB free 2GB+
Disk 200MB 1GB+

Verify Python version:

BASH
python --version
# Python 3.11.8

2. Installing Pi Agent

BASH
pip install pi-agent

(2) Install from Source

BASH
git clone https://github.com/pi-agent/pi-agent.git
cd pi-agent
pip install -e .

(3) Verify Installation

BASH
pi-agent --version
# Pi Agent v0.8.0

(4) Optional Dependencies

BASH
pip install pi-agent[all]          # Install all optional deps
pip install pi-agent[deepseek]     # DeepSeek support
pip install pi-agent[local]        # Local model support (llama.cpp)
pip install pi-agent[tools]        # Extended tool set

3. Authentication & Model Configuration

Pi Agent supports multiple LLM providers. You need to configure API keys before use.

BASH
# DeepSeek
export PI_DEEPSEEK_API_KEY="sk-xxxxxxxx"

# OpenAI
export PI_OPENAI_API_KEY="sk-xxxxxxxx"

# Anthropic
export PI_ANTHROPIC_API_KEY="sk-ant-xxxxxxxx"

Windows PowerShell:

POWERSHELL
$env:PI_DEEPSEEK_API_KEY = "sk-xxxxxxxx"

(2) Configuration File

Create ~/.pi-agent/config.yaml:

YAML
providers:
  deepseek:
    api_key: "sk-xxxxxxxx"
    base_url: "https://api.deepseek.com"
    model: "deepseek-chat"

  openai:
    api_key: "sk-xxxxxxxx"
    model: "gpt-4o"

  anthropic:
    api_key: "sk-ant-xxxxxxxx"
    model: "claude-sonnet-4-20250514"

default_provider: deepseek

(3) In-Code Configuration

PYTHON
from pi_agent import Agent

agent = Agent(
    name="my_agent",
    provider="deepseek",
    api_key="sk-xxxxxxxx",
    model="deepseek-chat"
)

4. Model Providers Overview

Provider Model Example Strengths Price
DeepSeek deepseek-chat High cost-effectiveness, excellent Chinese Low
OpenAI gpt-4o Strong overall capability Medium-High
Anthropic claude-sonnet-4-20250514 Long text, strong code Medium
Local models llama.cpp Privacy, offline Free
Ollama llama3, mistral Easy local deployment Free

Example 1: Multi-Provider Switching (Difficulty: ⭐)

PYTHON
from pi_agent import Agent

deepseek_agent = Agent(provider="deepseek", model="deepseek-chat")
openai_agent = Agent(provider="openai", model="gpt-4o")

result_d = deepseek_agent.chat("Explain quantum computing in one sentence")
result_o = openai_agent.chat("Explain quantum computing in one sentence")

print(f"DeepSeek: {result_d}")
print(f"OpenAI: {result_o}")

5. First Launch Test

After installation and configuration, run a quick test:

BASH
pi-agent chat "Hello, Pi Agent!"

Expected output:

TEXT 📖 Display only
Pi Agent v0.8.0
Provider: deepseek (deepseek-chat)
Hello! I'm Pi Agent, how can I help you?

Alice completed her setup in 3 minutes following these steps. Bob says: "Pi Agent's installation is simpler than most Python tools — install, configure a key, and you're good."


FAQ

Q pip install fails?
A Upgrade pip first (pip install --upgrade pip). If it's a network issue, use a mirror: pip install pi-agent -i https://pypi.tuna.tsinghua.edu.cn/simple.
Q API key configured but not working?
A Check the environment variable name (must have PI_ prefix), and the config file path (~/.pi-agent/config.yaml). In-code config has highest priority.
Q Can I use Pi Agent without an API key?
A Yes. Install pi-agent[local] and use llama.cpp or Ollama to run local models without any API key. See Lesson 18.

Summary


Exercises

  1. Basic (Difficulty: ⭐): Install Pi Agent and verify with pi-agent --version.
  2. Intermediate (Difficulty: ⭐⭐): Configure at least two LLM providers, create Agent instances for each, and verify connectivity.
  3. Advanced (Difficulty: ⭐⭐⭐): Write a script that auto-detects available API keys and lists currently available providers.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏