A Practical Guide to Pointing Coding Assistants at Local Models

    This guide explains why teams route coding assistants to self-hosted inference, how the OpenAI-style HTTP protocol maps to local endpoints, how to size GPU memory, deploy inference in process, container, or gateway form, configure clients, route tasks by complexity, and close the loop on latency, observability, security, and cost.

    Why point a coding assistant at a local model

    After trying intelligent coding assistants, many teams want the same change: stop locking requests to a remote vendor service and send them to an inference endpoint you operate. Four drivers usually appear:

    • Data stays in-network: code, internal API docs, and config snippets are sensitive; compliance may forbid sending them out.
    • Offline or weak networks: air-gapped development, classified work, and on-site debugging often have no public internet.
    • Controllable cost: high-volume, low-complexity completions explode usage-based bills; self-hosted inference turns that into a fixed resource cost.
    • Swappable models: avoid a single vendor lock-in; switch, canary, and roll back across model sizes.

    Local models are not a full replacement. They typically lag top cloud models on very long context, complex cross-file refactors, and stable tool use. The engineering goal is not “everything local,” but a switchable, tiered, observable model path.

    Protocol boundary between assistant and model

    Assistants and models generally do not rely on a proprietary protocol. The industry has converged on an HTTP-style chat/completion API—the same shape most local inference servers expose. Three fields complete the path:

    1. Base URL: e.g. http://<host>:<port>/v1. Whether the path ends in /v1 is the most common failure.
    2. Model id: must match a model the server actually loaded; verify via the list-models API—do not guess.
    3. API key placeholder: local servers often skip auth, but clients still require a non-empty value.

    Three protocol capabilities then drive UX: streaming (time-to-first-token), tool/function calling (read files, run commands), and context window (how much code fits in one request).

    Resource estimates before you deploy

    VRAM is the hard constraint. A usable estimate:

    1. weight VRAM ≈ parameters (B) × bytes per parameter
    2. FP16 → 2 bytes INT8 → 1 byte INT4 → 0.5 byte
    3. KV cache ≈ 2 × layers × hidden size × context length × concurrency × bytes

    For a 7B model in INT4, weights are about 3.5 GB. With KV cache and runtime overhead, 8 GB can support single-concurrency, fairly long-context completion. Multi-concurrency at 32K context typically needs 16 GB or more. Quantization is the best cost/quality lever, but code quality can drop in a noticeable way—A/B the same tasks before you lock a quant level.

    Three ways to run inference

    Form Fit Notes
    Single process Personal machine, single-GPU workstation Fastest start, no isolation, exclusive resources
    Containers Shared team, consistent environments Versioning and scale-out; can run on public-cloud container platforms
    Gateway Multi-model, multi-GPU, routing and rate limits One entry point, hides backends, easier canaries

    A generic start command:

    1. inference-server \
    2. --model-path /models/local-coder \
    3. --quantization int4 \
    4. --context-length 32768 \
    5. --host 0.0.0.0 --port 8080 \
    6. --max-concurrent 4

    On a cloud container platform (for example Baidu AI Cloud), you can deploy and autoscale, collect request traces with logging, alert on VRAM and latency, and store weights in object storage.

    Client configuration

    Most coding assistants support a custom provider. The essence is three fields:

    1. {
    2. "providers": [
    3. {
    4. "id": "local",
    5. "baseUrl": "http://127.0.0.1:8080/v1",
    6. "apiKey": "local-placeholder",
    7. "models": ["local-coder"]
    8. },
    9. {
    10. "id": "cloud",
    11. "baseUrl": "https://<your-gateway>/v1",
    12. "apiKey": "<token>",
    13. "models": ["reasoning-large"]
    14. }
    15. ],
    16. "default": { "completion": "local/local-coder", "chat": "cloud/reasoning-large" }
    17. }

    Debug in a fixed order: list-models to prove the server is up → exact model name match → smallest prompt to verify streaming.

    Tiered routing to keep quality usable

    One model rarely balances cost and quality. Route by task complexity:

    1. def route(task):
    2. if task.kind in ("completion", "rename", "docstring"):
    3. return "local/local-coder" # high volume, low difficulty
    4. if task.context_tokens > 0.7 * LOCAL_WINDOW:
    5. return "cloud/reasoning-large" # beyond local window
    6. if task.needs_multi_file_refactor:
    7. return "cloud/reasoning-large"
    8. return "local/local-coder"

    Supporting tactics: auto-fallback to cloud on local failure with metrics, cache cloud results per session, and aggressive context trim for completions (current file plus same-directory signatures).

    Performance and observability

    • Prioritize time-to-first-token: stream completions so wait time becomes progressive output.
    • Batching and concurrency: more concurrency raises throughput but also per-request latency—tune per workload.
    • KV cache reuse: stable session prefixes cut repeated compute via prefix cache.
    • Warm-up and timeouts: send an empty request after start to finish weight load; client timeouts around 5s first token and 120s overall, plus one retry.
    • Closed-loop metrics: at least TTFT, tokens/s, VRAM, queue length, and fallback rate; alert and scale or shift traffic on thresholds.

    Security, cost, and go-live checklist

    Keep inference on the internal network, centralize secrets, audit requests, and never commit credentialed configs. Compare self-hosted fixed capacity with usage-based subscriptions on the same basis: low or spiky demand favors subscription; high, steady, sensitive traffic favors self-hosting.

    Before production, confirm: /v1 on the endpoint, matching model names, context length vs. real repos, working tool calls, verified fallback, visible monitoring, and externalized keys. After those seven, local models can carry day-to-day coding load while hard tasks go to the cloud—cost and experience in one loop.