fix(openclaw): detect Anthropic provider and use correct API format#1260
Conversation
When Anthropic (or Anthropic-compatible) endpoints are configured, the endpoint URL was incorrectly normalized by appending `/chat/completions` (OpenAI format), causing 404 errors during skill evolution. The fix detects the provider type from the config key name or base URL and uses the correct endpoint path (`/v1/messages`) and request/response format (x-api-key header, Anthropic message schema) for Anthropic providers. Three locations fixed: - src/shared/llm-call.ts: loadOpenClawFallbackConfig, callLLMOnce - src/ingest/providers/index.ts: loadOpenClawFallbackConfig - scripts/refresh-summaries.ts: callLLM Fixes MemTensor#1254 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Fixes OpenClaw “native model” fallback and related tooling to correctly route Anthropic providers to the Anthropic Messages API format (instead of incorrectly normalizing to OpenAI’s /chat/completions), addressing 404s during skill evolution.
Changes:
- Added provider detection (by provider key name / base URL) and provider-specific endpoint normalization.
- Implemented Anthropic request/response formatting (
/v1/messages,x-api-key,anthropic-version, andcontent[]parsing) for direct LLM calls. - Updated the
refresh-summariesscript to support Anthropic-formatted calls.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| apps/memos-local-openclaw/src/shared/llm-call.ts | Adds provider detection + Anthropic vs OpenAI-compatible dispatch for one-off LLM calls and OpenClaw fallback config endpoint normalization. |
| apps/memos-local-openclaw/src/ingest/providers/index.ts | Updates OpenClaw fallback config creation to detect Anthropic and normalize endpoints accordingly. |
| apps/memos-local-openclaw/scripts/refresh-summaries.ts | Updates the maintenance script to call Anthropic with /v1/messages format and parse Anthropic responses. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| function defaultEndpointForProvider(provider: SummaryProvider, baseUrl: string): string { | ||
| const stripped = baseUrl.replace(/\/+$/, ""); | ||
| if (provider === "anthropic") { | ||
| if (stripped.endsWith("/v1/messages")) return stripped; |
| ): string { | ||
| const stripped = baseUrl.replace(/\/+$/, ""); | ||
| if (provider === "anthropic") { | ||
| if (stripped.endsWith("/v1/messages")) return stripped; |
| const isAnthropic = cfg.provider === "anthropic" | ||
| || cfg.endpoint?.toLowerCase().includes("anthropic"); | ||
|
|
||
| console.log(`Summarizer: ${cfg.provider} / ${cfg.model}`); | ||
|
|
||
| let endpoint = cfg.endpoint.replace(/\/+$/, ""); | ||
| if (!endpoint.endsWith("/chat/completions")) endpoint += "/chat/completions"; | ||
| if (isAnthropic) { | ||
| if (!endpoint.endsWith("/v1/messages") && !endpoint.endsWith("/messages")) { |
| /** | ||
| * Detect provider type from provider key name or base URL. | ||
| */ | ||
| function detectProvider(providerKey: string | undefined, baseUrl: string): SummaryProvider { | ||
| const key = providerKey?.toLowerCase() ?? ""; | ||
| const url = baseUrl.toLowerCase(); | ||
| if (key.includes("anthropic") || url.includes("anthropic")) return "anthropic"; | ||
| if (key.includes("gemini") || url.includes("generativelanguage.googleapis.com")) { | ||
| return "gemini"; | ||
| } | ||
| if (key.includes("bedrock") || url.includes("bedrock")) return "bedrock"; | ||
| return "openai_compatible"; | ||
| } |
…oint-normalization
|
The incoming block (from the plugin branch) is a partial Anthropic detection that leaked in from #1262/#1264. It should be discarded because: |
Summary
/chat/completions(OpenAI format), causing 404 errors during skill evolution/v1/messageswith correct headers (x-api-key,anthropic-version) and response parsingsrc/shared/llm-call.ts,src/ingest/providers/index.ts, andscripts/refresh-summaries.tsFixes #1254
Test plan
tsc --noEmit)vitest run)openclaw.jsonand verify skill evolution succeeds🤖 Generated with Claude Code