Skip to content

Install OpenCode in Terminal: macOS, Linux, Windows

Updated · TokenomixAI

Install OpenCode in terminal on macOS, Linux and Windows in two steps: the CLI from opencode.ai, then an API key through a base URL. This guide connects OpenCode to the TokenomixAI gateway with one command, then checks the config and the remaining token quota.

Install the OpenCode CLI from opencode.ai, then run the one-command installer so the tokenomixai provider and the TokenomixAI base URL land in opencode.json without touching your other providers.

What you need before you install OpenCode

OpenCode is a coding agent that runs in the terminal. Its CLI installation steps for each operating system live on opencode.ai, and this guide covers the part after that: connecting OpenCode to a model provider through a base URL, because without a provider the agent has nothing to send prompts to.

Prepare these items before you start.

  • A terminal on macOS or Linux, or PowerShell on Windows.
  • OpenCode already installed from opencode.ai.
  • A TokenomixAI API key in the format sk-tkx-..., sent after payment on the website.
  • A stable connection while the installer runs.

There is no account to create and no credit card required. You buy a package on the website, pay with QRIS or USDT, and the key arrives after payment. The same key works in OpenCode, Cursor, Cline, n8n or your own scripts. If you prefer OpenCode inside the editor, see Install OpenCode in VS Code.

How to install OpenCode in terminal on macOS and Linux

Open the terminal and follow the install command on opencode.ai for your distro or macOS version. Once the CLI runs, add the TokenomixAI provider with the command below.

bash <(curl -fsSL https://tokenomixai.com/install/opencode.sh)

The script asks for your API key, and the key is never put in a URL. It adds a provider named tokenomixai to the provider object in ~/.config/opencode/opencode.json, using the npm package @ai-sdk/openai-compatible with an options block for baseURL and apiKey.

Existing providers, MCP servers and plugins stay where they are. The script makes a backup of the config file before writing, so you can go back to the previous state at any time.

How to install OpenCode on Windows PowerShell

On Windows, use PowerShell. Install OpenCode from opencode.ai first, then run the TokenomixAI installer.

irm https://tokenomixai.com/install/opencode.ps1 | iex

irm stands for Invoke-RestMethod, which downloads the script, and iex for Invoke-Expression, which runs it. As on Unix, the script asks for the key separately and writes the config to opencode.json in your OpenCode config folder under the Windows home directory.

Don't paste the key into a URL or into a command argument that stays in your shell history. If you share a machine with other people, type the key only when the script prompts for it.

Add the API key and base URL by hand

If you skip the installer, for example because you keep every provider in one file, add the provider entry to opencode.json yourself. The key name is tokenomixai, the package is @ai-sdk/openai-compatible, options.baseURL is https://api.tokenomixai.com/v1, and options.apiKey is your sk-tkx-... key.

The base URL keeps the /v1 suffix because OpenCode calls the OpenAI-compatible chat completions endpoint. Claude Code is the exception: it adds the /v1/messages path itself, so its ANTHROPIC_BASE_URL is set to https://api.tokenomixai.com without /v1. The Claude Code setup page covers that side.

ToolBase URL to use
OpenCodehttps://api.tokenomixai.com/v1
OpenAI SDK script or curlhttps://api.tokenomixai.com/v1
Claude Codehttps://api.tokenomixai.com (no /v1)

Model IDs, context sizes and multipliers change over time and live only in the docs. In OpenCode you pick a model from that list instead of guessing an ID yourself.

Check the config and send a test prompt

Open ~/.config/opencode/opencode.json again and confirm that provider is an object, not an array, with one key named tokenomixai inside it. The wrong shape makes OpenCode ignore the provider even when the key itself is valid.

Start OpenCode, choose a model from the list, and send a small prompt such as asking for one simple function. If nothing comes back, check three things: the key is correct, the base URL ends in /v1, and tokens are still available on the quota.

The same key also works in Claude Code, Cursor, Cline, n8n and Python or curl scripts that use an OpenAI-compatible SDK, as long as the base URL is https://api.tokenomixai.com/v1. Only text and code models are available; some accept images as input, and there is no image, video or audio generation.

How to check token quota and the rate limit

You can check the remaining quota at any time with the quota endpoint and the same key.

curl https://api.tokenomixai.com/v1/quota -H "Authorization: Bearer sk-tkx-..."

The response contains status (active or exhausted), remainingTokens, maxTokens, usagePercent, expiresAt, and low, which is true when 10 percent or less remains. Those fields tell you whether the agent can still answer.

Quota is counted in tokens, not time windows, so the key keeps working while tokens remain and before it expires. There is a rate limit of 600 requests per minute per account, shared by every key on that account; above it the API returns 429 with a Retry-After header.

On a top-up, remaining tokens are added together and validity follows the latest top-up. The key stays the same, so you don't regenerate config for OpenCode.

Restore the OpenCode configuration

To remove the tokenomixai provider, run the installer with the restore flag. On macOS and Linux the command looks like this.

bash <(curl -fsSL https://tokenomixai.com/install/opencode.sh) --restore

On Windows, set the RESTORE environment variable first in the same command.

$env:RESTORE="1"; irm https://tokenomixai.com/install/opencode.ps1 | iex

Restore uses the backup made during installation, so other providers, MCP config and plugins return to their previous state. If you changed the file after installing, review the config before you rely on it again. Questions about keys and quota are answered on the FAQ page.

Frequently asked questions

Does OpenCode need a TokenomixAI API key?

No. OpenCode accepts any provider it supports, and TokenomixAI is one option: a single sk-tkx-... key for many text and code models through an OpenAI-compatible base URL. The model list lives on the docs page, so pick from there instead of hardcoding a name.

Should opencode.json use the base URL with or without /v1?

With /v1, so https://api.tokenomixai.com/v1, because OpenCode sends chat completion requests through an OpenAI-compatible SDK. Claude Code is the exception: its ANTHROPIC_BASE_URL is https://api.tokenomixai.com without /v1, since it appends the /v1/messages path itself.

Are my prompts and code stored?

The TokenomixAI gateway logs request metadata only: model, token count, time and status. Prompts and completions are not stored. That statement is about the gateway, not about the tools you run on your machine.

What happens when the token quota runs out?

The quota endpoint reports status exhausted and requests stop until you top up. Remaining tokens are added together on top-up, validity follows the latest top-up, and the key stays the same.

Do I need to reinstall OpenCode after a top-up?

No. Your key does not change after a top-up, so the existing tokenomixai entry in opencode.json keeps working. Rerun the installer only when you move to a new machine or want to rewrite the config.

More articles