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.

Get a key from the class LLM gateway

  1. Click the badge. Click Sign in with GitHub. Use the same account you used for your fork.
  2. Click Get my key.
  3. 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.

Warning

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.

  1. Open github.com/settings/codespaces.
  2. Under Secrets, click New secret.
  3. Name: LITELLM_API_KEY. Type it exactly like that.
  4. Value: paste your key.
  5. Repository access: pick your fork of codespace.
  6. 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-6

If 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:

opencode

Type 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-collaboration
  • jupyter-server-mcp adds an MCP server to JupyterLab. MCP (Model Context Protocol) is how an agent reaches tools outside itself.
  • jupyter-ai-tools gives that server the tools: read a notebook, add a cell, run a cell.
  • jupyter-ai-acp-client adds a chat panel to JupyterLab that can talk to opencode.
  • jupyter-collaboration lets 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
    }
  }
}
JSON

opencode 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.
MD

Both 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 shell
jupyter lab --ip=0.0.0.0 --port=8888 --no-browser --IdentityProvider.token='' --ServerApp.password='' --config=jupyter_config.py

Open 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.

The Ports tab in VS Code. The row for port 8888 is highlighted and the globe icon shows a tooltip that says Open in Browser.

Hover over the 8888 row and click the globe.

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:

opencode

Ask 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:

  1. Click the Source Control icon on the left bar.
  2. Stage these files by clicking the + next to each one:
    • opencode.json
    • AGENTS.md
    • pixi.toml
    • pixi.lock
    • any notebooks you made in notebooks/
  3. Type a message like add opencode and jupyter mcp setup.
  4. 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.