OpenCode logo
Coding agents

Use TokenRex with OpenCode

Use TokenRex as a custom OpenAI-compatible provider in OpenCode.

Setup checked against the linked documentation. Screenshots are reference examples from the tool's publisher, not proof of a TokenRex connection. Live execution inside this third-party app has not been tested; verify a short request before running larger tasks.

Before you start

  • A TokenRex API key
  • A version of the app that accepts a custom OpenAI-compatible base URL

Setup methods

01

Connect and configure a custom provider

  1. 1

    Run /connect in OpenCode, choose Other, use tokenrex as the provider ID and enter your key privately. OpenCode stores this credential in its local auth.json.

  2. 2

    Merge the provider configuration below into opencode.json or opencode.jsonc. This stable-documentation schema uses provider, npm and options.

  3. 3

    Use @ai-sdk/openai-compatible for Chat Completions; @ai-sdk/openai uses Responses and is not interchangeable.

  4. 4

    Run /models and select the registered TokenRex model, then send a short test.

Configuration
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "tokenrex": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "TokenRex",
      "options": {
        "baseURL": "https://tokenrex.ai/api/public/v1"
      },
      "models": {
        "gpt-6-astra": {
          "name": "TokenRex model"
        }
      }
    }
  }
}

Setup reference
02

Environment-based credentials

  1. 1

    Instead of /connect, store TOKENREX_API_KEY in your private environment.

  2. 2

    Add apiKey: {env:TOKENREX_API_KEY} inside the provider's options, as in the example below.

  3. 3

    Global configuration lives in ~/.config/opencode/opencode.json and merges with project settings. Do not mix the stable schema with the separate v2 providers/package/settings schema.

Configuration
{
  "provider": {
    "tokenrex": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "TokenRex",
      "options": {
        "baseURL": "https://tokenrex.ai/api/public/v1",
        "apiKey": "{env:TOKENREX_API_KEY}"
      },
      "models": {
        "gpt-6-astra": {
          "name": "TokenRex model"
        }
      }
    }
  }
}

Setup reference

Troubleshooting

Authentication fails
Check that the saved TokenRex key is active and belongs in the tool's API-key field, not its subscription sign-in. Remove accidental spaces, check your wallet balance, and never share the key in screenshots or exported settings.
The model is missing or the request URL returns 404
Copy an exact enabled model ID from Models & Pricing. Follow this method's URL field: some tools expect the versioned base, others the root or full completion address. Check the documented API protocol before changing the path.
Chat works but streaming or tools fail
Test a short plain-text conversation first. Confirm the selected model and installed tool version support the required protocol and capabilities. Enable agent actions only after separately checking streaming and tool calls.

Verify the connection

Send a short message with the selected model, read its response, then confirm the exact model appears in your TokenRex usage. Test streaming and tool use separately before larger agent tasks.