fix(openclaw): detect Anthropic provider and use correct API format#1260
Open
zerone0x wants to merge 1 commit intoMemTensor:mainfrom
Open
fix(openclaw): detect Anthropic provider and use correct API format#1260zerone0x wants to merge 1 commit intoMemTensor:mainfrom
zerone0x wants to merge 1 commit intoMemTensor:mainfrom
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>
Contributor
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; |
Comment on lines
+65
to
+72
| 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")) { |
Comment on lines
+5
to
+17
| /** | ||
| * 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"; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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