Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions coworker/providers/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1589,6 +1589,25 @@ def verify_provider_key(
},
timeout=timeout,
)
elif name == "atlascloud":
# Atlas Cloud's /models is public (a bad key still answers 200) and its
# /chat/completions has no GET route (a valid key gets 404 there), so the
# generic probe would reject a good key with the "missing /v1" message.
# Send a non-persisted one-token completion instead, like Ark below.
default_base = next(
(f.default for f in d.fields if f.key == "base_url" and f.default), ""
)
base = (base_url or "").strip().rstrip("/") or default_base.rstrip("/")
resp = httpx.post(
base + "/chat/completions",
headers={"Authorization": f"Bearer {key}"},
json={
"model": d.recommended_model,
"messages": [{"role": "user", "content": "Reply with OK."}],
"max_tokens": 1,
},
timeout=timeout,
)
elif name in ("ark", "ark-agent-plan-cn"):
default_base = next(
(f.default for f in d.fields if f.key == "base_url" and f.default), ""
Expand Down
19 changes: 19 additions & 0 deletions tests/test_provider_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,25 @@ def test_verify_nvidia_self_hosted_rejected_key_is_invalid(monkeypatch):
) == {"ok": False, "error": "Invalid API key."}


def test_verify_atlascloud_uses_one_token_completion_probe(monkeypatch):
"""Atlas Cloud's /models is public and its /chat/completions has no GET route, so the
default probes would reject a good key (404 -> "missing /v1")."""
cap: dict = {}
_patch_post(monkeypatch, status=200, capture=cap)

assert verify_provider_key("atlascloud", api_key="ac-key") == {"ok": True}
assert cap["url"] == "https://api.atlascloud.ai/v1/chat/completions"
assert cap["headers"]["Authorization"] == "Bearer ac-key"
assert cap["json"]["model"] == "zai-org/glm-5.2"
assert cap["json"]["max_tokens"] == 1

_patch_post(monkeypatch, status=401)
assert verify_provider_key("atlascloud", api_key="bad") == {
"ok": False,
"error": "Invalid API key.",
}


def test_verify_network_error_is_clean(monkeypatch):
_patch_get(monkeypatch, raise_exc=ConnectionError("boom"))
res = verify_provider_key("openai", api_key="sk-x")
Expand Down
Loading