> ## Documentation Index
> Fetch the complete documentation index at: https://docs.corvex.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect Kilo Code to Token Factory

> Add Corvex Token Factory as a custom OpenAI Compatible provider in Kilo Code and size each model's limits.

Corvex Token Factory connects to Kilo Code as a **custom provider** that uses the
OpenAI Compatible API. The Kilo Code CLI and the VS Code and JetBrains extensions
read the same global configuration file, so one provider entry serves all of them.

Verified with Kilo Code 7.8.8, October 2026, using the Kilo Code CLI.

## Prerequisites

* A Token Factory API key. See [Authentication](https://docs.corvex.cloud/getting-started/authentication.md).
* [Kilo Code](https://kilo.ai/docs/) 7.8.8 or later: the CLI
  (`npm install -g @kilocode/cli`) or the VS Code or JetBrains extension.
* A model from the [Token Factory catalog](https://docs.corvex.cloud/models/overview.md).

## Context window and compaction

Kilo Code does not read limits from the endpoint, so each model declares them
under `limit`:

* `limit.context` is the model's `context_window`.
* `limit.output` is the model's `max_output_tokens`. Kilo Code sends
  `max_tokens` = the smaller of this and its built-in 32,000-token cap, reduced
  only when the context is nearly full.
* `limit.input` sets where Kilo Code compacts: it summarizes the conversation
  once a request reaches `limit.input` minus 20,000 tokens (its default
  `compaction.reserved` while the output cap is at least 20,000). Without
  `limit.input`, Kilo Code compacts only at `limit.context − max_tokens`, with
  no headroom.

A single turn with large tool results can push the context past the compaction
point before compaction runs, so leave about 15% headroom: the compaction window
is `(context_window − max_tokens) / 1.15`, rounded down, and `limit.input` is
that value plus 20,000:

| Model | Context window | Output cap | `max_tokens` sent | Compaction window | `limit.input` |
| - | - | - | - | - | - |
| `zai-org/GLM-5.3` | 393,216 | 393,216 | 32,000 | 314,100 | 334,100 |
| `deepseek-ai/DeepSeek-V4-Flash-0731` | 1,048,576 | 1,048,576 | 32,000 | 883,979 | 903,979 |

`GET /v1/models` reports each model's current `context_window` and
`max_output_tokens`.

**1. Store the API key**

Export the key in your shell profile. The configuration below reads it with
`{env:CORVEX_API_KEY}`, which Kilo Code resolves only in the global
configuration file.

```bash theme={null}
export CORVEX_API_KEY="sk-corvex-..."
```

**2. Add the provider configuration**

Add the provider to the global configuration file,
`~/.config/kilo/kilo.jsonc`:

```jsonc kilo.jsonc theme={null}
{
  "provider": {
    "corvex": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Corvex Token Factory",
      "options": {
        "baseURL": "https://api.tokenfactory.corvex.cloud/v1",
        "apiKey": "{env:CORVEX_API_KEY}"
      },
      "models": {
        "zai-org/GLM-5.3": {
          "name": "GLM 5.3",
          "reasoning": true,
          "tool_call": true,
          "limit": { "context": 393216, "input": 334100, "output": 393216 }
        },
        "deepseek-ai/DeepSeek-V4-Flash-0731": {
          "name": "DeepSeek V4 Flash 0731",
          "reasoning": true,
          "tool_call": true,
          "limit": { "context": 1048576, "input": 903979, "output": 1048576 }
        }
      }
    }
  },
  "model": "corvex/zai-org/GLM-5.3"
}
```

In the extensions you can also add the provider from the settings (gear
icon) under **Providers → Custom provider**, with the Base URL
`https://api.tokenfactory.corvex.cloud/v1` and **OpenAI Compatible** as the
API. Then add the `limit` entries above to the same file and reload the
window (**Developer: Reload Window** in VS Code).

**3. Select the model and verify the connection**

New sessions in the extension can start on Kilo Code's own model router,
which does not use Token Factory. Select the model button under the chat box
and choose a model in the **Corvex Token Factory** group. The context bar
shows the configured window (`393.2K` for `zai-org/GLM-5.3`).

From the CLI, run one prompt non-interactively:

```bash theme={null}
kilo run -m corvex/deepseek-ai/DeepSeek-V4-Flash-0731 "Summarize this repository."
```

`kilo models corvex --verbose` prints the limits Kilo Code loaded for each
model.

## Compatibility notes

* **Model IDs.** Use the exact `id` from `GET /v1/models`. IDs are
  case-sensitive and use `namespace/model` format; add the `corvex/` provider
  prefix only when you select a model on the command line.
* **Output budget.** Reasoning tokens count toward the 32,000-token budget. The
  `KILO_EXPERIMENTAL_OUTPUT_TOKEN_MAX` environment variable changes the cap;
  recompute the compaction window if you change it.
* **Context length.** If a long task still exceeds the model's window, the
  gateway returns `context_length_exceeded`. Start a new task or shorten the
  context. See [Errors](https://docs.corvex.cloud/reference/errors.md#context_length_exceeded-400).
* **Debug output.** `kilo debug config` prints the resolved API key in plain
  text. Do not paste its output into issues or logs.

## Related documentation

* [Connect OpenCode](https://docs.corvex.cloud/integrations/opencode.md) — the same configuration format in
  OpenCode.
* [Use the OpenAI SDK](https://docs.corvex.cloud/integrations/openai-drop-in.md) — the same endpoint from
  Python or TypeScript.
* [Errors](https://docs.corvex.cloud/reference/errors.md) — authentication, rate-limit, and validation
  responses.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.