Federico Mariani created CAMEL-27514:
----------------------------------------
Summary: camel-jbang - the AI commands reject an OpenAI-compatible
--url that ends with /v1 or needs the API key on /v1/models
Key: CAMEL-27514
URL: https://issues.apache.org/jira/browse/CAMEL-27514
Project: Camel
Issue Type: Bug
Components: camel-jbang
Affects Versions: 4.23.0
Reporter: Federico Mariani
h3. Problem
With an explicit {{--url}}, the AI commands of the CLI ({{explain}}, {{ask}},
{{overview}}, {{harden}}, the Ollama doctor and the TUI provider selector,
through {{LlmClient.detectEndpoint()}}) first check that the endpoint is
reachable. For an OpenAI-compatible server, that check rejects two common
setups with {{LLM service is not running or not reachable}}, although the
server would serve the request:
# *A base URL that ends with {{/v1}}*, such as {{https://api.openai.com/v1}} or
{{http://localhost:8000/v1}}. This is the usual form of an OpenAI base URL
({{OPENAI_BASE_URL}}, vLLM, LiteLLM, LM Studio docs). The check appends its
paths to it and probes {{/v1/api/tags}}, {{/v1/v1/models}} and {{/v1}}.
# *A server that requires the API key on {{/v1/models}}*, even without {{/v1}}
in the URL. The check never sends the configured key, so {{/v1/models}} returns
401, and the server passes only if its root URL happens to return 200.
The second case includes the example the CLI prints itself: {{camel explain
my-route.yaml --url=https://api.openai.com --api-type=openai
--api-key=sk-...}}. Without a key, {{api.openai.com}} returns 401 on
{{/v1/models}}, 404 on {{/api/tags}} and 421 on {{/}} (checked 2026-11-24), so
the check fails.
The rest of the client already accepts a trailing {{/v1}}:
* {{normalizeOpenAiUrl}} builds {{.../v1/chat/completions}} from it.
* The models listing does the same.
* {{OPENAI_BASE_URL=http://host/v1}} with {{OPENAI_API_KEY}} works, because
that path skips the check.
h3. Reproducer
A fake server that, like OpenAI and most gateways, requires a key on
{{/v1/models}} and returns 404 on its root:
{noformat}
import http.server, json, sys
RESP = json.dumps({"object": "chat.completion", "model": "m", "choices":
[{"index": 0, "finish_reason": "stop",
"message": {"role": "assistant", "content":
"HELLO-FROM-FAKE"}}]}).encode()
class H(http.server.BaseHTTPRequestHandler):
def _send(self, code, data):
self.send_response(code); self.send_header("Content-Type",
"application/json")
self.send_header("Content-Length", str(len(data))); self.end_headers();
self.wfile.write(data)
def _authed(self):
return (self.headers.get("Authorization") or "").startswith("Bearer ")
def do_GET(self):
sys.stderr.write(f"GET {self.path} auth={self._authed()}\n")
if self.path == "/v1/models":
return self._send(200 if self._authed() else 401,
json.dumps({"data": [{"id": "m"}]}).encode())
self._send(404, b'{"detail":"Not Found"}')
def do_POST(self):
self.rfile.read(int(self.headers.get("Content-Length") or 0))
sys.stderr.write(f"POST {self.path} auth={self._authed()}\n")
ok = self.path == "/v1/chat/completions" and self._authed()
self._send(200 if ok else 401, RESP)
http.server.HTTPServer(("127.0.0.1", 18558), H).serve_forever()
{noformat}
On 4.24.0-SNAPSHOT ({{--stream=false}} because of CAMEL-27513):
||Command||Result||Requests the server saw||
|{{camel explain r.yaml --api-type=openai --url=http://127.0.0.1:18558/v1
--api-key=x --model=m --stream=false}}|LLM service is not running or not
reachable|{{GET /v1/api/tags}}, {{GET /v1/v1/models}}, {{GET /v1}}, all without
Authorization|
|{{camel explain r.yaml --api-type=openai --url=http://127.0.0.1:18558
--api-key=x --model=m --stream=false}}|LLM service is not running or not
reachable|{{GET /api/tags}}, {{GET /v1/models}}, {{GET /}}, all without
Authorization|
|{{OPENAI_BASE_URL=http://127.0.0.1:18558/v1 OPENAI_API_KEY=x camel explain
r.yaml --model=m --stream=false}}|HELLO-FROM-FAKE|{{POST /v1/chat/completions}}
with Authorization|
4.23.0 shows the same requests for a {{/v1}} URL.
h3. Cause
{{LlmClient.isEndpointReachable}} (used by {{tryExplicitUrl}} when
{{--api-type}} is set) and the auto-detection loop in {{tryExplicitUrl}} both:
* append {{/api/tags}}, {{/v1/models}} and the empty path to the URL as given,
without removing a trailing {{/v1}} or {{/v1/chat/completions}} first, which
{{normalizeOpenAiUrl}} does;
* call {{tryHealthCheck(url, Map.of(), false)}}, so no Authorization header is
sent, even when a key is configured. Only Azure and Gemini get their headers.
h3. Suggested fix
* Normalize the URL the way {{normalizeOpenAiUrl}} does before probing: strip a
trailing {{/v1}} or {{/v1/chat/completions}}.
* For the OpenAI-compatible probe, send the configured key
({{buildOpenAiAuthHeaders(resolveApiKey())}}).
* Treat 401/403 on {{/v1/models}} as "the server is there but rejected the key"
and say so, instead of "not running". That error is the one users can act on.
* Tests: add cases for a {{/v1}} URL and for a server that requires a key on
{{/v1/models}}, for example with the fake LLM server of the CLI tests.
Related: CAMEL-27513 (explain prints nothing for these providers). Found while
running the Camel AI integration tests against an OpenAI-compatible gateway
(vLLM behind LiteLLM).
_Claude Code on behalf of Croway_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)