For the complete documentation index, see llms.txt. This page is also available as Markdown.

OpenCode

Track usage, control costs, and add guardrails to your OpenCode coding agent

What is OpenCode?

OpenCode is an open-source coding agent that runs in your terminal, IDE, or desktop. It handles coding tasks, file operations, and multi-step workflows through natural language, and supports multiple model providers through its built-in provider settings.

By routing OpenCode through FastRouter, you get:

  • 100+ models from OpenAI, Anthropic, Google, xAI, Meta, Groq, Mistral, and more through one endpoint

  • Observability for every request: cost, tokens, latency, and model selection tracked in real time

  • Reliability through automatic failover across providers, response caching, and intelligent routing

  • Governance with per-key budgets, rate limits, model restrictions, role-based access, and project isolation

This guide covers OpenCode desktop configuration with FastRouter, model selection, team governance, and production feature usage. It does not cover the OpenCode CLI or IDE plugins.

Prerequisites


Quick Start for OpenCode Desktop App

Step 1: Install OpenCode Desktop App

Download OpenCode and install it on your system.

Step 2: Get Your FastRouter API Key

  1. Sign up or log in at fastrouter.ai

  2. Navigate to your project's Keys page

  3. Click Create User Key

  4. Copy the key immediately. FastRouter does not display the key again after creation.

Step 3: Open OpenCode Settings

Launch the OpenCode desktop app and open Settings.

Step 4: Go to Providers

In the Settings sidebar, select Providers.

Step 5: Show More Providers

Click Show more Providers to expand the full provider list.

Step 6: Select FastRouter

Search for or scroll to FastRouter in the provider list and select it.

Step 7: Add Your API Key

Paste the FastRouter API key from Step 2 and save. You should see a Successfully added confirmation.

Step 8: Enable FastRouter Models

To access FastRouter's full model catalog inside OpenCode:

  1. Click the model name below the prompt box

  1. Click Manage Models

    Manage Models
  2. Toggle on the FastRouter models you want to use

All enabled models are now available from the model picker. Requests route through FastRouter, and you can monitor usage in your FastRouter Dashboard.


Quick Start for OpenCode CLI

Step 1: Install OpenCode CLI

Download OpenCode and install it on your system.

Step 2: Get Your FastRouter API Key

  1. Sign up or log in at fastrouter.ai

  2. Navigate to your project's Keys page

  3. Click Create User Key

  4. Copy the key immediately. FastRouter does not display the key again after creation.

Step 3: Start OpenCode

Step 4: Connect FastRouter

Inside OpenCode, run the /connect command and select FastRouter from the provider list:

  1. Select FastRouter

  2. Paste the API key from Step 2

  3. Pick a model and start prompting

Step 4 (Alternative): Configure via opencode.json

Instead of running /connect, you can declare the FastRouter provider in your opencode.json config file:

Set your API key via /connect, or by adding it to ~/.local/share/opencode/auth.json:

Note: OpenCode stores credentials at ~/.local/share/opencode/auth.json on Linux. macOS and Windows users should consult the OpenCode docs for their platform's auth path.


Use OpenCode with 100+ Models

Switch between any of FastRouter's 100+ supported models from the OpenCode model picker (desktop) or by setting the model field / running /model (CLI). FastRouter uses the provider/model-name format:

Model Examples

Pick a different provider or model at any time:

No code changes or SDK swaps required. Select the model and OpenCode uses the new provider for the next request.

Automatic Model Selection

Let FastRouter pick the best model for each request based on query complexity, domain, and cost. Use this model identifier:

FastRouter analyzes the input and routes to the most appropriate model from the available pool. This is the fastest way to get started without maintaining model preferences.

Explore automatic provider selection

Cost-Optimized Routing with Sorting Slugs

Append a suffix to any model identifier to control provider selection:

Configure cost and performance routing

Flex Pricing

For batch-style coding tasks that tolerate higher latency, append :flex to any model to access up to 50% lower token costs:

Flex routes your request to the provider's discounted inference tier. Same API key, same endpoint, same payload.

Note: Flex is not recommended for interactive OpenCode sessions where you need low-latency responses. Use it for large refactoring jobs, codebase analysis, or documentation generation.

Compare flex pricing options


FAQs

Configuration & Setup

Can I use multiple models with the same API key?

Yes. The API key controls access and budget. The model is selected per request in OpenCode (model picker on desktop, /model or the model field in opencode.json on the CLI). You can switch models at any time without changing your key.

Can I use OpenCode with my own provider keys (BYOK)?

Yes. Set up an External Key integration in the FastRouter dashboard, then route OpenCode traffic through it. You retain your provider's pricing and rate limits while gaining FastRouter's routing and observability layer.

Can I restrict a key to only use specific models?

Yes. When creating or editing a key, use the Select Models setting to limit which models the key can access. FastRouter rejects requests to unauthorized models.

Costs & Budgeting

What happens when a key exceeds its budget?

FastRouter blocks further requests until the budget resets (if a reset interval is configured) or an admin increases the limit. The developer receives an error response indicating the budget has been exceeded.

How do I track OpenCode spending by team?

Create separate projects for each team, issue project-scoped API keys, and use Dynamic Tags for finer-grained attribution. The Dashboard breaks down costs by project, key, model, and tag.

Performance & Reliability

Does FastRouter add latency to OpenCode requests?

FastRouter adds near-zero gateway overhead. For most workflows, this is negligible compared to model inference time.

Privacy & Security

Is my code sent to FastRouter's servers?

FastRouter acts as a pass-through gateway. Requests are routed to the model provider and responses are returned to your client. Content logging can be disabled per key for sensitive workloads. See the Disable Content Logging option in key settings.


Next Steps

Last updated