LM Studio "failed to send message" error #2168

Closed
opened 2026-02-16 17:34:29 -05:00 by yindo · 16 comments
Owner

Originally created by @cybardev on GitHub (Oct 18, 2025).

Description

I am getting an error with the following config:

{
  "$schema": "https://opencode.ai/config.json",
  "autoupdate": false,
  "command": {
    "ctx": {
      "description": "Prompt with context7 MCP server.",
      "template": "$ARGUMENTS. use context7"
    },
    "hi": {
      "agent": "build",
      "description": "Say hi. Confirms readiness.",
      "template": "echo hi"
    }
  },
  "instructions": [
    "CONTRIBUTING.md",
    "docs/guidelines.md",
    ".cursor/rules/*.md"
  ],
  "mcp": {
    "context7": {
      "command": ["bun", "x", "@upstash/context7-mcp"],
      "enabled": true,
      "type": "local"
    }
  },
  "model": "lmstudio/qwen/qwen2.5-coder-14b",
  "provider": {
    "lmstudio": {
      "models": { "qwen/qwen2.5-coder-14b": { "name": "Qwen 2.5 Coder" } },
      "name": "LM Studio",
      "npm": "@ai-sdk/openai-compatible",
      "options": { "baseURL": "http://localhost:1234/v1" }
    }
  },
  "theme": "aura"
}
Latest log file (click to open)
INFO  2025-10-18T23:10:37 +77ms service=default version=0.15.2 args=[] opencode
INFO  2025-10-18T23:10:37 +3ms service=project directory=/Users/sage/.config/nixos fromDirectory
INFO  2025-10-18T23:10:38 +200ms service=config path=/Users/sage/.config/opencode/config.json loading
INFO  2025-10-18T23:10:38 +0ms service=config path=/Users/sage/.config/opencode/opencode.json loading
INFO  2025-10-18T23:10:38 +4ms service=config path=/Users/sage/.config/opencode/opencode.jsonc loading
INFO  2025-10-18T23:10:38 +3ms service=bun cmd=["/nix/store/k28iv28i21j1yhm4x3bamxa7d46si22y-opencode-0.15.2/bin/.opencode-wrapped","add","@opencode-ai/plugin@0.15.2","--exact"] cwd=/Users/sage/.config/opencode running
INFO  2025-10-18T23:10:38 +3ms service=plugin path=opencode-copilot-auth@0.0.3 loading plugin
INFO  2025-10-18T23:10:38 +11ms service=plugin path=opencode-anthropic-auth@0.0.2 loading plugin
INFO  2025-10-18T23:10:38 +30ms service=bus type=* subscribing
INFO  2025-10-18T23:10:38 +0ms service=bus type=session.updated subscribing
INFO  2025-10-18T23:10:38 +0ms service=bus type=message.updated subscribing
INFO  2025-10-18T23:10:38 +0ms service=bus type=message.part.updated subscribing
INFO  2025-10-18T23:10:38 +0ms service=format init
INFO  2025-10-18T23:10:38 +1ms service=bus type=file.edited subscribing
INFO  2025-10-18T23:10:38 +3ms service=lsp serverIds=typescript, vue, eslint, gopls, ruby-lsp, pyright, elixir-ls, zls, csharp, rust, clangd, svelte, jdtls enabled LSP servers
INFO  2025-10-18T23:10:38 +1ms service=models.dev file={} refreshing
INFO  2025-10-18T23:10:38 +2ms service=bun code=0 stdout=bun add v1.3.0 (b0a6feca)

installed @opencode-ai/plugin@0.15.2

[14.00ms] done
 stderr=Saved lockfile
 done
INFO  2025-10-18T23:10:38 +2ms service=provider init
INFO  2025-10-18T23:10:38 +1ms service=provider providerID=opencode found
INFO  2025-10-18T23:10:38 +0ms service=provider providerID=lmstudio found
INFO  2025-10-18T23:10:38 +7ms service=default cmd=["/Users/sage/.cache/opencode/tui/tui-d3nbe23x."] tui
INFO  2025-10-18T23:10:38 +72ms service=server method=GET path=/agent request
INFO  2025-10-18T23:10:38 +2ms service=server duration=2 response
INFO  2025-10-18T23:10:38 +1ms service=server method=GET path=/path request
INFO  2025-10-18T23:10:38 +1ms service=server duration=1 response
INFO  2025-10-18T23:10:38 +0ms service=server method=GET path=/project/current request
INFO  2025-10-18T23:10:38 +0ms service=server duration=0 response
INFO  2025-10-18T23:10:38 +4ms service=server method=GET path=/config request
INFO  2025-10-18T23:10:38 +0ms service=server duration=0 response
INFO  2025-10-18T23:10:38 +5ms service=server method=GET path=/command request
INFO  2025-10-18T23:10:38 +0ms service=server duration=0 response
INFO  2025-10-18T23:10:38 +1ms service=server method=GET path=/file/status request
INFO  2025-10-18T23:10:38 +1ms service=tui commands={"agent_cycle":{},"agent_cycle_reverse":{},"agent_list":{},"app_exit":{},"app_help":{},"ctx":{},"editor_open":{},"hi":{},"input_clear":{},"input_newline":{},"input_paste":{},"input_submit":{},"messages_copy":{},"messages_first":{},"messages_half_page_down":{},"messages_half_page_up":{},"messages_last":{},"messages_page_down":{},"messages_page_up":{},"messages_redo":{},"messages_undo":{},"model_cycle_recent":{},"model_cycle_recent_reverse":{},"model_list":{},"project_init":{},"session_child_cycle":{},"session_child_cycle_reverse":{},"session_compact":{},"session_export":{},"session_interrupt":{},"session_list":{},"session_new":{},"session_share":{},"session_timeline":{},"session_unshare":{},"theme_list":{},"thinking_blocks":{},"tool_details":{}} Loaded commands
INFO  2025-10-18T23:10:38 +4ms service=server method=GET path=/event request
INFO  2025-10-18T23:10:38 +1ms service=server event connected
INFO  2025-10-18T23:10:38 +1ms service=bus type=* subscribing
INFO  2025-10-18T23:10:38 +1ms service=server duration=3 response
INFO  2025-10-18T23:10:38 +1ms service=server method=GET path=/config/providers request
INFO  2025-10-18T23:10:38 +0ms service=server duration=0 response
INFO  2025-10-18T23:10:38 +0ms service=server method=GET path=/tui/control/next request
INFO  2025-10-18T23:10:38 +22ms service=server duration=31 response
INFO  2025-10-18T23:10:39 +1385ms service=server method=POST path=/session request
INFO  2025-10-18T23:10:39 +2ms service=session id=ses_606691b9cffeudEbIegvHWl05t version=0.15.2 projectID=89f34abaaf3f1e37f8ed37aff0273e2e780127e1 directory=/Users/sage/.config/nixos title=New session - 2025-10-18T23:10:39.715Z time={"created":1760829039715,"updated":1760829039715} created
INFO  2025-10-18T23:10:39 +1ms service=bus type=session.updated publishing
INFO  2025-10-18T23:10:39 +1ms service=server duration=4 response
INFO  2025-10-18T23:10:39 +8ms service=server method=POST path=/session/ses_606691b9cffeudEbIegvHWl05t/message request
INFO  2025-10-18T23:10:39 +4ms service=session.prompt session=ses_606691b9cffeudEbIegvHWl05t prompt
INFO  2025-10-18T23:10:39 +6ms service=bus type=message.updated publishing
INFO  2025-10-18T23:10:39 +2ms service=bus type=message.part.updated publishing
INFO  2025-10-18T23:10:39 +1ms service=bus type=session.updated publishing
INFO  2025-10-18T23:10:39 +0ms service=provider providerID=lmstudio modelID=qwen/qwen2.5-coder-14b getModel
INFO  2025-10-18T23:10:39 +1ms service=provider status=started providerID=lmstudio getSDK
INFO  2025-10-18T23:10:39 +60ms service=provider status=completed duration=60 providerID=lmstudio getSDK
INFO  2025-10-18T23:10:39 +0ms service=provider providerID=lmstudio modelID=qwen/qwen2.5-coder-14b found
INFO  2025-10-18T23:10:39 +0ms service=session.prompt session=ses_606691b9cffeudEbIegvHWl05t sessionID=ses_606691b9cffeudEbIegvHWl05t locking
INFO  2025-10-18T23:10:39 +19ms service=mcp key=context7 type=local found
INFO  2025-10-18T23:10:40 +292ms service=bus type=message.updated publishing
INFO  2025-10-18T23:10:40 +4ms service=session.prompt session=ses_606691b9cffeudEbIegvHWl05t process
INFO  2025-10-18T23:10:40 +3ms service=session.prompt session=ses_606691b9cffeudEbIegvHWl05t type=start part
ERROR 2025-10-18T23:10:40 +335ms service=session.prompt session=ses_606691b9cffeudEbIegvHWl05t error={"error":"The number of tokens to keep from the initial prompt is greater than the context length. Try to load the model with a larger context length, or provide a shorter input"} stream error
INFO  2025-10-18T23:10:40 +0ms service=session.prompt session=ses_606691b9cffeudEbIegvHWl05t type=start-step part
INFO  2025-10-18T23:10:40 +2ms service=bus type=message.part.updated publishing
INFO  2025-10-18T23:10:40 +18ms service=snapshot initialized
INFO  2025-10-18T23:10:40 +151ms service=snapshot hash=d9401cc1427b8890c5c61de75030a5d3385c406d
 cwd=/Users/sage/.config/nixos git=/Users/sage/.local/share/opencode/snapshot/89f34abaaf3f1e37f8ed37aff0273e2e780127e1 tracking
INFO  2025-10-18T23:10:40 +0ms service=session.prompt session=ses_606691b9cffeudEbIegvHWl05t type=error part
ERROR 2025-10-18T23:10:40 +1ms service=session.prompt session=ses_606691b9cffeudEbIegvHWl05t error=The number of tokens to keep from the initial prompt is greater than the context length. Try to load the model with a larger context length, or provide a shorter input process
INFO  2025-10-18T23:10:40 +1ms service=bus type=message.updated publishing
INFO  2025-10-18T23:10:40 +0ms service=session.prompt session=ses_606691b9cffeudEbIegvHWl05t sessionID=ses_606691b9cffeudEbIegvHWl05t unlocking
ERROR 2025-10-18T23:10:40 +0ms service=server error="The number of tokens to keep from the initial prompt is greater than the context length. Try to load the model with a larger context length, or provide a shorter input" is not an Object. (evaluating '"name" in input') failed
INFO  2025-10-18T23:10:40 +0ms service=server duration=900 response
INFO  2025-10-18T23:10:40 +0ms service=bus type=session.idle publishing
ERROR 2025-10-18T23:10:40 +1ms service=tui failed to send message: POST "http://127.0.0.1:51738/session/ses_606691b9cffeudEbIegvHWl05t/message": 400 Bad Request {"name":"UnknownError","data":{"message":"TypeError: \"The number of tokens to keep from the initial prompt is greater than the context length. Try to load the model with a larger context length, or provide a shorter input\" is not an Object. (evaluating '\"name\" in input')\n    at isInstance (/$bunfs/root/opencode:64186:26)\n    at process (/$bunfs/root/opencode:104913:56)\n    at processTicksAndRejections (native:7:39)"}}
INFO  2025-10-18T23:10:42 +2092ms service=bus type=* unsubscribing
INFO  2025-10-18T23:10:42 +0ms service=server event disconnected

If it is relevant, I used the opencode package in unstable nixpkgs through a custom home-manager module. This means the opencode installation directory is read-only, as it is in the /nix/store/ path. The config directory (~/.config/opencode/) is writable though.

Steps to reproduce

  1. Run opencode in terminal
  2. Type hi or /hi
  3. Press Enter

Screenshot and/or share link

Image

Operating System

macOS Tahoe 26.0.1 (Darwin blade 25.0.0 Darwin Kernel Version 25.0.0: Wed Sep 17 21:41:39 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T8103 arm64 arm Darwin)

Terminal

kitty 0.42.1 created by Kovid Goyal

OpenCode version

0.15.2

Originally created by @cybardev on GitHub (Oct 18, 2025). ### Description I am getting an error with the following config: ```json { "$schema": "https://opencode.ai/config.json", "autoupdate": false, "command": { "ctx": { "description": "Prompt with context7 MCP server.", "template": "$ARGUMENTS. use context7" }, "hi": { "agent": "build", "description": "Say hi. Confirms readiness.", "template": "echo hi" } }, "instructions": [ "CONTRIBUTING.md", "docs/guidelines.md", ".cursor/rules/*.md" ], "mcp": { "context7": { "command": ["bun", "x", "@upstash/context7-mcp"], "enabled": true, "type": "local" } }, "model": "lmstudio/qwen/qwen2.5-coder-14b", "provider": { "lmstudio": { "models": { "qwen/qwen2.5-coder-14b": { "name": "Qwen 2.5 Coder" } }, "name": "LM Studio", "npm": "@ai-sdk/openai-compatible", "options": { "baseURL": "http://localhost:1234/v1" } } }, "theme": "aura" } ``` <details><summary>Latest log file (click to open)</summary> ``` INFO 2025-10-18T23:10:37 +77ms service=default version=0.15.2 args=[] opencode INFO 2025-10-18T23:10:37 +3ms service=project directory=/Users/sage/.config/nixos fromDirectory INFO 2025-10-18T23:10:38 +200ms service=config path=/Users/sage/.config/opencode/config.json loading INFO 2025-10-18T23:10:38 +0ms service=config path=/Users/sage/.config/opencode/opencode.json loading INFO 2025-10-18T23:10:38 +4ms service=config path=/Users/sage/.config/opencode/opencode.jsonc loading INFO 2025-10-18T23:10:38 +3ms service=bun cmd=["/nix/store/k28iv28i21j1yhm4x3bamxa7d46si22y-opencode-0.15.2/bin/.opencode-wrapped","add","@opencode-ai/plugin@0.15.2","--exact"] cwd=/Users/sage/.config/opencode running INFO 2025-10-18T23:10:38 +3ms service=plugin path=opencode-copilot-auth@0.0.3 loading plugin INFO 2025-10-18T23:10:38 +11ms service=plugin path=opencode-anthropic-auth@0.0.2 loading plugin INFO 2025-10-18T23:10:38 +30ms service=bus type=* subscribing INFO 2025-10-18T23:10:38 +0ms service=bus type=session.updated subscribing INFO 2025-10-18T23:10:38 +0ms service=bus type=message.updated subscribing INFO 2025-10-18T23:10:38 +0ms service=bus type=message.part.updated subscribing INFO 2025-10-18T23:10:38 +0ms service=format init INFO 2025-10-18T23:10:38 +1ms service=bus type=file.edited subscribing INFO 2025-10-18T23:10:38 +3ms service=lsp serverIds=typescript, vue, eslint, gopls, ruby-lsp, pyright, elixir-ls, zls, csharp, rust, clangd, svelte, jdtls enabled LSP servers INFO 2025-10-18T23:10:38 +1ms service=models.dev file={} refreshing INFO 2025-10-18T23:10:38 +2ms service=bun code=0 stdout=bun add v1.3.0 (b0a6feca) installed @opencode-ai/plugin@0.15.2 [14.00ms] done stderr=Saved lockfile done INFO 2025-10-18T23:10:38 +2ms service=provider init INFO 2025-10-18T23:10:38 +1ms service=provider providerID=opencode found INFO 2025-10-18T23:10:38 +0ms service=provider providerID=lmstudio found INFO 2025-10-18T23:10:38 +7ms service=default cmd=["/Users/sage/.cache/opencode/tui/tui-d3nbe23x."] tui INFO 2025-10-18T23:10:38 +72ms service=server method=GET path=/agent request INFO 2025-10-18T23:10:38 +2ms service=server duration=2 response INFO 2025-10-18T23:10:38 +1ms service=server method=GET path=/path request INFO 2025-10-18T23:10:38 +1ms service=server duration=1 response INFO 2025-10-18T23:10:38 +0ms service=server method=GET path=/project/current request INFO 2025-10-18T23:10:38 +0ms service=server duration=0 response INFO 2025-10-18T23:10:38 +4ms service=server method=GET path=/config request INFO 2025-10-18T23:10:38 +0ms service=server duration=0 response INFO 2025-10-18T23:10:38 +5ms service=server method=GET path=/command request INFO 2025-10-18T23:10:38 +0ms service=server duration=0 response INFO 2025-10-18T23:10:38 +1ms service=server method=GET path=/file/status request INFO 2025-10-18T23:10:38 +1ms service=tui commands={"agent_cycle":{},"agent_cycle_reverse":{},"agent_list":{},"app_exit":{},"app_help":{},"ctx":{},"editor_open":{},"hi":{},"input_clear":{},"input_newline":{},"input_paste":{},"input_submit":{},"messages_copy":{},"messages_first":{},"messages_half_page_down":{},"messages_half_page_up":{},"messages_last":{},"messages_page_down":{},"messages_page_up":{},"messages_redo":{},"messages_undo":{},"model_cycle_recent":{},"model_cycle_recent_reverse":{},"model_list":{},"project_init":{},"session_child_cycle":{},"session_child_cycle_reverse":{},"session_compact":{},"session_export":{},"session_interrupt":{},"session_list":{},"session_new":{},"session_share":{},"session_timeline":{},"session_unshare":{},"theme_list":{},"thinking_blocks":{},"tool_details":{}} Loaded commands INFO 2025-10-18T23:10:38 +4ms service=server method=GET path=/event request INFO 2025-10-18T23:10:38 +1ms service=server event connected INFO 2025-10-18T23:10:38 +1ms service=bus type=* subscribing INFO 2025-10-18T23:10:38 +1ms service=server duration=3 response INFO 2025-10-18T23:10:38 +1ms service=server method=GET path=/config/providers request INFO 2025-10-18T23:10:38 +0ms service=server duration=0 response INFO 2025-10-18T23:10:38 +0ms service=server method=GET path=/tui/control/next request INFO 2025-10-18T23:10:38 +22ms service=server duration=31 response INFO 2025-10-18T23:10:39 +1385ms service=server method=POST path=/session request INFO 2025-10-18T23:10:39 +2ms service=session id=ses_606691b9cffeudEbIegvHWl05t version=0.15.2 projectID=89f34abaaf3f1e37f8ed37aff0273e2e780127e1 directory=/Users/sage/.config/nixos title=New session - 2025-10-18T23:10:39.715Z time={"created":1760829039715,"updated":1760829039715} created INFO 2025-10-18T23:10:39 +1ms service=bus type=session.updated publishing INFO 2025-10-18T23:10:39 +1ms service=server duration=4 response INFO 2025-10-18T23:10:39 +8ms service=server method=POST path=/session/ses_606691b9cffeudEbIegvHWl05t/message request INFO 2025-10-18T23:10:39 +4ms service=session.prompt session=ses_606691b9cffeudEbIegvHWl05t prompt INFO 2025-10-18T23:10:39 +6ms service=bus type=message.updated publishing INFO 2025-10-18T23:10:39 +2ms service=bus type=message.part.updated publishing INFO 2025-10-18T23:10:39 +1ms service=bus type=session.updated publishing INFO 2025-10-18T23:10:39 +0ms service=provider providerID=lmstudio modelID=qwen/qwen2.5-coder-14b getModel INFO 2025-10-18T23:10:39 +1ms service=provider status=started providerID=lmstudio getSDK INFO 2025-10-18T23:10:39 +60ms service=provider status=completed duration=60 providerID=lmstudio getSDK INFO 2025-10-18T23:10:39 +0ms service=provider providerID=lmstudio modelID=qwen/qwen2.5-coder-14b found INFO 2025-10-18T23:10:39 +0ms service=session.prompt session=ses_606691b9cffeudEbIegvHWl05t sessionID=ses_606691b9cffeudEbIegvHWl05t locking INFO 2025-10-18T23:10:39 +19ms service=mcp key=context7 type=local found INFO 2025-10-18T23:10:40 +292ms service=bus type=message.updated publishing INFO 2025-10-18T23:10:40 +4ms service=session.prompt session=ses_606691b9cffeudEbIegvHWl05t process INFO 2025-10-18T23:10:40 +3ms service=session.prompt session=ses_606691b9cffeudEbIegvHWl05t type=start part ERROR 2025-10-18T23:10:40 +335ms service=session.prompt session=ses_606691b9cffeudEbIegvHWl05t error={"error":"The number of tokens to keep from the initial prompt is greater than the context length. Try to load the model with a larger context length, or provide a shorter input"} stream error INFO 2025-10-18T23:10:40 +0ms service=session.prompt session=ses_606691b9cffeudEbIegvHWl05t type=start-step part INFO 2025-10-18T23:10:40 +2ms service=bus type=message.part.updated publishing INFO 2025-10-18T23:10:40 +18ms service=snapshot initialized INFO 2025-10-18T23:10:40 +151ms service=snapshot hash=d9401cc1427b8890c5c61de75030a5d3385c406d cwd=/Users/sage/.config/nixos git=/Users/sage/.local/share/opencode/snapshot/89f34abaaf3f1e37f8ed37aff0273e2e780127e1 tracking INFO 2025-10-18T23:10:40 +0ms service=session.prompt session=ses_606691b9cffeudEbIegvHWl05t type=error part ERROR 2025-10-18T23:10:40 +1ms service=session.prompt session=ses_606691b9cffeudEbIegvHWl05t error=The number of tokens to keep from the initial prompt is greater than the context length. Try to load the model with a larger context length, or provide a shorter input process INFO 2025-10-18T23:10:40 +1ms service=bus type=message.updated publishing INFO 2025-10-18T23:10:40 +0ms service=session.prompt session=ses_606691b9cffeudEbIegvHWl05t sessionID=ses_606691b9cffeudEbIegvHWl05t unlocking ERROR 2025-10-18T23:10:40 +0ms service=server error="The number of tokens to keep from the initial prompt is greater than the context length. Try to load the model with a larger context length, or provide a shorter input" is not an Object. (evaluating '"name" in input') failed INFO 2025-10-18T23:10:40 +0ms service=server duration=900 response INFO 2025-10-18T23:10:40 +0ms service=bus type=session.idle publishing ERROR 2025-10-18T23:10:40 +1ms service=tui failed to send message: POST "http://127.0.0.1:51738/session/ses_606691b9cffeudEbIegvHWl05t/message": 400 Bad Request {"name":"UnknownError","data":{"message":"TypeError: \"The number of tokens to keep from the initial prompt is greater than the context length. Try to load the model with a larger context length, or provide a shorter input\" is not an Object. (evaluating '\"name\" in input')\n at isInstance (/$bunfs/root/opencode:64186:26)\n at process (/$bunfs/root/opencode:104913:56)\n at processTicksAndRejections (native:7:39)"}} INFO 2025-10-18T23:10:42 +2092ms service=bus type=* unsubscribing INFO 2025-10-18T23:10:42 +0ms service=server event disconnected ``` </details> If it is relevant, I used the `opencode` package in unstable `nixpkgs` through a custom `home-manager` module. This means the `opencode` installation directory is read-only, as it is in the `/nix/store/` path. The config directory (`~/.config/opencode/`) is writable though. ### Steps to reproduce 1. Run `opencode` in terminal 2. Type `hi` or `/hi` 3. Press <kbd>Enter</kbd> ### Screenshot and/or share link <img width="639" height="221" alt="Image" src="https://github.com/user-attachments/assets/3a3c2862-4b58-48a4-8c90-9a9a6b213a21" /> ### Operating System macOS Tahoe 26.0.1 (Darwin blade 25.0.0 Darwin Kernel Version 25.0.0: Wed Sep 17 21:41:39 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T8103 arm64 arm Darwin) ### Terminal kitty 0.42.1 created by Kovid Goyal ### OpenCode version 0.15.2
yindo added the bug label 2026-02-16 17:34:29 -05:00
yindo closed this issue 2026-02-16 17:34:29 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Oct 18, 2025):

This issue might be a duplicate of existing issues. Please check:

  • #2259: LM Studio, Qwen 3 Coder, MacOS: ERROR: The number of tokens to keep from the initial prompt is greater than the context length. - Very similar error message and context length issue with LM Studio and Qwen models
  • #942: failed to send message: POST error with TypeError related to "name" in input evaluation - Similar TypeError pattern in error handling
  • #2742: Nvidia NIM provider error with identical TypeError about "name" in input evaluation - Exact same TypeError stack trace

The core issue appears to be that OpenCode is not properly handling error responses from LM Studio when the context length is exceeded, causing a TypeError in the error handling code rather than displaying a user-friendly error message.

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Oct 18, 2025): This issue might be a duplicate of existing issues. Please check: - #2259: LM Studio, Qwen 3 Coder, MacOS: ERROR: The number of tokens to keep from the initial prompt is greater than the context length. - Very similar error message and context length issue with LM Studio and Qwen models - #942: failed to send message: POST error with TypeError related to "name" in input evaluation - Similar TypeError pattern in error handling - #2742: Nvidia NIM provider error with identical TypeError about "name" in input evaluation - Exact same TypeError stack trace The core issue appears to be that OpenCode is not properly handling error responses from LM Studio when the context length is exceeded, causing a TypeError in the error handling code rather than displaying a user-friendly error message. Feel free to ignore if none of these address your specific case.
Author
Owner

@cybardev commented on GitHub (Oct 18, 2025):

Duplicate of #2259 it seems. Apologies for not searching more thoroughly. But even with the following config with context limits added from LM Studio, I get the same error:

{
  "$schema": "https://opencode.ai/config.json",
  "autoupdate": false,
  "command": {
    "ctx": {
      "description": "Prompt with context7 MCP server.",
      "template": "$ARGUMENTS. use context7"
    },
    "hi": {
      "agent": "build",
      "description": "Say hi. Confirms readiness.",
      "template": "echo hi"
    }
  },
  "instructions": [
    "CONTRIBUTING.md",
    "docs/guidelines.md",
    ".cursor/rules/*.md"
  ],
  "mcp": {
    "context7": {
      "command": ["bun", "x", "@upstash/context7-mcp"],
      "enabled": true,
      "type": "local"
    }
  },
  "model": "lmstudio/qwen/qwen2.5-coder-14b",
  "provider": {
    "lmstudio": {
      "models": {
        "qwen/qwen2.5-coder-14b": {
          "limit": { "context": 4096, "output": 4096 },
          "name": "Qwen 2.5 Coder"
        }
      },
      "name": "LM Studio",
      "npm": "@ai-sdk/openai-compatible",
      "options": { "baseURL": "http://localhost:1234/v1" }
    }
  },
  "theme": "aura"
}

I also can't find the limit.context and limit.output model config options documented on https://opencode.ai/docs

@cybardev commented on GitHub (Oct 18, 2025): Duplicate of #2259 it seems. Apologies for not searching more thoroughly. But even with the following config with context limits added from LM Studio, I get the same error: ```json { "$schema": "https://opencode.ai/config.json", "autoupdate": false, "command": { "ctx": { "description": "Prompt with context7 MCP server.", "template": "$ARGUMENTS. use context7" }, "hi": { "agent": "build", "description": "Say hi. Confirms readiness.", "template": "echo hi" } }, "instructions": [ "CONTRIBUTING.md", "docs/guidelines.md", ".cursor/rules/*.md" ], "mcp": { "context7": { "command": ["bun", "x", "@upstash/context7-mcp"], "enabled": true, "type": "local" } }, "model": "lmstudio/qwen/qwen2.5-coder-14b", "provider": { "lmstudio": { "models": { "qwen/qwen2.5-coder-14b": { "limit": { "context": 4096, "output": 4096 }, "name": "Qwen 2.5 Coder" } }, "name": "LM Studio", "npm": "@ai-sdk/openai-compatible", "options": { "baseURL": "http://localhost:1234/v1" } } }, "theme": "aura" } ``` I also can't find the `limit.context` and `limit.output` model config options documented on https://opencode.ai/docs
Author
Owner

@rekram1-node commented on GitHub (Oct 19, 2025):

Tbh @cybardev this just won't really work well, a context limit of 4096 is so small that just the opencode system prompt + information + tools is going to exceed that.

We could probably add soeme option for you to override things but a context limit of 5k is so small adding tools etc is goign to make your agent extremely limited in what they can do.

@rekram1-node commented on GitHub (Oct 19, 2025): Tbh @cybardev this just won't really work well, a context limit of 4096 is so small that just the opencode system prompt + information + tools is going to exceed that. We could probably add soeme option for you to override things but a context limit of 5k is so small adding tools etc is goign to make your agent extremely limited in what they can do.
Author
Owner

@rekram1-node commented on GitHub (Oct 19, 2025):

This isn't really a bug in opencode because the error is coming from LM studio, ig you can try:
to lower the “tokens to keep” setting in LM Studio so it’s less than the context length of the model

@rekram1-node commented on GitHub (Oct 19, 2025): This isn't really a bug in opencode because the error is coming from LM studio, ig you can try: to lower the “tokens to keep” setting in LM Studio so it’s less than the context length of the model
Author
Owner

@cybardev commented on GitHub (Oct 19, 2025):

@rekram1-node In that case, would you say it's impractical to try using local LLMs with opencode on 16GB unified memory, and only hosted solutions are viable?

@cybardev commented on GitHub (Oct 19, 2025): @rekram1-node In that case, would you say it's impractical to try using local LLMs with opencode on 16GB unified memory, and only hosted solutions are viable?
Author
Owner

@rekram1-node commented on GitHub (Oct 19, 2025):

Well ig my question is what are you hoping to use opencode for if you can only access ~4k tokens?

@rekram1-node commented on GitHub (Oct 19, 2025): Well ig my question is what are you hoping to use opencode for if you can only access ~4k tokens?
Author
Owner

@rekram1-node commented on GitHub (Oct 19, 2025):

We could make it so you can override system prompt, and you can disable all the tools

Just wanting to warn you about how this wont make for a great coding agent

@rekram1-node commented on GitHub (Oct 19, 2025): We could make it so you can override system prompt, and you can disable all the tools Just wanting to warn you about how this wont make for a great coding agent
Author
Owner

@cybardev commented on GitHub (Oct 19, 2025):

I'm just trying out new tools. I've mostly been a manual coder, and recently I started using Reins (frontend) for Ollama (locally hosted) with Cogito (model). There I was copy pasting to and from the chat window. So I thought maybe something like opencode could remove some of the manual copy-pasting if the LLM could access my project files directly (specific files or parts of files via line ranges I direct it to while prompting, not ingest the entire project).

I also use Helix for code editing, so Cursor or Copilot in VS Code is undesirable. opencode has a nice TUI I like.

@cybardev commented on GitHub (Oct 19, 2025): I'm just trying out new tools. I've mostly been a manual coder, and recently I started using Reins (frontend) for Ollama (locally hosted) with Cogito (model). There I was copy pasting to and from the chat window. So I thought maybe something like opencode could remove some of the manual copy-pasting if the LLM could access my project files directly (specific files or parts of files via line ranges I direct it to while prompting, not ingest the entire project). I also use Helix for code editing, so Cursor or Copilot in VS Code is undesirable. opencode has a nice TUI I like.
Author
Owner

@cybardev commented on GitHub (Oct 19, 2025):

Anyway, closing since I kinda understand what the error came from. (as mentioned, system prompt + tools + etc. exceeding context)

Thanks for helping me understand the issue better and guiding me towards a solution (hosted models).

@cybardev commented on GitHub (Oct 19, 2025): Anyway, closing since I kinda understand what the error came from. (as mentioned, system prompt + tools + etc. exceeding context) Thanks for helping me understand the issue better and guiding me towards a solution (hosted models).
Author
Owner

@cybardev commented on GitHub (Oct 27, 2025):

Just to update in case anyone (including myself in the future) comes looking...

I was actually confused by LM Studio's interface saying the model had 4K tokens. The model itself can support a lot more, the option to increase it was just deep in the settings and I didn't notice. I did switch from Qwen2-Coder-14B to Cogito-3B, but now I gave it 128K context (in both LM Studio GUI and opencode config), and it has been working well enough.

@cybardev commented on GitHub (Oct 27, 2025): Just to update in case anyone (including myself in the future) comes looking... I was actually confused by LM Studio's interface saying the model had 4K tokens. The model itself can support a lot more, the option to increase it was just deep in the settings and I didn't notice. I did switch from Qwen2-Coder-14B to Cogito-3B, but now I gave it 128K context (in both LM Studio GUI and opencode config), and it has been working well enough.
Author
Owner

@microfx commented on GitHub (Oct 29, 2025):

Can you give me the config.json of opencode? I can't get it to work sadly

@microfx commented on GitHub (Oct 29, 2025): Can you give me the config.json of opencode? I can't get it to work sadly
Author
Owner

@cybardev commented on GitHub (Oct 29, 2025):

@microfx Sure, it's this:

{
  "$schema": "https://opencode.ai/config.json",
  "autoupdate": false,
  "command": {
    "ctx": {
      "description": "Prompt with context7 MCP server.",
      "template": "$ARGUMENTS. use context7"
    },
    "hi": {
      "agent": "plan",
      "description": "Say hi. Confirms readiness.",
      "template": "echo hi"
    }
  },
  "disabled_providers": ["opencode", "ollama"],
  "instructions": [
    "CONTRIBUTING.md",
    "docs/guidelines.md",
    ".cursor/rules/*.md"
  ],
  "mcp": {
    "context7": {
      "command": ["bun", "x", "@upstash/context7-mcp"],
      "enabled": true,
      "type": "local"
    }
  },
  "model": "lmstudio/deepcogito/cogito:3b",
  "provider": {
    "lmstudio": {
      "models": {
        "deepcogito/cogito:3b": {
          "limit": { "context": 131072, "output": 32768 },
          "name": "Cogito Mini"
        }
      },
      "name": "LM Studio",
      "npm": "@ai-sdk/openai-compatible",
      "options": { "baseURL": "http://localhost:1234/v1" }
    }
  },
  "theme": "aura"
}
@cybardev commented on GitHub (Oct 29, 2025): @microfx Sure, it's this: ```json { "$schema": "https://opencode.ai/config.json", "autoupdate": false, "command": { "ctx": { "description": "Prompt with context7 MCP server.", "template": "$ARGUMENTS. use context7" }, "hi": { "agent": "plan", "description": "Say hi. Confirms readiness.", "template": "echo hi" } }, "disabled_providers": ["opencode", "ollama"], "instructions": [ "CONTRIBUTING.md", "docs/guidelines.md", ".cursor/rules/*.md" ], "mcp": { "context7": { "command": ["bun", "x", "@upstash/context7-mcp"], "enabled": true, "type": "local" } }, "model": "lmstudio/deepcogito/cogito:3b", "provider": { "lmstudio": { "models": { "deepcogito/cogito:3b": { "limit": { "context": 131072, "output": 32768 }, "name": "Cogito Mini" } }, "name": "LM Studio", "npm": "@ai-sdk/openai-compatible", "options": { "baseURL": "http://localhost:1234/v1" } } }, "theme": "aura" } ```
Author
Owner

@microfx commented on GitHub (Oct 29, 2025):

thank you very much! My confusion started in LM Studio - there are literally hundreds of -3B models (most of them have names like preview-llama-3B- and then some lettering.

This is my first day and I already drowning in version names. Got a weak M1 with 16 GB shared memory and the models I tried always gave me that token error. Would you be so kind and tell me what exact version I could / need / must try to make it work with this config?

@microfx commented on GitHub (Oct 29, 2025): thank you very much! My confusion started in LM Studio - there are literally hundreds of -3B models (most of them have names like preview-llama-3B- and then some lettering. This is my first day and I already drowning in version names. Got a weak M1 with 16 GB shared memory and the models I tried always gave me that token error. Would you be so kind and tell me what exact version I could / need / must try to make it work with this config?
Author
Owner

@cybardev commented on GitHub (Oct 29, 2025):

@microfx I'm not following naming conventions. It's kinda hacky but if there is only one model configured in Opencode like in my example, I can load whatever model in LM Studio and it will work, even if the model name doesn't match what is written in the Opencode config. Cogito 3B is actually called deepcogito-cogito-v1-preview-llama-3b formally, so the correct config would be like:

  "models": {
    "deepcogito-cogito-v1-preview-llama-3b": {
      "limit": { "context": 131072, "output": 32768 },
      "name": "Cogito Mini"
    }
  },

  // ...

  "model": "lmstudio/deepcogito-cogito-v1-preview-llama-3b",

Anyway, I also have M1 Air 16GB. I'm using LM Studio from Homebrew and Opencode from Nixpkgs unstable. But as long as you set the context to a high number in LM Studio and set limits like in my config (matching what you set in LM Studio), it should work with any recent version.

@cybardev commented on GitHub (Oct 29, 2025): @microfx I'm not following naming conventions. It's kinda hacky but if there is only one model configured in Opencode like in my example, I can load whatever model in LM Studio and it will work, even if the model name doesn't match what is written in the Opencode config. Cogito 3B is actually called `deepcogito-cogito-v1-preview-llama-3b` formally, so the correct config would be like: ```jsonc "models": { "deepcogito-cogito-v1-preview-llama-3b": { "limit": { "context": 131072, "output": 32768 }, "name": "Cogito Mini" } }, // ... "model": "lmstudio/deepcogito-cogito-v1-preview-llama-3b", ``` Anyway, I also have M1 Air 16GB. I'm using LM Studio from Homebrew and Opencode from Nixpkgs unstable. But as long as you set the context to a high number in LM Studio and set limits like in my config (matching what you set in LM Studio), it should work with any recent version.
Author
Owner

@microfx commented on GitHub (Oct 29, 2025):

it ain't working... tried the 1.4 GB model ... the larger ones ... the mids ... with the smaller I get after 70 seconds or so really weird output (yay)

but it's like a hacker doing random stuff after I said "hi"

</response_tool_call_results>

<response_tool_call_results> [TOOL_RESULT] Now let me use the Task
tool to launch the general agent. </response_tool_call_results>

<response_tool_call_results> [TOOL_RESULT] Let me create a todo list
to track this implementation. Creates todo list with the following
items:

  1. Review code for potential optimizations
  2. Check if a number is prime (task 123)
  3. Mark todos as in_progress

</response_tool_call_results>

<response_tool_call_results> [TOOL_RESULT] Now let me use the Task
tool to launch the general agent. </response_tool_call_results>

<request_command_type>todowrite <response_tool_call_results>
[TOOL_RESULT] Let me create a todo list to track this implementation.
Creates todo list with the following items:

  1. Review code for potential optimizations
  2. Check if a number is prime (task 123)
  3. Mark todos as in_progress

I was frightened... it didn't stop - like a virus doing hacker stuff 👯

@microfx commented on GitHub (Oct 29, 2025): it ain't working... tried the 1.4 GB model ... the larger ones ... the mids ... with the smaller I get after 70 seconds or so really weird output (yay) but it's like a hacker doing random stuff after I said "hi" </response_tool_call_results> <response_tool_call_results> [TOOL_RESULT] Now let me use the Task tool to launch the general agent. </response_tool_call_results> <response_tool_call_results> [TOOL_RESULT] Let me create a todo list to track this implementation. Creates todo list with the following items: 1. Review code for potential optimizations 2. Check if a number is prime (task 123) 3. Mark todos as in_progress </response_tool_call_results> <response_tool_call_results> [TOOL_RESULT] Now let me use the Task tool to launch the general agent. </response_tool_call_results> <request_command_type>todowrite <response_tool_call_results> [TOOL_RESULT] Let me create a todo list to track this implementation. Creates todo list with the following items: 1. Review code for potential optimizations 2. Check if a number is prime (task 123) 3. Mark todos as in_progress I was frightened... it didn't stop - like a virus doing hacker stuff 👯
Author
Owner

@cybardev commented on GitHub (Oct 29, 2025):

@microfx That is... unusual. You can share your config and I'll see if I can replicate.

The other thing is you may have downloaded a lower quantized model. Mine is Cogito 3B 8bit quantized MLX, which is a bit less than 4GB. I can also use Cogito 8B 4bit quantized if I wanted something similar in size and performance, or 8bit quantized for more intelligent responses but slower. MLX is a type of model built specifically for Apple Silicon.

@cybardev commented on GitHub (Oct 29, 2025): @microfx That is... unusual. You can share your config and I'll see if I can replicate. The other thing is you may have downloaded a lower quantized model. Mine is Cogito 3B 8bit quantized MLX, which is a bit less than 4GB. I can also use Cogito 8B 4bit quantized if I wanted something similar in size and performance, or 8bit quantized for more intelligent responses but slower. MLX is a type of model built specifically for Apple Silicon.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#2168