Skip to content

How to Use OpenCode: First Session to Reading Diffs

Updated · TokenomixAI

How to use OpenCode comes down to three steps: open your project folder in a terminal, pick a model from a provider already in the config, then give one small task. When the agent stops, read the diff before you accept anything. This guide uses a TokenomixAI API key as the provider, and the same flow works for any provider you register yourself.

A clean first OpenCode session means one folder, one model, one small task, and a diff you read to the end before you commit.

What you need before your first OpenCode session

OpenCode is a coding agent that runs in the terminal and reads files inside the project folder you open. Before the first session you need three things in place: OpenCode installed, an API key in the sk-tkx- format from TokenomixAI, and a project folder without uncommitted noise.

If OpenCode is not installed yet, the one-command installer adds the tokenomixai provider to your config and asks for the API key without putting it in a URL. On macOS and Linux:

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

On Windows, run it from PowerShell:

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

The installer backs up the config first and keeps the other providers, MCP servers and plugins you already have. Full steps, including where the config file lives on Windows, are in Install OpenCode in Terminal: macOS, Linux, Windows.

  • A project folder with existing changes committed or stashed, so the diff shows only the agent's work.
  • One small task with a clear finish line, such as adding validation to a single function.
  • The model list from docs, so you copy a real name instead of guessing one.

How to use OpenCode: pick a model from your provider

OpenCode reads its provider list from opencode.json in the .config/opencode folder inside your home directory. The installer adds one entry named tokenomixai to the provider object, not to an array, using the npm package @ai-sdk/openai-compatible with two options: baseURL and apiKey. The shape looks roughly like this.

{
  "provider": {
    "tokenomixai": {
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "https://api.tokenomixai.com/v1",
        "apiKey": "sk-tkx-..."
      }
    }
  }
}

Model names and context sizes live only in the docs. Do not invent an ID; copy one from the list and match it to the job. Mechanical work such as renaming or reformatting usually runs fine on a smaller model, while a refactor that touches several files deserves a stronger one.

If the config already lists other providers, leave them in place. OpenCode can still use them, so you can switch models across providers without changing your TokenomixAI API key.

Open the project folder and give one small task

  1. Open a terminal at the root of the project folder, not in your home directory.
  2. Start OpenCode from the terminal and pick a model from the tokenomixai provider in the model picker.
  3. Write the task in one or two sentences and name the files that matter.
  4. Let the agent finish; do not stack a second task on a running one.

A good first task can be reviewed in a minute: adding input validation to one handler, renaming a confusing variable, or writing a test for a function that already exists. Avoid requests like tidy up the whole project on a first session, because the diff will be too large to read properly.

Give just enough context: the file name, the function name and the behaviour you expect. Something like add an empty email check to the register function in the auth handler, and do not touch other files. Explicit boundaries like that make the output easier to review and spend fewer tokens.

Read the diff before you accept changes

When the agent stops, read the diff file by file, not just the summary it prints at the end. You are checking two things: that the result is correct, and that no unrelated file, dead code or new dependency came along with it.

  • Read every changed file and confirm the change matches the request.
  • Run the tests or linter the project already has.
  • Revert anything outside the task scope, either by asking the agent or by hand.
  • Commit in one small commit so a rollback stays easy.

If the agent does not show every change, compare the folder with a plain Git diff in the terminal. If the diff is too large to review, do not accept it: narrow the instruction, for example only this file or leave the tests alone, then run the task again.

429 errors and a quota that runs out mid-session

These two problems get confused often. A 429 means rate limit: 600 requests per minute per account, shared by every key on that account. The response carries Retry-After, so wait that long and send the request again. It does not mean your quota is gone.

An empty quota shows up as status exhausted on the quota endpoint. Quota is counted in tokens, not time windows, so there is no 5-hour limit. The key keeps working while tokens remain and before it expires.

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

The response returns status, remainingTokens, maxTokens, usagePercent, expiresAt, and low, which is true at 10 percent or less. Check it before a long session, especially if you plan a large refactor.

What you seeWhat to check
429 responseRate limit of 600 requests per minute, wait for Retry-After
status exhaustedNo tokens left, top up and keep the same key
Model missing from the pickertokenomixai entry in the provider object, baseURL and apiKey options
Diff spreading across filesTask scope too wide, narrow the instruction

Habits that keep OpenCode sessions cheap in tokens

  • One task per session, since long conversations resend the context.
  • Name the relevant files instead of the whole folder.
  • Match the model to the job instead of always picking the largest one.
  • Read usagePercent after a big task before starting the next one.

On top-up your remaining tokens are added together and validity follows the latest top-up. The key stays the same, so there is no new config to paste into OpenCode.

If you prefer reviewing diffs inside an editor, OpenCode also runs in VS Code; the steps are in Install OpenCode in VS Code: Terminal Setup Guide. The TokenomixAI gateway logs request metadata only, such as model, token count, time and status; prompts and completions are not stored.

Frequently asked questions

Do I need to reinstall OpenCode to change models?

No. You pick the model while the session runs, from any provider already listed in opencode.json. The current list is on the docs page, and your API key stays the same when you switch between models.

Why does my TokenomixAI model not show up in OpenCode?

Usually the provider entry is missing or one of its options is wrong. Check that tokenomixai sits in the provider object, not in an array, with baseURL and apiKey filled in. If you are unsure, run the installer again, which backs the config up first, or read the docs.

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 at the gateway.

What if the 429 error keeps coming back?

The rate limit of 600 requests per minute is counted per account and shared by all keys on it. If it keeps returning, another script or agent is probably using the same account. Reduce parallel requests and wait for the Retry-After value before retrying.

How long is my quota valid?

The expiresAt field on the quota endpoint shows when the key expires. On top-up, remaining tokens are added together and validity follows the latest top-up, with the same key.

More articles