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

> Run the Aider CLI against a Corvex Token Factory model through the OpenAI-compatible Chat Completions API.

Corvex Token Factory connects to Aider as an OpenAI-compatible endpoint. Set two
environment variables, register the model's limits in a metadata file, and pass
the model ID with the `openai/` prefix.

## Prerequisites

* A Token Factory API key. See [Authentication](/getting-started/authentication).
* [Aider](https://aider.chat/docs/install.html) installed (this guide was
  verified with Aider 0.86).
* A model ID from the [Token Factory catalog](/models/overview).

<Steps>
  <Step title="Store the key and endpoint in your shell">
    Aider reads the OpenAI-compatible endpoint and key from the environment.

    ```bash theme={null}
    export OPENAI_API_BASE="https://api.tokenfactory.corvex.cloud/v1"
    export OPENAI_API_KEY="sk-corvex-YOUR_VIRTUAL_KEY"
    ```

    Add both lines to your shell profile to make them permanent.
  </Step>

  <Step title="Register the model limits">
    Aider does not read context limits from the endpoint. Without this step it
    starts with `Warning for openai/zai-org/GLM-5.3: Unknown context window
            size and costs, using sane defaults.` Create `.aider.model.metadata.json`
    in your home directory or the repository root with the Token Factory
    models. Use the fully qualified `openai/` name.

    ```json theme={null}
    {
      "openai/zai-org/GLM-5.3": {
        "max_input_tokens": 393216,
        "max_output_tokens": 32000,
        "input_cost_per_token": 0,
        "output_cost_per_token": 0,
        "litellm_provider": "openai",
        "mode": "chat"
      },
      "openai/deepseek-ai/DeepSeek-V4-Flash-0731": {
        "max_input_tokens": 1048576,
        "max_output_tokens": 32000,
        "input_cost_per_token": 0,
        "output_cost_per_token": 0,
        "litellm_provider": "openai",
        "mode": "chat"
      }
    }
    ```

    The cost fields only affect Aider's local cost display; the published rates
    are on the [Pricing](/pricing) page. `max_output_tokens` is a per-response
    budget; keep it well below the context window so there is room for input.
  </Step>

  <Step title="Run Aider">
    Pass the Token Factory model ID with the `openai/` prefix.

    ```bash theme={null}
    cd /path/to/your/repo
    aider --model openai/zai-org/GLM-5.3
    ```

    Aider uses its `whole` edit format for models it does not know, which
    resends entire files on every edit. Both Token Factory models handle the
    more economical `diff` format; pass `--edit-format diff` or set it in the
    config file. To make the model and edit format the default, add them to
    `.aider.conf.yml` in your home directory or the repository root:

    ```yaml theme={null}
    model: openai/zai-org/GLM-5.3
    edit-format: diff
    ```

    To run a single change non-interactively:

    ```bash theme={null}
    aider --model openai/zai-org/GLM-5.3 --yes-always \
      --message "Fix the bug in add() so it returns a + b." calc.py
    ```
  </Step>

  <Step title="Verify the connection">
    Aider prints the model name on startup. Ask for a small edit to a file you
    added to the chat. Aider shows the model's reasoning under **THINKING**,
    the diff under **ANSWER**, applies the edit, and commits it. A completed
    edit confirms the endpoint, key, and model ID.
  </Step>
</Steps>

## Compatibility notes

* **Model IDs.** Use `openai/` followed by the exact `id` from `GET /v1/models`,
  for example `openai/zai-org/GLM-5.3`. IDs are case-sensitive. Do not add a
  `corvex/` prefix.
* **Reasoning.** Both models reason before answering. Aider displays the
  reasoning separately from the answer. Reasoning tokens count toward
  `max_output_tokens`.
* **Context length.** If a session exceeds the model's window, the gateway
  returns `context_length_exceeded`. Drop files from the chat with `/drop` or
  start a new session. See
  [Errors](/reference/errors#context_length_exceeded-400).
* **Input types.** Neither model accepts image input. Do not add images with
  `/paste` or `--image`; the request returns a structured error.

## Related documentation

* [Use the OpenAI SDK](/integrations/openai-drop-in) — the same endpoint from
  Python or TypeScript.
* [Connect OpenCode](/integrations/opencode) and
  [Connect Codex](/integrations/codex) — other terminal coding agents.
* [Errors](/reference/errors) — authentication, rate-limit, and validation
  responses.
