Skip to content

[Bug]: LM Studio Provider Fails: Environment Variable Expansion + API Endpoint Mismatch #80495

@jpereze12

Description

@jpereze12

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

OpenClaw's LM Studio provider fails due to two critical issues:

Environment variables ($LMSTUDIO_API_KEY) not expanded in API calls
API endpoint incompatibility (uses /v1/chat/completions but LM Studio's OpenAI-compatible API returns HTTP 200 with errors)

Steps to reproduce

  1. Configure LM Studio provider in openclaw.json with apiKey: "$LMSTUDIO_API_KEY"
  2. Set environment variable LMSTUDIO_API_KEY with valid token
  3. Attempt to use any LM Studio model
  4. Observe 401 error with literal string $LMSTUDIO_API_KEY

Expected behavior

  • Environment variables should be expanded before sending API requests
  • Should detect and use LM Studio's working endpoints (/api/v1/chat for native API or /v1/completions for OpenAI-compatible)

Actual behavior

  • $LMSTUDIO_API_KEY sent literally, causing 401 errors
  • Attempts to use /v1/chat/completions which LM Studio returns HTTP 200 with error: "Unexpected endpoint or method

OpenClaw version

2026.5.7

Operating system

Linux (containerized)

Install method

docker

Model

google/gemma-4-26b-a4b

Provider / routing chain

openclaw -> LM Studio

Additional provider/model setup details

Additional Context:

  • LM Studio has functional native API at /api/v1/chat (different format)
  • LM Studio's OpenAI-compatible API at /v1/chat/completions is buggy (returns 200 with errors)
  • LM Studio's old OpenAI completions API at /v1/completions works but uses deprecated format
  • Other providers (OpenRouter, Gemini) properly expand environment variables

Proposed Solutions:

  • Fix environment variable expansion in LM Studio provider
  • Add support for LM Studio's native API (/api/v1/chat)
  • Implement endpoint fallback logic for LM Studio's inconsistent API

Logs, screenshots, and evidence

Impact and severity

  • Priority: High - prevents users from using local LM Studio inference with OpenClaw

Additional information

Related Links:

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingbug:behaviorIncorrect behavior without a crash

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions