AI Pairing
In this unit you pair with an AI coding agent inside your Codespace. The agent is opencode. It runs in your terminal. With one extra piece, it can read and run cells in your JupyterLab notebooks.
You need your fork of the class repo and the pixi environment from the Codespaces unit.
1. Get your key
The agent needs a key to talk to the class LLM gateway. Your key is tied to your GitHub account.
- Click the badge. Click Sign in with GitHub. Use the same account you used for your fork.
- Click Get my key.
- Click Copy. The key is shown once. Paste it somewhere safe for the next step.
If you lose the key, go back and click Make a new key. That turns off the old one.
Never paste the key into a notebook. Never commit it to GitHub.
If the page says you are not on the class roster, tell the instructor your GitHub username.
2. Give the key to your Codespace
The Codespace reads the key from a secret. A secret is a value GitHub stores for you and puts into your Codespace as an environment variable.
- Open github.com/settings/codespaces.
- Under Secrets, click New secret.
- Name:
LITELLM_API_KEY. Type it exactly like that. - Value: paste your key.
- Repository access: pick your fork of
codespace. - Click Add secret.
Now go to your Codespace tab. GitHub shows a message that secrets changed and offers to reload. Click Reload. If you do not see it, stop the Codespace and start it again from github.com/codespaces.
Check that the key arrived. This prints only the first six characters:
echo $LITELLM_API_KEY | cut -c1-6If it prints a blank line, the secret did not reach the Codespace. Check the name and the repository access, then restart the Codespace.
3. Try opencode
opencode is already installed. It is already set up to use the class gateway and the deepseek-v4-pro model. Run it in the terminal:
opencodeType a question, like “What files are in this project?”, and press Enter. Press Ctrl+C twice to quit.
If it says the key is missing or you get an authentication error, go back to step 2.
4. Install the Jupyter AI packages
These go into your pixi environment, next to JupyterLab:
pixi add jupyter-server-mcp jupyter-ai-tools jupyter-ai-acp-client jupyter-collaborationjupyter-server-mcpadds an MCP server to JupyterLab. MCP (Model Context Protocol) is how an agent reaches tools outside itself.jupyter-ai-toolsgives that server the tools: read a notebook, add a cell, run a cell.jupyter-ai-acp-clientadds a chat panel to JupyterLab that can talk to opencode.jupyter-collaborationlets the agent and you edit the same notebook at the same time.
If pixi add fails on one name, add the others and tell the instructor.
5. Tell opencode about Jupyter
opencode reads a file named opencode.json at the top of the project. Make it with this one command:
cat > opencode.json <<'JSON'
{
"mcp": {
"jupyter-mcp": {
"type": "remote",
"url": "http://localhost:3001/mcp",
"enabled": true
}
}
}
JSONopencode also reads a file named AGENTS.md for house rules. Make it too:
cat > AGENTS.md <<'MD'
- Use the jupyter-mcp tools to read and run notebook cells.
- Use pixi to manage Python and R packages.
MDBoth files are safe to commit. They do not contain your key.
6. Start JupyterLab with the MCP server on
The repo has a file named jupyter_config.py. It turns on the MCP server on port 3001 and lists the notebook tools. Start JupyterLab with it:
pixi shelljupyter lab --ip=0.0.0.0 --port=8888 --no-browser --IdentityProvider.token='' --ServerApp.password='' --config=jupyter_config.pyOpen JupyterLab the same way as before. Click the Ports tab, find the 8888 row, and click the globe icon. Do not use the Open in Browser popup.

7. Pair with the agent
There are two ways. Start with the terminal.
From the terminal. JupyterLab is using your first terminal, so open a second one. Click the + next to the terminal tab. Then run:
opencodeAsk it to make a notebook in the notebooks folder and add a cell that prints hello. Then look at your JupyterLab tab. The notebook appears and the cell runs.
From JupyterLab. Click the chat icon in the left sidebar. Type @OpenCode and then your question. The agent answers in the chat and can edit your notebooks the same way.
8. Commit and push
Save your setup to your fork so it is there next time. Go to the VS Code tab:
- Click the Source Control icon on the left bar.
- Stage these files by clicking the + next to each one:
opencode.jsonAGENTS.mdpixi.tomlpixi.lock- any notebooks you made in
notebooks/
- Type a message like
add opencode and jupyter mcp setup. - Click Commit, then Sync Changes.
Your key is not in any of these files. It lives only in the GitHub secret.
Things to know
- Budget. Each key has a $5 budget and a limit of 30 requests per minute. That is plenty for class. Ask short, clear questions.
- Stop your Codespace when you are done to save your free hours.
