#14187: fix: add Moonshot AI to non-standard provider detection
agents
stale
size: XS
Cluster:
Moonshot Provider Enhancements
## Problem
When using Moonshot AI's direct API (`api.moonshot.ai` / `platform.moonshot.cn`) as a provider, OpenClaw sends the `developer` role in messages. Moonshot's chat completions endpoint enforces a strict role enum (`system`, `user`, `assistant`) and rejects unknown roles with:
```
400 invalid request: unsupported role ROLE_UNSPECIFIED
```
This makes Moonshot direct unusable as a provider.
Fixes #8579
## Root Cause
The `normalizeModelCompat` function in `model-compat.ts` sets `supportsDeveloperRole: false` for providers that don't support the newer OpenAI `developer` role — but only covered Z-AI. Moonshot endpoints were missing from this check, so the `developer` role was sent unmodified and rejected by Moonshot's API.
## Fix
Extend the existing Z-AI detection pattern to also match Moonshot endpoints (`moonshot.ai`, `platform.moonshot.cn`, or provider `moonshot`). This ensures `developer` messages are mapped to `system` before being sent.
## Changes
- `src/agents/model-compat.ts` — add `isMoonshot` check alongside existing `isZai`
- `src/agents/model-compat.test.ts` — add two test cases for Moonshot (provider name and baseUrl detection)
## Testing
- Tested locally with `moonshot/kimi-k2.5` via direct API key against `api.moonshot.ai`
- Before: `400 invalid request: unsupported role ROLE_UNSPECIFIED`
- After: Clean completions with system + user roles accepted
- Verified via both raw curl and OpenClaw sub-agent runtime flow
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates `src/agents/model-compat.ts` so `normalizeModelCompat` disables the OpenAI `developer` role not only for Z-AI (`api.z.ai` / provider `zai`) but also for Moonshot endpoints (provider `moonshot`, `moonshot.ai`, or `platform.moonshot.cn`). This causes downstream message-role mapping to send `developer` content as `system` for Moonshot OpenAI-completions models.
Two unit tests were added in `src/agents/model-compat.test.ts` to cover Moonshot detection via provider name and via base URL. The change is localized and matches the existing Z-AI compatibility behavior.
<h3>Confidence Score: 4/5</h3>
- This PR looks safe to merge and addresses the reported provider incompatibility with low blast radius.
- The change is a narrow extension of an existing compatibility gate: it only affects `openai-completions` models and only when the provider/baseUrl matches Moonshot or Z-AI. Added tests cover both detection paths. I could not execute the test suite in this environment (no node/pnpm), so confidence is slightly reduced.
- src/agents/model-compat.ts (provider/baseUrl matching logic)
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#19281: fix: set supportsDeveloperRole false as default for moonshot provider
by MisterGuy420 · 2026-02-17
91.5%
#22194: fix(agent) Moonshot/Kimi kimi-k2.5 returns ROLE_UNSPECIFIED
by ShengFuC · 2026-02-20
90.7%
#21911: Enable `reasoning: true` for Kimi models
by ighostych · 2026-02-20
84.2%
#23655: fix(model): map developer role to system for Aliyun/Dashscope/Qianf...
by SleuthCo · 2026-02-22
80.0%
#9024: Fix/Moonshot Provider Issue with kimi-k2-thinking Model Role Mappin...
by fotorpics · 2026-02-04
79.0%
#4459: fix: enable image input for Kimi K2.5 and refresh stale config mode...
by manikv12 · 2026-01-30
78.3%
#7570: fix: allow models from providers with auth profiles configured
by DonSqualo · 2026-02-03
77.7%
#22741: fix(models): add DashScope/Qwen to normalizeModelCompat developer r...
by lailoo · 2026-02-21
77.4%
#6960: feat: Add kimi-coding provider support
by YYW0228 · 2026-02-02
77.2%
#22175: fix: support xai tool stream and compat flags
by ShunsukeHayashi · 2026-02-20
76.8%