#189

Anthropic route verification drops the base URL path (new URL("/v1/models", baseUrl))

OpenMarcoHertenopened 23d ago

Summary

modelsEndpoint() builds the verification URL for Anthropic routes with an absolute path, which discards any path component of the configured base URL:

if (route.route.provider === "anthropic")
  return new URL("/v1/models?limit=1", route.route.baseUrl);

new URL("/v1/models", base) replaces the entire path of base. For every provider whose base URL carries a path, verification therefore probes the wrong endpoint and setup fails with Model route verification failed with HTTP 404 — even though the provider fully works (messages + models both return 200 at the correct URL).

Reproduction (deepsec 2.3.10)

npx deepsec init --scaffold-only
# then configure a direct anthropic route against an Anthropic-compatible
# provider whose base URL has a path, e.g. z.ai:
npx deepsec setup --agent claude --model glm-5.3 \
  --model-auth direct --ai-provider anthropic \
  --ai-base-url https://api.z.ai/api/anthropic \
  --ai-api-key-env ZAI_API_KEY --through login --no-tui
# → Model route verification failed with HTTP 404

What actually happens:

  • probed: https://api.z.ai/v1/models?limit=1 → 404 (path /api/anthropic dropped)
  • correct: https://api.z.ai/api/anthropic/v1/models?limit=1 → 200

Suggested fix

Append the path relatively, like the OpenAI branch already does:

if (route.route.provider === "anthropic") {
  const base = new URL(route.route.baseUrl);
  base.pathname = `${base.pathname.replace(/\/$/, "")}/v1/models`;
  base.search = "limit=1";
  return base;
}

This affects any custom/direct provider with a path in its base URL (z.ai /api/anthropic, gateways behind path prefixes, etc.). We currently work around it with a local pnpm patch; happy to send a PR if the suggested fix looks right.

Activity

0

No activity yet.