Merged
Conversation
igordayen
approved these changes
Apr 6, 2026
Contributor
igordayen
left a comment
There was a problem hiding this comment.
Thanks Jasper, so running IT time2time in bulk actually helps:)
|
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.



Fix inconsistent /v1 in OpenAI-compatible base URLs
Problem
Spring AI's
OpenAiApi.builder().baseUrl()appends/v1internally. Theopenai-javaSDK (OpenAIOkHttpClient) does NOT — it uses the URL as-is. Both readOPENAI_BASE_URL, which is set without/v1for Spring AI compatibility. This mismatch causes issues in several places.Fixes
OpenAiCompatibleModelFactory.mistral()— base URL included/v1, producing double/v1/v1/through Spring AIOpenAiCompatibleModelFactory.byok()KDoc — example URL included/v1, misleading for Spring AI consumersOpenAiCompatibleModelFactoryByokSpecTest— test example URL included/v1LLMOpenAiGuardRailsIntegrationIT—OpenAIOkHttpClient.fromEnv()usedOPENAI_BASE_URLwithout/v1, producing 404s on the moderation endpointNew file
OpenAiCompatibleModelFactoryByokIT— IT tests that validate BYOKbuildValidated()against real provider APIs (OpenAI, DeepSeek, Mistral, Gemini). Each test is gated by@EnabledIfEnvironmentVariableso it skips cleanly without the corresponding API key.Details
OpenAiCompatibleModelFactory.mistral()Before:
ByokSpec("https://api.mistral.ai/v1", ...)— Spring AI appends/v1internally, producinghttps://api.mistral.ai/v1/v1/chat/completions(confirmed 404 via curl).After:
ByokSpec("https://api.mistral.ai", ...)— Spring AI appends/v1, producing the correcthttps://api.mistral.ai/v1/chat/completions(confirmed 200 via curl and BYOK IT test).LLMOpenAiGuardRailsIntegrationITBefore:
OpenAIOkHttpClient.fromEnv()— readsOPENAI_BASE_URL(spring AI compatible version ofhttps://api.openai.com), SDK appends/moderationsdirectly → hitshttps://api.openai.com/moderations→ 404. This was masked by the previoustry/catchpattern intestThinkingCreateObject— theNotFoundExceptionwas silently swallowed because it wasn't aGuardRailViolationException. Only surfaced after #1577 replaced the catch withassertThrows.After: Explicit builder reads
OPENAI_BASE_URLand appends/v1→https://api.openai.com/v1, SDK appends/moderations→ hitshttps://api.openai.com/v1/moderations→ 200. Moderation correctly flags the content (violencecategory) andGuardRailViolationExceptionis thrown.Verified
embabel-agent-openaipass.OpenAiCompatibleModelFactoryByokIT— 3 passed (OpenAI, DeepSeek, Mistral), 1 skipped (Gemini, no key). Mistral confirmed working against the real API after the/v1fix.LLMOpenAiGuardRailsIntegrationIT.testThinkingCreateObjectnow passes.Fun fact
The guardrails test prompt mentions blowing up crocodiles in Florida. Southern Florida is actually the only place in the world where alligators and crocodiles coexist — the American crocodile (Crocodylus acutus) lives alongside the American alligator in the Everglades. The more you know.