Set Up OpenCode with the RC LLM API
Level: Beginner · Time: 15–20 min · Category: How-to
Tags: OpenCode · AI coding assistant · Custom Provider
OpenCode is a free AI coding assistant. You describe what you want in plain English, and it reads your project, writes and edits files, and runs commands for you. This guide connects OpenCode to the Research Computing LLM gateway so it uses your RC API key and the models available to your account.
This page assumes no prior setup. If a step already applies to you, skip it.
Getting Started with AI covers this setup plus everything around it — choosing a tool, the Voyager config generator, agents, the RC skills library, and the prompting habits that make locally hosted models work well. This page is the detailed OpenCode reference.
New to this? What is an "AI coding assistant"?
An AI coding assistant is a program that talks to a large language model (LLM) and can act on your project — creating files, editing code, and running commands — based on instructions you type in plain language. OpenCode is one such assistant. It does not include a model of its own; you point it at a model provider. Here, that provider is the Research Computing LLM gateway.
What you will do
- Get your RC API key and a model ID from the portal.
- Install OpenCode.
- Store your API key as an environment variable so it stays out of your files.
- Add the RC gateway as a provider so OpenCode knows the endpoint and models.
- Open OpenCode (desktop app or terminal), select an RC model, and send a test message.
1. Get your API key and a model ID
OpenCode needs two values from the portal before anything else.
- Follow the LLM API Guide to create an API key.
- On the same page, open the model list and copy one model ID available to your account
(for example
muse-glimmer-30b). You will use it in the provider config below. Choose one with the Tools badge — without tool calling, OpenCode cannot edit files.
Keep the key somewhere safe for the next step. Treat it like a password — never paste it into shared files, screenshots, or Git.
2. Install OpenCode
Pick your operating system. The curl and package-manager installers below do not require
Node.js.
- macOS / Linux
- Windows
The one-line installer works on both:
curl -fsSL https://opencode.ai/install | bash
Or, if you use a package manager:
# macOS (Homebrew)
brew install anomalyco/tap/opencode
# Arch Linux
sudo pacman -S opencode
Windows has two routes to PowerShell in the start menu: Terminal and PowerShell. Opening Terminal will usually open PowerShell in your user files, while opening PowerShell will open it in system files.
Windows also has package managers, and we specifically note Scoop and Chocolatey as options. these enable installation of software through PowerShell. Either will work, though Scoop is easier to install.
Once you have either installed, continue in powershell:
# Scoop
scoop install opencode
# or Chocolatey
choco install opencode
Confirm it installed. This should print a version number:
opencode --version
Fully quit and reopen your terminal so it picks up the newly installed command, then run
opencode --version again. Prefer to install with npm instead? Run
npm install -g opencode-ai — but that route needs Node.js, so set up
Node.js first.
3. Understand the two pieces you are about to set up
Connecting OpenCode to RC takes two pieces that work together — not one or the other:
- A provider config — a small JSON file that tells OpenCode where the RC gateway is
(
https://openai.rc.asu.edu/v1) and which models exist. Without it, OpenCode has no idea RC exists. - Your API key — the secret that proves the request is yours. The config file references the key from an environment variable so your secret never sits inside the file itself.
You need both. The next two steps set up one each.
4. Store your API key as an environment variable
An environment variable is a named value your shell hands to every program it launches. Storing the key here keeps it out of your project files.
- macOS / Linux
- Windows (PowerShell)
Open your shell's startup file in a text editor so it is set every time you open a terminal — use
~/.zshrc on macOS (the default shell is zsh) or ~/.bashrc on most Linux systems:
nano ~/.zshrc # macOS; use ~/.bashrc on most Linux systems
Add this line at the bottom, pasting your key between the quotes, then save and exit (Ctrl+O, Enter, Ctrl+X in nano):
export OPENAI_API_KEY="paste-your-key-here"
Editing the file, rather than echoing the line into it, keeps the key out of your shell history.
Now source the file. Sourcing re-reads it into your current terminal, so you do not have to close and reopen it:
source ~/.zshrc
What does "source" mean, and why do I need it?
Your shell only reads ~/.zshrc (or ~/.bashrc) once, when a
terminal first opens. Editing the file afterward does not change terminals that are already
open. source ~/.zshrc re-runs the file in your current terminal so the new
export takes effect immediately. New terminals you open later pick it up
automatically.
Confirm it is set (this should print your key):
echo $OPENAI_API_KEY
This prompts you to paste the key, then stores it permanently for your user account. Using a prompt rather than typing the key into the command keeps it out of your PowerShell history:
[Environment]::SetEnvironmentVariable("OPENAI_API_KEY", (Read-Host "Paste your key"), "User")
Then close and reopen PowerShell — the value only reaches terminals opened after it is set. Confirm it is set (this should print your key):
echo $env:OPENAI_API_KEY
Because the key lives in an environment variable, it never needs to appear in your project. Do not paste it into code, commit it, or share a screenshot that shows it.
Bear in mind that anything you type at a prompt is written to your shell history in plain text —
~/.zsh_history, ~/.bash_history, or PowerShell's
ConsoleHost_history.txt. Keep the key out of commands as well as files. If it ends
up somewhere it should not, regenerate it in the portal; rotating a key invalidates the exposed
one.
5. Add the RC gateway as a provider
OpenCode reads its settings from ~/.config/opencode/opencode.json (macOS/Linux) or
%USERPROFILE%\.config\opencode\opencode.json (Windows). This is the global config, so RC is
available in every project.
The Voyager portal → LLM Access → opencode tab builds this file for you, with the endpoint and your real model list already filled in — plus agent roles and tool permissions. Choose Environment variable for the API key so your secret stays out of the file, then copy or download it to the path above. The walkthrough is in Getting Started with AI. The manual version below is here so you understand what the generator produces.
To write it by hand, paste the following and replace the model IDs with real ones from your Voyager model list:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"asu": {
"npm": "@ai-sdk/openai-compatible",
"name": "ASU Air",
"options": {
"baseURL": "https://openai.rc.asu.edu/v1",
"apiKey": "{env:OPENAI_API_KEY}"
},
"models": {
"muse-glimmer-30b": { "name": "muse-glimmer-30b" },
"devstral2-123b": { "name": "devstral2-123b" }
}
}
},
"model": "asu/muse-glimmer-30b"
}
What each part does:
provider.asu— the short ID for this provider. Agents and themodelfield reference models asasu/model-id, so if you change this key you must change those references too. The Voyager generator usesasu.name— the display label in the model picker. The generator uses "ASU Air".npm: "@ai-sdk/openai-compatible"— the adapter for any OpenAI-compatible gateway like RC. Leave this exactly as shown.options.baseURL— the RC gateway endpoint. Already correct; do not change it.options.apiKey: "{env:OPENAI_API_KEY}"— reads the key from the environment variable you set in step 4. The{env:...}syntax keeps the secret out of this file.models— the model IDs your key can use. Each key must match a model ID from the portal exactly; thenameis just a friendly label. Add or remove entries to match your account. Pick at least one with the Tools badge, or OpenCode will not be able to edit files.model— the default model, written asprovider-id/model-id. Optional, but it saves you from picking one every time.
If the ~/.config/opencode/ folder does not exist yet, create it first:
mkdir -p ~/.config/opencode (macOS/Linux). Then create
opencode.json inside it with the content above.
6. Open OpenCode and select an RC model
OpenCode has two interfaces that use the same config and key you just set up. Use whichever you prefer — they are fully equivalent for this tutorial.
- Desktop app (visual)
- Terminal (TUI)
The desktop app is the most approachable if you are new to the terminal.
- Install the OpenCode desktop app from opencode.ai and open it.
- Click
Default Projectto open the projects menu and make a new one instead, at the directory of your choosing. - Open the model picker and choose a model under ASU Air. Make sure you pick one with the Tools badge, or OpenCode will not be able to edit files.
- Type a message in the chat box and send it (see step 7).
The app reads the same ~/.config/opencode/opencode.json from step 5 — make sure you
saved it, then fully quit and reopen the app so it reloads the config. If a model returns an
authentication error, the app may not see your shell's environment variable; in that case run
opencode auth login once in a terminal, choose the ASU Air
provider, and paste your key. That stores the key in OpenCode's own auth
store, which both interfaces can use.
The terminal interface (a "TUI", or text user interface) runs entirely in your terminal.
-
Move into a project folder (any folder works for a first test):
mkdir opencode-test
cd opencode-test -
Start OpenCode:
opencode -
Open the model list with the
/modelscommand (type it and press Enter), then choose a model under ASU Air. If you set themodeldefault in step 5, it is already selected. -
Type a message at the prompt and press Enter (see step 7).
Quit OpenCode (press Esc then type /exit) and restart it so it reloads
opencode.json. Confirm your key is set with echo $OPENAI_API_KEY — if
it prints nothing, redo step 4 and remember to source your shell file.
7. Send a test message
With an RC model selected, send a harmless prompt to confirm the whole chain works:
Reply with exactly: OpenCode is connected to ASU Air.
A normal reply — with no authentication, provider, or model-not-found error — means OpenCode is talking to the RC gateway with your key. You are ready to build.
A good next prompt, once connected:
Look at the files in this folder and summarize what this project does. Do not edit anything yet.
Troubleshooting
opencode: command not found— quit and reopen your terminal after installing. If you installed vianpm, confirm Node.js is set up (node --version).- Authentication failed / 401 — your key is wrong, expired, or not visible to OpenCode. Confirm
echo $OPENAI_API_KEY(macOS/Linux) orecho $env:OPENAI_API_KEY(Windows) prints your key, then restart OpenCode. In the desktop app, useopencode auth loginas described in step 6. - No RC provider or models in the picker — the config was not loaded. Re-check the path and JSON in step 5, then fully restart OpenCode (config changes need a restart).
- Model not found — a model ID in
opencode.jsondoes not match the portal. Copy the exact ID from the model list and update themodelsblock. - Key works in
curlbut not OpenCode — the environment variable is not set in the session that launched OpenCode. Re-run step 4,sourceyour shell file, and start OpenCode from that same terminal. For the desktop app, preferopencode auth login.
Related guides
- LLM API Guide — create a key, find model IDs, and test the endpoint directly.
- Connect VS Code to the RC API — prefer VS Code Chat? Use BYOK instead.
- Create a Basic Lab Web Portal — put OpenCode to work on a real beginner project.