Engine protocol predict request returned 400 (LM Studio with Claude Code)
LM Studio's llama.cpp engine could not build a grammar from the tool definitions in the request. Cut the tools or MCP servers, or move back to a runtime that users report works.
Summary
- The text after returned 400 is the engine's own error; in public reports it is Failed to initialize samplers.
- Reports tie it to tool definitions; the same model answers plain prompts without tools.
- Users report it working again after disabling MCP servers, downgrading LM Studio to 0.4.16, or using the llama.cpp runtime v2.23.1 or an MLX build.
- The bug is open on LM Studio's tracker with no maintainer answer yet.
On this page
Read the part after returned 400
The message comes from LM Studio, not from Claude Code or any cloud API. LM Studio wraps the error from its local engine; the reporter of issue #2236 saw it as:
500 Engine protocol predict request returned 400
with this inside the 400 invalid_request_error:
Failed to initialize samplers: failed to parse grammar
Failed to initialize samplers means the engine could not set up token sampling for the request. If yours ends in std::exception instead, the same sampler step failed and the engine gave no more specific reason. The public reports all show the grammar form, so start with the tool checks below.
Check whether tool definitions trigger it
The reports point at the tools in the request. In issue #2220 (LM Studio 0.4.20, Claude Code 2.1.216, openai/gpt-oss-120b), a plain request without tool calling succeeds while Claude Code's requests fail. The #2236 reporter reads it as LM Studio turning Claude Code's tool schemas into a grammar for llama.cpp's sampler, a grammar too large to parse. That reading is the reporter's; LM Studio has not confirmed it.
Each MCP server you enable adds its tool definitions to Claude Code's requests, as the Claude Code error reference notes for context size. So the quickest test is fewer tools:
- In Claude Code, run
/mcpand turn off servers you do not need with/mcp disable <name>, then retry. - If the error stops, turn servers back on one at a time to find the schema LM Studio cannot handle.
Issue #2193 found exactly that kind of culprit: one MCP server's search tool had a pattern llama.cpp could not parse, and removing the server, or just that tool, fixed it. In issue #2230 several users report the same fix from disabling MCP servers. Turning reasoning off did not help there, and neither did switching off Structured Output in LM Studio or setting CLAUDE_CODE_DISABLE_STRUCTURED_OUTPUT=1 in #2236.
Versions and runtimes users report working
When you need all your tools, the reports give three ways back:
| What changed | Reported result | Report |
|---|---|---|
| LM Studio 0.4.20 Build 1 back to 0.4.16-2 | Error gone completely | #2236 |
| Metal llama.cpp runtime back to v2.23.1 (v2.24.0, v2.25.2, v2.27.0 and v2.27.1 failed) | Works | #2193 |
| Same model in MLX format with the MLX runtime | Works | #2193 |
All three are user reports. Note your LM Studio version and runtime before changing them so you can return.
Where the fix will land
The issues above are open, and none has a reply from LM Studio's maintainers. The #2193 reporter thinks the parser fix belongs in llama.cpp itself. Subscribe to #2236 if you run Claude Code against LM Studio; when a release mentions grammar parsing, test with your full tool set again.
For setting a local model up behind an Anthropic-compatible endpoint in the first place, see how to use Qwen 27B in Claude Code. Other 400 messages Claude Code prints are on our Claude Code API Error 400 page.
Sources and checks
- lmstudio-bug-tracker #2236: Grammar parser crash (failed to parse grammar) with Claude Code on 0.4.20, worked fine on 0.4.16
- lmstudio-bug-tracker #2220: API Error 400 with Claude Code running openai/gpt-oss-120b
- lmstudio-bug-tracker #2193: MCP server breaks runtime: Failed to initialize samplers: failed to parse grammar
- Claude Code error reference
- lmstudio-bug-tracker #2230: Qwen3-8B chat fails with Failed to initialize samplers: failed to parse grammar