> For the complete documentation index, see [llms.txt](https://thegrid.ai/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://thegrid.ai/docs/integrations-and-best-practices/integrations/kilocode.md).

# Kilo Code Integration with The Grid | VS Code and CLI Setup

Kilo Code talks to The Grid through its built-in custom-provider flow. The CLI has a `/connect` shortcut; the VS Code extension exposes the same setup behind a gear icon. Either way, your requests go straight to `api.thegrid.ai/v1` with your Grid consumption key, billed against your Grid credits.

## Prerequisites

* Kilo Code installed (the [VS Code extension](https://marketplace.visualstudio.com/items?itemName=kilocode.Kilo-Code) or the CLI: `npm install -g @kilocode/cli`).
* 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.

### 2a. CLI: run `/connect`

```bash
kilo
```

Inside the TUI, run `/connect`, select **The Grid** from the provider list, and paste your consumption key when prompted. Kilo writes the provider config for you.

### 2b. VS Code: gear icon → Custom provider

In the Kilo Code panel, click the gear icon. In the **Providers** tab, choose **Custom provider** and select **The Grid**. Paste your consumption key and submit. Kilo populates the instrument list automatically.

### 3. Pick a default instrument

Set your default instrument in the Kilo model picker. `code-prime` is a good starting point for a coding agent; `agent-prime` fits agentic tool-use work; the Max tier handles hard architecture or long-horizon planning. The full tier guide lives in the [current instruments list](/docs/instrument-specifications/current-instruments.md).

### 4. Check the context window per instrument

Kilo Code is part of the Cline/Roo family and needs an accurate context window per model to decide how much it can send. When it reads The Grid's `/v1/models`, it picks up the window automatically. If you set a model up by hand or override it, set the context window to 128K on the `code-prime` or `agent-prime` instruments above and 1M on the Max tier, and keep max output below it. A window larger than the instrument's real one makes Kilo overpack a long task and return a 400. For any other instrument, get its context window from the [current instruments list](/docs/instrument-specifications/current-instruments.md).

### 5. (Optional) Tier instruments per mode

Kilo Code's Architect, Coder, and Debugger modes each accept their own model. A common split: Code Max for Architect and Debugger, Code Prime for Coder, Code Standard for autocomplete.

## Verification

Open a project and ask: "Add a rate limiter middleware to the Express app in `src/server.ts` and a test for it." If Kilo reads files, writes code, and runs the test, the integration is live.

## Troubleshooting

{% hint style="warning" %}
**401 Unauthorized.** You used a Grid trading key, not a consumption key. Trading keys authenticate the order book, not inference. Generate a new consumption key and reconnect.
{% endhint %}

{% hint style="warning" %}
**402 Payment Required.** Your credits are at zero. Top up at [app.thegrid.ai](https://app.thegrid.ai). Auto Buy is on by default; if it's not catching this, check that your payment method is valid.
{% endhint %}

{% hint style="info" %}
**Instruments missing from the model picker.** Confirm The Grid is in the connected providers list (gear icon → Providers in VS Code, or `kilo models` in the CLI). If you previously used another OpenAI-compatible provider with the ID `openai-compatible`, pick a fresh ID and reconnect.
{% endhint %}

{% hint style="info" %}
**Cost numbers don't match the Grid dashboard.** Kilo Code's cost display uses static per-model fields. The Grid bills at market rate per fill, which varies by supplier. Treat the dashboard at [app.thegrid.ai](https://app.thegrid.ai) as the source of truth.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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/kilocode.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.
