> ## 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 OpenCode to Token Factory

> Configure Corvex Token Factory as an OpenAI-compatible provider in OpenCode.

Corvex Token Factory connects to OpenCode through a custom OpenAI-compatible
provider. Store the API key with `/connect`, add the provider configuration,
then select a Token Factory model from `/models`.

## Prerequisites

* A Token Factory API key. See [Authentication](/getting-started/authentication).
* [OpenCode](https://opencode.ai/docs/) installed from its official documentation.
* A model from the [Token Factory catalog](/models/overview).

<Steps>
  <Step title="Store the API key">
    Start `opencode` and run `/connect`. Select **Other**, enter `corvex` as the
    provider ID, and paste your `sk-corvex-...` key. OpenCode stores the key in
    its credential store.

    To use an environment variable instead, skip `/connect`, add
    `"apiKey": "{env:CORVEX_API_KEY}"` to `options` in the next step, and export
    `CORVEX_API_KEY` before starting OpenCode.
  </Step>

  <Step title="Add the provider configuration">
    Add the following configuration to `opencode.json` in the project root, or
    to `~/.config/opencode/opencode.json` for global use. The provider ID must
    match the `corvex` value used with `/connect`.

    ```json theme={null}
    {
      "$schema": "https://opencode.ai/config.json",
      "provider": {
        "corvex": {
          "npm": "@ai-sdk/openai-compatible",
          "name": "Corvex Token Factory",
          "options": {
            "baseURL": "https://api.tokenfactory.corvex.cloud/v1"
          },
          "models": {
            "zai-org/GLM-5.3": {
              "name": "GLM 5.3",
              "limit": { "context": 393216, "output": 393216 }
            },
            "deepseek-ai/DeepSeek-V4-Flash-0731": {
              "name": "DeepSeek V4 Flash 0731",
              "limit": { "context": 1048576, "output": 1048576 }
            }
          }
        }
      }
    }
    ```

    OpenCode does not read context limits from the endpoint, so the configuration
    declares each model's current limit. To make GLM the default, add
    `"model": "corvex/zai-org/GLM-5.3"` at the top level.
  </Step>

  <Step title="Select and test a model">
    Start OpenCode in your repository and run `/models`. Select a model under
    **Corvex Token Factory**, then run a short task that exercises a tool call.
    A successful response confirms the provider configuration and stored key.
  </Step>
</Steps>

## Output-token limit

OpenCode currently limits each step to 32,000 output tokens through its built-in
`OUTPUT_TOKEN_MAX`. The larger `limit.output` values above record each model's
Token Factory limit but do not override the OpenCode limit.

Reasoning tokens count toward the 32,000-token step budget. If a response or tool
call is truncated, retry with a shorter prompt or divide the task into smaller
steps.
