OpenCode Integration
Launch OpenCode with Treasure AI as the backend, using your existing AI Suite credits.
tdx opencode starts a local proxy, reuses your tdx authentication, and makes compatible models available under the Treasure AI provider. The active tdx profile determines the account and region.
Quick start
Install OpenCode using the upstream installation instructions, then sign in to tdx and launch:
tdx auth setup
tdx opencodeSelect a model from the Treasure AI provider in OpenCode, or pass its full td-llm-proxy/<model-id> name:
tdx opencode -- --model td-llm-proxy/claude-sonnet-5-5You need a Treasure AI account with LLM access and the opencode executable on your PATH.
Usage
tdx opencode [options] -- [opencode-args...]Arguments after -- are passed to OpenCode. Place tdx options before the separator.
# Use a specific tdx profile
tdx --profile production opencode
# Start the interactive UI with a prompt
tdx opencode -- --prompt "Explain this codebase"
# Run a prompt without the interactive UI
tdx opencode -- run --model td-llm-proxy/claude-sonnet-5-5 "Explain this codebase"
# Continue the most recent OpenCode session
tdx opencode -- --continue
# Use your own OpenCode provider configuration
tdx opencode --no-proxyThe selected profile is also inherited by tdx commands run inside OpenCode. Restart OpenCode to switch the launcher's account or region.
Options
| Option | Description |
|---|---|
--no-proxy | Launch with your own OpenCode providers, without the Treasure AI proxy or injected provider config |
--disable-1h-cache | Skip tdx's one-hour prompt-cache default, preserving explicit cache TTLs |
--llm-proxy [url] | Use Treasure AI pass-through mode, optionally with a custom upstream URL; proxy mode is already the default |
Standard tdx global options also apply, including --profile <name> and --debug.
Models and reasoning effort
List the models the launcher offers in OpenCode:
tdx opencode -- models td-llm-proxytdx ai models --feature v1_messages shows the full catalog of Messages API models and routing aliases. The launcher offers non-deprecated chat models and the auto alias, displayed as Auto.
The launcher loads model names, context limits, supported reasoning efforts, and prices from your account's model catalog. When a context limit is available, it also sets OpenCode's output limit to 32,000 tokens. If no live or cached catalog is available, it declares only Auto, without catalog metadata.
Auto uses the smallest context limit and shared reasoning efforts among its resolved candidates. It has no fixed cost metadata because the serving model varies; use tdx usage for cost estimates.
For signed-in users at treasure.ai or treasure-data.com, interactive proxy sessions default to td-llm-proxy/auto. Explicit model options, resumed sessions (-c/--continue or -s/--session), and subcommands such as run or serve keep their own model selection.
Models with supported reasoning efforts expose variants such as Low, Medium, High, XHigh, and Max, depending on the model. Select a variant in OpenCode to change the reasoning effort.
Session-scoped configuration
The Treasure AI provider is passed through OPENCODE_CONFIG_CONTENT for the launched process. If you already set this variable, tdx merges its provider settings into it and preserves unrelated settings.
The launcher does not write provider settings to your OpenCode config on each launch. On upgrading from an older tdx version, it removes the legacy td-llm-proxy provider only when its options.baseURL is exactly {env:TD_LLM_PROXY_BASE_URL}/v1, preserving comments and other settings. It checks opencode.jsonc, opencode.json, and config.json in ~/.config/opencode and prints a notice for each cleanup. User-owned providers with other URLs are kept.
With --no-proxy, provider injection and legacy cleanup are skipped.
Prompt caching
In proxy mode, tdx defaults existing ephemeral cache markers to a one-hour TTL for Claude model IDs and Auto routing aliases. It applies this to system, message, and tool blocks without replacing an explicit TTL. Other model IDs keep their existing cache settings.
To skip the one-hour default:
tdx opencode --disable-1h-cacheThis flag leaves OpenCode's cache markers and explicit TTL settings intact. One-hour cache writes can cost more than five-minute writes. For Claude models, OpenCode's cache-write price uses the catalog's one-hour rate when available and the default is enabled.
Usage report
tdx usage
tdx usage --jsonProxy requests are recorded in the shared tdx usage ledger under the tdx-opencode source. Usage is tracked per session using request metadata when present, otherwise OpenCode's x-opencode-session-id header, with default as the fallback.
tdx usage estimates costs using catalog prices, including cache and long-context rates. OpenCode's displayed model costs omit long-context pricing because its fixed threshold does not match all catalog thresholds. Use tdx usage for the catalog-aware estimate. Requests made through your own providers with --no-proxy are not recorded by the tdx proxy.
Client identification
TD-proxied LLM requests use X-TD-Client: tdx/opencode. Child tdx commands inherit this identity through TDX_CLIENT, including with --no-proxy. The User-Agent retains tdx/<version> and adds client=tdx/opencode in its comment; X-TD-Client-Version remains the tdx version. Parent startup requests and OAuth token refresh requests are outside this attribution.
Production account 1
tdx opencode is unavailable on production account 1 (TD account ID 1 on a non-dev, non-staging site), including with --no-proxy, because local conversation non-persistence cannot be enforced. Use tdx claude for that account. Launching OpenCode requires a successful TD account lookup.
Troubleshooting
OpenCode CLI not found: Install OpenCode and ensure opencode is on your PATH.
Authentication fails: Check tdx status, run tdx auth setup if needed, and relaunch.
Treasure AI models are missing: Launch with tdx opencode rather than plain opencode, and check that --no-proxy is not set. List the injected models with tdx opencode -- models td-llm-proxy.
Invalid OPENCODE_CONFIG_CONTENT: Correct the JSON/JSONC object in that environment variable and retry. The launcher reports the parsing error before starting OpenCode.