Qwen Code with a local model through Ollama: pros and limits

Qwen Code can connect to Ollama so your code never leaves the machine. Setup, the limits of local models and a money comparison with a cloud API.

5 min · · сравнение · агенты

The query "qwen code local model" is usually asked for two reasons: the code cannot be sent outside, or you want to avoid paying for tokens. Qwen Code can work with a local server through an OpenAI-compatible address, so connecting Ollama is easy. The harder part is honestly judging what you get in return: a local model has different limits on quality, speed and context. Below is the setup per the Qwen Code documentation and a comparison with a cloud API at Zukko prices as of October 18, 2026.

What you need for a local run

Qwen Code, per its docs, supports local servers (Ollama, vLLM, LM Studio) through the same modelProviders mechanism as cloud services. Conditions:

  1. Qwen Code installed: npm install -g @qwen-code/qwen-code@latest (Node.js 22+).
  2. Ollama installed and running, with a model downloaded. See its name with ollama list.
  3. Ollama serves an OpenAI-compatible API at http://localhost:11434/v1.

Pick the model for your video or system memory: the bigger the model, the harder it is to run on a laptop. Which local option suits agent tasks depends on your hardware and work; there is no universal recipe.

Configuring Qwen Code for Ollama

In ~/.qwen/settings.json add a provider modeled on the documentation example. The key for a local server can be any placeholder string:

bash
{
  "env": { "OLLAMA_API_KEY": "ollama" },
  "modelProviders": {
    "openai": [
      {
        "id": "model-name-from-ollama-list",
        "name": "Local model (Ollama)",
        "envKey": "OLLAMA_API_KEY",
        "baseUrl": "http://localhost:11434/v1",
        "generationConfig": {
          "timeout": 300000,
          "streamIdleTimeoutMs": 600000,
          "maxRetries": 1,
          "contextWindowSize": 32768
        }
      }
    ]
  },
  "security": { "auth": { "selectedType": "openai" } },
  "model": { "name": "model-name-from-ollama-list" }
}

What matters here:

  • id must match the model name on the Ollama side;
  • timeout and streamIdleTimeoutMs are raised on purpose: per the docs, slow local servers may need longer waits, and streamIdleTimeoutMs sets how long the model may stay silent between stream chunks;
  • contextWindowSize describes the context window you actually configured. Check that it matches the model's launch parameters in Ollama: a server's default context size can be smaller than the agent needs, and then the start of the conversation is cut silently.

Start qwen and check with /model that the local model is selected. If the agent does not respond, test outside the agent: curl http://localhost:11434/v1/models should return a list.

What a local run gives you

  • Privacy. Code and requests stay on your machine. This is the one argument the cloud cannot beat on price.
  • No per-token fee. You pay with hardware and electricity.
  • Offline work. For example, on a plane or in a closed network.

Limits

  • Agents need tool-calling support. An agent does not just reply in text, it calls functions: reads files, runs commands. Not every local model does this equally well. Test it on a simple task.
  • Speed. An agent session sends the model a large context at each step. On local hardware, processing a long context can take noticeable time. How long depends on your computer; there are no universal figures.
  • Context size. Cloud models in the Zukko catalog offer a 1M-token context (GLM has 128K). A local model is limited by your memory.
  • Quality. We do not rate it in advance: compare both models on one task.

What it costs in the cloud

To compare with buying hardware, let us compute the monthly cloud bill. Suppose 20 agent tasks a day at 200K input and 20K output tokens, 22 working days. That is 20 × 22 = 440 tasks, 88M input and 8.8M output per month. Formula: input in millions × input price + output in millions × output price. Prices per 1M tokens as of October 18, 2026.

ModelCalculationMonthly bill
deepseek-v4.1-flash88 × 0.013 + 8.8 × 0.038 = 1.144 + 0.3344$1.4784
glm-5.3-flash88 × 0.04 + 8.8 × 0.04 = 3.52 + 0.352$3.872
qwen3.8-max88 × 0.088 + 8.8 × 0.238 = 7.744 + 2.0944$9.8384
claude-sonnet-5-588 × 0.4 + 8.8 × 2 = 35.2 + 17.6$52.80

The real bill depends on cache and history size, so this is a guideline, not a forecast. Payback period of hardware = the price of a computer for local models ÷ the monthly cloud bill. Plug in your own numbers: at a few dollars a month, buying a graphics card to save money never pays off, though it can be justified for privacy.

How to check whether a local model is good enough

Do not choose by description; take one typical task from your own work, for example "add validation to this function and update the test". Run it on the local model and on a cloud one, and note three things: whether the agent coped without your help, how many minutes it took, and how many tokens were used (for the cloud this is in the "Usage" section, for a local model in /stats). If the local one copes with simple tasks but not hard ones, use the hybrid from the next section.

Hybrid: local and cloud models in one config

Nothing stops you from describing both models in modelProviders and switching with /model: local for private files, cloud for a hard task.

bash
{
  "modelProviders": {
    "openai": [
      {
        "id": "model-name-from-ollama-list",
        "name": "Local (Ollama)",
        "envKey": "OLLAMA_API_KEY",
        "baseUrl": "http://localhost:11434/v1"
      },
      {
        "id": "qwen3.8-max",
        "name": "Qwen 3.8 Max (Zukko)",
        "envKey": "ZUKKO_API_KEY",
        "baseUrl": "https://api.zukko.pro/v1"
      }
    ]
  }
}

Do not forget to set both variables (OLLAMA_API_KEY and ZUKKO_API_KEY with a fetch_... key), and create the key on the API keys page. The full list of models and prices: models in the docs. Access from Russia goes through the gateway: the balance is topped up via SBP (the payment page adds 8.5% on top), MasterCard or crypto.

A broader comparison of approaches than for a single agent is in local AI or an API. The basic cloud connection of Qwen Code: Qwen Code CLI. If the task is bulk and simple, look at the cheapest models.

FAQ

Can I work with Qwen Code without internet?

With a local server, yes, if the program and the model are already installed. Installing and downloading a model need a network.

Does Ollama need a Qwen model specifically?

No, any model Ollama can run will do. Qwen and Qwen Coder names are not required, but tool support matters for agents.

Why does the agent "forget" the start of the conversation?

Often it is the context window: the local server truncates input if the window is smaller than needed. Increase the window in Ollama settings and fix contextWindowSize.

What is cheaper, local or cloud?

It depends on volume. By the table above, at modest volume the cloud bill is a few dollars a month. A local run is justified by privacy or a very large volume, not by price alone.

zukko

Pay 25×
less

for Claude Code & ChatGPT

One fetch_* key and base URL api.zukko.pro — for Cursor, Claude Code, Codex, and any SDK.

Get API keyDocumentation

api.zukko.pro · fetch_*

Qwen Code local model: Ollama setup and comparison · Zukko