fix(credential_pool): match Anthropic OAuth tokens by sk-ant-oat prefix

This commit is contained in:
charliekerfoot 2026-04-27 18:07:11 -05:00 committed by Teknium
parent b5267671f2
commit 18966b6244

View file

@ -2162,7 +2162,17 @@ def _seed_from_env(provider: str, entries: List[PooledCredential]) -> Tuple[bool
if _is_source_suppressed(provider, source):
continue
active_sources.add(source)
auth_type = AUTH_TYPE_OAUTH if provider == "anthropic" and not token.startswith("sk-ant-api") else AUTH_TYPE_API_KEY
# Claude Code OAuth tokens are the only Anthropic credentials that should
# flow into the OAuth refresh path. Match the `sk-ant-oat` prefix
# positively — matching by negation (everything not `sk-ant-api`) wrongly
# tagged admin keys (`sk-ant-admin*`) and any future API-key prefix as
# OAuth, which then got immediately marked exhausted on first use because
# they have no refresh token.
auth_type = (
AUTH_TYPE_OAUTH
if provider == "anthropic" and token.startswith("sk-ant-oat")
else AUTH_TYPE_API_KEY
)
base_url = env_url or pconfig.inference_base_url
if provider == "kimi-coding":
base_url = _resolve_kimi_base_url(token, pconfig.inference_base_url, env_url)