gnodet opened a new pull request, #30725: URL: https://github.com/apache/camel/pull/30725
## Summary Two bugs in `LlmClient.detectEndpoint()` caused AI commands (`camel ai`, `camel ask`, etc.) to reject OpenAI-compatible endpoints when the user passes `--url https://api.openai.com/v1` or uses a server that requires an API key to answer `/v1/models`. ## Root Cause **Bug 1 — double `/v1` prefix:** `tryExplicitUrl()` appended `/v1/models` directly to the caller-supplied URL without checking whether it already ended with `/v1`. A URL like `https://api.openai.com/v1` produced the probe path `/v1/v1/models`, which returns 404, so detection reported the endpoint as unreachable. `normalizeOpenAiModelsUrl()` already handles this case correctly but was not used in `tryExplicitUrl()`. **Bug 2 — missing API key on health check:** `isEndpointReachable()` passed empty headers to `tryHealthCheck()` for the `/v1/models` probe. Servers that require authentication return 401, which was treated as "unreachable". The API key was never forwarded to the health-check request. ## Fix - In `tryExplicitUrl()`, route the OpenAI probe through `normalizeOpenAiModelsUrl()` (which already strips a trailing `/v1` before appending `/v1/models`) and pass `buildOpenAiAuthHeaders(resolveApiKey())`. - In `isEndpointReachable()`, apply the same two corrections to the generic fallback path: strip a trailing `/v1` before constructing the probe URL, and pass auth headers on the `/v1/models` probe. ## Tests Two new regression tests in `LlmClientExplicitUrlTest`: - `urlEndingWithV1IsDetectedAsOpenAi` — passes `server.url() + "/v1"` as the URL; confirms detection succeeds and sets `apiType = openai`. Fails on unfixed code (the double-prefix produces 404). - `openAiCompatibleEndpointRequiringAuthIsDetectedWhenKeyIsConfigured` — a local server returns 401 without an Authorization header and 200 with one; confirms detection fails without a key and succeeds with one. Fails on unfixed code (no auth header sent). Both tests were verified RED on unfixed code and GREEN on the fix. The full `camel-jbang-core` test suite (3442 tests) passes. Fixes CAMEL-27514 --- _Hermes Agent (Claude Sonnet 4.6) on behalf of Guillaume Nodet_ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
