Use 3llama in OpenCode
OpenCode is an open-source AI coding agent that you can use as a desktop app or in your terminal. Connect it to 3llama, and it can read, write, and explain code with the models in your plan, drawing on the same allowance as your chats.
- About 5 minutes
- macOS, Windows, and Linux
- Needs API access
Set it up with one command
On macOS, Linux, or WSL, paste this command into a terminal. It connects both the OpenCode desktop app and the terminal app to 3llama, and asks for your API token along the way.
curl -fsSL https://3llama.com/opencode.sh | bashHere's what it does:
- Checks your token, and that your plan includes API access
- Adds only the models in your plan, by name, with their limits
- Saves your token in a private file only you can read, so the desktop app can use it too
- Backs up your OpenCode settings before changing them
- Offers to install OpenCode if it isn't installed yet
Your token stays hidden as you paste it, and it's sent only to 3llama. As with any command you paste into a terminal, you can read the script before you run it.
When it's done, quit and reopen OpenCode, then choose a 3llama model. Run the command again whenever your plan changes to update your models.
Set it up step by step
Prefer to see every change, or using the desktop app on Windows? Follow these steps instead.
Step 1
Create an API token
On the API tokens page, give your token a name you'll recognize, such as the computer you'll use it on, and select Create token.
Open API tokensCopy your token as soon as it appears. It's shown only once to keep it secure. If you lose it, revoke it and create a new one.
Step 2
Install OpenCode
OpenCode comes as a desktop app and as a terminal app, and both work with 3llama. Choose the one you'll use, and the rest of this guide follows your choice.
Download the desktop app for your computer, open the file, and follow the installer's steps.
- macOS
- Windows
- Linux
On a Mac with Homebrew, you can install it from the terminal instead:
Homebrew brew install --cask opencode-desktopInstall OpenCode 2 with any of these methods. If OpenCode is already installed, run
opencode --versionto see which version you have.curl curl -fsSL https://opencode.ai/v2/install | bashHomebrew brew install anomalyco/tap/opencode-v2npm npm install -g @opencode/cliOn Windows, run these commands in WSL, because Windows package managers aren't supported.
Step 3
Give OpenCode your token
Apps you open from the Dock, Start menu, or app launcher don't see variables set in a terminal, so save your token in a private file instead. OpenCode reads it from there each time it starts. Replace the placeholder with your token, then run the commands for your system.
macOS, Linux mkdir -p ~/.config/3llama printf '%s' 'paste-your-token-here' > ~/.config/3llama/api-key chmod 600 ~/.config/3llama/api-keyWindows PowerShell New-Item -ItemType Directory -Force "$HOME\.config\3llama" | Out-Null Set-Content -NoNewline -Path "$HOME\.config\3llama\api-key" -Value 'paste-your-token-here'This file stores your token as plain text. Keep it private, and never share it or add it to version control.
OpenCode reads your token from the
THREELLAMA_API_KEYenvironment variable, so it never has to be saved in a configuration file. Run this in the terminal where you'll start OpenCode, replacing the placeholder with your token.shell export THREELLAMA_API_KEY="paste-your-token-here"This applies only to the current terminal. To set it in every new terminal, add the same line to your shell profile, such as
~/.zshrcor~/.bashrc.Step 4
Add 3llama as a provider
Open
~/.config/opencode/opencode.json, where OpenCode keeps the settings for all of your projects. On Windows,~is your user folder, such asC:\Users\you. Create the file if it doesn't exist, then add the 3llama provider below, or merge it into the settings you already have.This configuration reads your token from
~/.config/3llama/api-keyand lists every model on 3llama, with its limits. Your plan may not include all of them. On macOS and Linux, the one-command setup at the top of this page adds only your plan's models.Loading 3llama's models…OpenCode reads
opencode.jsonfrom your project folder, and settings for all of your projects from~/.config/opencode/opencode.json. Add the 3llama provider to either file, or merge it into the configuration you already have.The configuration below lists every model on 3llama, with its limits. Your plan may not include all of them, so to copy one that lists only your plan's models, choose your OpenCode version on the API tokens page.
Get your plan's configurationLoading 3llama's models…This example is for OpenCode 2. OpenCode 1 uses a different format, which you can also copy from the API tokens page.
Step 5
Start OpenCode and choose a model
Open OpenCode. If it was already open, quit it completely and open it again, so it picks up your new settings.
Open your project folder, then open the model list and choose one of the models under 3llama. You're ready to start coding.
In the same terminal, go to your project folder and start OpenCode:
shell opencode --standaloneThen type
/modelsand choose one of the models under 3llama. You're ready to start coding.--standalonestarts OpenCode with its own private server, which can read the token you just set. Without it, OpenCode may connect to a background server that started before you set the token.
Troubleshooting
Most problems come down to the token, the configuration file, or your plan. Start with the one that matches what you see.
3llama doesn't appear in the desktop app
OpenCode reads its settings when it starts, so quit it completely and open it again. If 3llama still doesn't appear, check that ~/.config/opencode/opencode.json is valid JSON and includes the 3llama provider, and that ~/.config/3llama/api-key holds your full token and nothing else.
3llama doesn't appear in /models
Check that the configuration is in opencode.json in the folder where you started OpenCode, or in ~/.config/opencode/opencode.json, and that the file is valid JSON. Then make sure you copied the configuration for your OpenCode version.
OpenCode says my token is missing or invalid
If you used the one-command setup or the desktop app steps, check that ~/.config/3llama/api-key holds your full token and nothing else. If you set the token in the terminal, run echo $THREELLAMA_API_KEY in the same terminal to check it, then start OpenCode again with opencode --standalone. If you revoked the token, create a new one and save it again.
How do I undo the one-command setup?
Run curl -fsSL https://3llama.com/opencode.sh | bash -s -- --uninstall. It removes 3llama from OpenCode and deletes the saved token, keeping a backup of your settings. To stop the token from working anywhere, revoke it on the API tokens page.
A request fails because the model isn't included in my plan
Your plan decides which models you can use through the API, and the guides list every model on 3llama. Copy the configuration from the API tokens page instead, so it lists only the models in your current plan.
Requests stopped working before the end of the month
Requests from your tools draw on the same allowance as your chats. When you've used all of it, requests pause until your allowance resets. You can check your usage in the app, or upgrade your plan for more.
Can I use one token on several computers?
You can, but a separate token for each computer is safer. If one is lost, you can revoke just that token and the others keep working.
