fix(ai): tolerate trailing /v1 in custom model base URL to avoid /v1/v1 requests - #1889
Merged
openai0229 merged 1 commit intoJul 21, 2026
Merged
Conversation
Spring AI's OpenAiApi/AnthropicApi append version-prefixed paths (/v1/chat/completions, /v1/messages) to the configured base URL, while the settings UI asked users to include /v1 in the Base URL. Custom OpenAI-compatible models therefore requested .../v1/v1/chat/completions and failed with 404, even though the connection test passed. Normalize the resolved runtime base URL by stripping a trailing /v1 so base URLs with and without it hit the same endpoint, make the connection test request the same URL as the runtime, fix the upstream-target log to print the real URL, and update the Base URL hints in all locales.
This was referenced Jul 21, 2026
Closed
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.
Fixes #1888
What changed
AiModelConfigServiceImpl.resolveRuntimeModel(the single placeAiRuntimeModelis built, covering saved configs, request overrides, and theOPENAI_BASE_URL/ANTHROPIC_BASE_URLenv fallbacks) now strips a trailing/v1(and trailing slashes) from the base URL for the OPENAI and CLAUDE providers.testOpenAiCompatibleConfig) now builds the exact URL the runtime requests (normalized base + /v1/chat/completions), so a passing test no longer masks a failing chat request.ai upstream targetlog inAiModelFactorynow prints the URL actually requested (it previously loggedbase + /chat/completionswhile the real request wasbase + /v1/chat/completions)./v1is optional and never duplicated.AiModelConfigServiceImplBaseUrlTestcovers both providers, prefixed gateways (.../compatible-mode/v1), and non-/v1suffixes (.../v1betastays untouched).Why
The settings UI instructs users to include
/v1in the Base URL, and "Test connection" honors that contract (baseUrl + "/chat/completions"). But the actual chat request goes through Spring AI'sOpenAiApi, whose defaultcompletionsPathis/v1/chat/completions(Spring AI 1.1.4). Following the UI hint therefore produces.../v1/v1/chat/completions→404 Not Found, while the connection test passes.AnthropicApihas the same trap (/v1/messages).Stripping the trailing
/v1— rather than settingcompletionsPath("/chat/completions")— was chosen deliberately: it fixes configs that follow the UI hint without breaking configs that already work today with a base URL that omits/v1, and it keeps prefixed endpoints likehttps://dashscope.aliyuncs.com/compatible-mode/v1working.How I tested it
mvn -pl :chat2db-community-domain-core -am -Dtest='AiModelConfigServiceImpl*' -Dmaven.test.skip=false -DskipTests=false -Dsurefire.failIfNoSpecifiedTests=false -Dmaven.test.failure.ignore=false test→ 19 tests, 0 failures (new BaseUrlTest 7 + existing StorageTest 12).mvn -pl :chat2db-community-web -am ... test→ compiles clean (main + test sources)./v1→ 404 at.../v1/v1/chat/completions; without/v1→ works.yarn lint/build:web:communitywere not run locally.Known limitations
/v1at all (e.g. a gateway exposing/api/chat/completions) still gets/v1/chat/completionsappended — same behavior as before this change, so no regression.