Skip to content

API Error 400 with Claude Code running openai/gpt-oss-120b #2220

Description

@jacob3794

Which version of LM Studio?
LM Studio 0.4.20+1

Claude Code version 2.1.216

Which operating system?
macOS 26.6

What is the bug?
When running claude --model openai/gpt-oss-120b I get the following error

500 Engine protocol predict request returned 400: {"error":{"code":400,"message":"Failed to initialize samplers: failed to parse grammar","type":"invalid_request_error"}}

Logs
From lms log stream --source runtime

runtime.log

From lms log stream --source server

Streaming logs from LM Studio

[2026-07-29 13:41:23][INFO][openai/gpt-oss-120b] Running Anthropic messages API on conversation with 3 messages.
[2026-07-29 13:41:23][INFO][openai/gpt-oss-120b] Streaming Anthropic response...
[2026-07-29 13:41:23][ERROR][openai/gpt-oss-120b] Anthropic streaming error: Engine protocol predict request returned 400: {"error":{"code":400,"message":"Failed to initialize samplers: failed to parse grammar","type":"invalid_request_error"}}
[2026-07-29 13:41:23][INFO][openai/gpt-oss-120b] Finished streaming Anthropic response
[2026-07-29 13:41:23][INFO][openai/gpt-oss-120b] Running Anthropic messages API on conversation with 3 messages.
[2026-07-29 13:41:23][ERROR][Server Error] {
  "type": "error",
  "error": {
    "type": "api_error",
    "message": "Engine protocol predict request returned 400: {\"error\":{\"code\":400,\"message\":\"Failed to initialize samplers: failed to parse grammar\",\"type\":\"invalid_request_error\"}}"
  }
}
[2026-07-29 13:41:24][INFO][openai/gpt-oss-120b] Running Anthropic messages API on conversation with 3 messages.
[2026-07-29 13:41:24][ERROR][Server Error] {
  "type": "error",
  "error": {
    "type": "api_error",
    "message": "Engine protocol predict request returned 400: {\"error\":{\"code\":400,\"message\":\"Failed to initialize samplers: failed to parse grammar\",\"type\":\"invalid_request_error\"}}"
  }
}
[2026-07-29 13:41:25][INFO][openai/gpt-oss-120b] Running Anthropic messages API on conversation with 3 messages.
[2026-07-29 13:41:25][ERROR][Server Error] {
  "type": "error",
  "error": {
    "type": "api_error",
    "message": "Engine protocol predict request returned 400: {\"error\":{\"code\":400,\"message\":\"Failed to initialize samplers: failed to parse grammar\",\"type\":\"invalid_request_error\"}}"
  }
}

To Reproduce
Steps to reproduce the behavior:

  1. Download openai/gpt-oss-120b
  2. lms server start
  3. export ANTHROPIC_BASE_URL=http://localhost:1234 export ANTHROPIC_AUTH_TOKEN=lmstudio export CLAUDE_CODE_ATTRIBUTION_HEADER=0
  4. claude --model openai/gpt-oss-120b
  5. Type hello, see error

From ChatGPT:

My conclusion

I think this is almost certainly an LM Studio bug (or an incompatibility in the bundled llama.cpp version) affecting Claude Code + gpt-oss.

The runtime is rejecting the generated GBNF before inference starts:

parse: error parsing grammar:
number of repetitions exceeds sane defaults

That's a parser limitation, not a model limitation.

After running the following cURL command ChatGPT had me try which succeeded

curl http://localhost:1234/v1/messages \
  -H "Content-Type: application/json" \
  -H "x-api-key: lmstudio" \
  -d '{
    "model":"openai/gpt-oss-120b",
    "max_tokens":32,
    "messages":[
      {
        "role":"user",
        "content":[
          {
            "type":"text",
            "text":"Say hello."
          }
        ]
      }
    ]
  }'

it came back with the following

That means:

The model is fine.
The Anthropic Messages API is fine.
The Claude Code connection is fine.
The grammar Claude Code generates for tool use is what triggers the bug when LM Studio adapts it for gpt-oss.

Notice in the runtime log that the grammar contains definitions for Claude Code's tools (tool-Bash, tool-Agent, tool-DesignSync, etc.), not just a simple JSON grammar.

The plain curl request never asks for tool calling, so LM Studio never has to generate that enormous grammar—which is why it succeeds.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions