# OpenCode

OpenCode ships with a `/connect` flow that adds The Grid as a provider in one step. No JSON to edit, no config scope to choose. Run `opencode auth /connect`, pick The Grid, paste your consumption key, and the agent loop runs on market-priced inference.

## Prerequisites

* OpenCode installed (`opencode --version` to check).
* A Grid account at [app.thegrid.ai](https://app.thegrid.ai).
* Credits in your account. The Grid is prepaid; zero credits returns 402.
* A Grid consumption API key from **Settings → API Keys → Create Consumption Key**.

## Setup

### 1. Get your Grid consumption API key

Log into [app.thegrid.ai](https://app.thegrid.ai). Go to **Settings → API Keys → Create Consumption Key** and copy it.

### 2. Run `opencode auth /connect`

```bash
opencode auth /connect
```

Select **The Grid** from the provider list. Paste your Grid consumption key when prompted. OpenCode persists the credential for you.

### 3. Pick your `model` and `small_model`

OpenCode separates a primary `model` from a cheaper `small_model` used for title generation, summaries, and utility calls. Map both to Grid instruments. A useful default for coding agents:

* `model`: `code-prime`
* `small_model`: `text-standard`

Set them in the TUI with `/model thegrid/code-prime` and the equivalent setting for `small_model`. Instrument tiers and use cases live in the [current instruments list](/docs/instrument-specifications/current-instruments.md).

### 4. Launch OpenCode

```bash
opencode
```

The Grid's instruments appear in the `/model` picker.

## Verification

Run a quick non-interactive check against both tiers:

```bash
opencode run --model thegrid/code-prime "Reply with OK only."
opencode run --model thegrid/text-standard "Reply with OK only."
```

If both return `OK`, the provider is wired up, the key is valid, and both tiers route correctly.

## Troubleshooting

{% hint style="warning" %}
**401 on the first request.** Your key is a Grid trading key, not a consumption key. Trading keys authorize the order book, not inference. Generate a new consumption key and run `opencode auth /connect` again.
{% endhint %}

{% hint style="warning" %}
**402 Payment Required.** Your credits are at zero. Top up at [app.thegrid.ai](https://app.thegrid.ai), or enable Auto Top Up so long agent runs do not stall.
{% endhint %}

{% hint style="info" %}
**The Grid's instruments don't appear in `/model`.** Restart OpenCode after `auth /connect`. If the providers list still excludes The Grid, run `auth /connect` again to re-register.
{% endhint %}

{% hint style="info" %}
**Token counts don't match the Grid dashboard.** OpenCode's built-in counter is provider-agnostic and does not see Grid market pricing. Real spend is in the Grid dashboard.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://thegrid.ai/docs/integrations-and-best-practices/integrations/opencode.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
