Integration guide

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
Fastest way

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.

Terminal
curl -fsSL https://3llama.com/opencode.sh | bash

Here'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.

Read the script

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.

  1. 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 tokens

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

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

    All downloads

    On a Mac with Homebrew, you can install it from the terminal instead:

    Homebrew
    brew install --cask opencode-desktop
  3. 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-key
    Windows 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.

  4. 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 as C:\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-key and 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…
  5. 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.

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.

Keep going