mlx-optiq
Integration · OpenCode

OpenCode

OpenCode is an open-source AI coding agent that reads, edits, and runs code in your project. It speaks the OpenAI Chat Completions API, which optiq serve exposes by default.

Quick start: optiq run

One command starts optiq serve for the model (or reuses one already running on the port), configures OpenCode for that session only, and launches it. When OpenCode exits, a server it started is stopped. Arguments after -- go to OpenCode.

terminalbash
# interactive TUI
$ optiq run opencode -m mlx-community/Qwen3.5-9B-OptiQ-4bit

# one-shot, non-interactive
$ optiq run opencode -m mlx-community/Qwen3.5-9B-OptiQ-4bit -- run "list the python files here"

The provider config is handed to OpenCode for that session and merged over your own opencode.jsonc, which is not edited. The model's context window is set too.

The steps below set up the same connection by hand, for when you run optiq serve yourself. See optiq run for every option.

1. Install OpenCode

terminalbash
# macOS / Linux:
$ curl -fsSL https://opencode.ai/install | bash

# or via Homebrew:
$ brew install sst/tap/opencode

# or, project-local via npm (handy for CI / pinned versions):
$ npm install opencode-ai

2. Start optiq serve

terminalbash
$ optiq serve \
    --model mlx-community/Qwen3.5-9B-OptiQ-4bit \
    --mtp --mtp-depth 2 \
    --port 8080

3. Configure OpenCode

OpenCode reads custom providers from opencode.jsonc, global at ~/.config/opencode/opencode.jsonc, or per-project in the workspace root (overrides global). Drop in:

opencode.jsoncjson
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "optiq": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "OptiQ Local",
      "options": {
        "baseURL": "http://localhost:8080/v1",
        "apiKey": "sk-optiq-local"
      },
      "models": {
        "qwen-9b": {
          "name": "Qwen3.5-9B (OptiQ)"
        }
      }
    }
  },
  "model": "optiq/qwen-9b"
}

The key under models (here qwen-9b) becomes the model id OpenCode sends in the request body. optiq serve ignores the body's model field and serves whichever model you started it with, so any short alias works. Do not put an absolute filesystem path in the model key (OpenCode would treat it as a literal directory and try to read files relative to it).

Launch OpenCode in your project and start chatting:

terminalbash
# interactive TUI:
$ opencode

# or one-shot non-interactive:
$ opencode run --model optiq/qwen-9b "list the python files here and tell me what main.py does"

Notes

  • Tool use: OpenCode uses function calling for file edits and shell commands. Qwen3.5-9B-OptiQ and up handle this reliably; smaller models will chat but call tools unreliably.
  • Streaming: works.
  • MTP works transparently: OpenCode sees a normal OpenAI endpoint; the speculation happens server-side.
  • Verified: tested against opencode 1.18.4, including optiq run on macOS (Apple Silicon).