Body
Summary
Learn how to configure Pi to connect to USNH DeepThought. This article includes installation, API configuration, and setup instructions for integrating the Pi terminal-based AI coding agent with DeepThought, enabling secure AI-assisted code analysis, documentation generation, code explanation, and code editing within the USNH environment.
Capabilities
- Analyze and modify code from the command line.
- Generate documentation and explain code.
- Keep AI requests within the USNH DeepThought environment.
How-To
Task: Configure Pi to connect to USNH DeepThought using a DeepThought API key.
Prerequisites
- DeepThought API Key
- Pi installed
- Terminal access (macOS/Linux) or PowerShell/Git Bash (Windows)
- Git Bash, WSL, MSYS2, or Cygwin (Windows)
Step 1 - Install Pi
Verify Installation
pi --version
Step 2 -Get a DeepThought API Key
If you do not already have a DeepThought API key, create one from the DeepThought Integrations page. You can optionally add the API key to your shell profile (~/.zshenv or ~/.bash_profile, depending on your shell).
export DEEPTHOUGHT_API_KEY=your-key-here
Reload your shell so the environment variable takes effect.
source ~/.bash_profile
Windows
Option A: Git Bash
If you're using Git Bash, add the export statement to your ~/.bashrc file and reload your shell.
echo 'export DEEPTHOUGHT_API_KEY=your-key-here' >> ~/.bashrc
source ~/.bashrc
Option B: PowerShell
If you're launching Pi from PowerShell, set the environment variable for the current session.
$env:DEEPTHOUGHT_API_KEY = "your-key-here"
To make the environment variable persistent across future sessions, run:
setx DEEPTHOUGHT_API_KEY "your-key-here"
Step 3 -Connect Pi to DeepThought
Create the following file:
~/.pi/agent/extensions/deepthought.ts
Paste the following exactly as written:
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
export default async function (pi: ExtensionAPI) {
const response = await fetch("https://dtcontroller.sr.unh.edu:4242/openai/v1/models", {
headers: { Authorization: `Bearer ${process.env.DEEPTHOUGHT_API_KEY}` }
});
const payload = await response.json() as { data: Array<{ id: string }> };
pi.registerProvider("deepthought", {
name: "DeepThought",
baseUrl: "https://dtcontroller.sr.unh.edu:4242/openai/v1",
apiKey: "$DEEPTHOUGHT_API_KEY",
api: "openai-completions",
models: payload.data.map((m) => ({
id: m.id,
name: m.id,
reasoning: false,
input: ["text"],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: 128000,
maxTokens: 4096,
})),
});
}
That completes the setup. You should not need to modify this file again.
Windows
On Windows, the path resolves to:
C:\Users\<you>\.pi\agent\extensions\deepthought.ts
From Git Bash, create the folder and open the file in Notepad:
mkdir -p ~/.pi/agent/extensions
notepad ~/.pi/agent/extensions/deepthought.tsTry It on a Real Codebase
Step 4- Try It on a Real Codebase
Navigate to the project folder you want Pi to work on, then launch Pi:
cd ~/path/to/your/project
pi
Windows
If you are running Pi from PowerShell instead of Git Bash, use a standard Windows path:
cd C:\path\to\your\project
pi
The first time Pi starts, switch to a DeepThought model using:
Ctrl+L
or:
/model
Then select a model such as:
ets:aws:us.anthropic.claude-sonnet-4-6
Example: Document a Codebase and Make a Change
Ask Pi to explain and document the codebase:
Look through this repository, give me a summary of what it does, how it's structured, and write a README.md documenting the main modules and how to run it.
Pi will review the files in the directory, build an understanding of the project structure, and create a README.md file directly in the folder.
Then ask Pi to make a change:
In the README you just wrote, add a "Known Issues" section. Also, find the function that handles file uploads and add error handling for files larger than 10MB.
Pi will locate the relevant function, show the proposed changes, and apply them directly to the file.
Other Things Worth Trying
Find every place in this codebase that calls the legacy auth API and list them.
Refactor the database connection logic into its own module and update all the imports that reference it.
Write unit tests for the functions in utils.py that don't have any test coverage yet.
A few tips
- Pi works directory by directory. Run
pi from inside the project you want it to work on.
- It will show you what it's doing (reading files, running commands, writing edits) as it goes, rather than just producing a final answer.
- If you want it to stop and not make a change, you can interrupt with
Escape before it finalizes an edit.
- On Windows, Pi still needs a working bash (Git Bash, Cygwin, MSYS2, or WSL) even if you launch
pi itself from PowerShell, since its file and shell tools run through bash. If it can't find one, install Git for Windows and restart your terminal.
- In Windows Terminal, use
Ctrl+Enter for multi-line input instead of Shift+Enter.
Need additional help?
If you have any additional questions, please fill out the Research Computing Center Request Form to reach RCC Support.