fix: respect OPENAI_BASE_URL when resolving API key priority
When base_url points to a non-OpenRouter endpoint (e.g. Z.ai), OPENROUTER_API_KEY incorrectly takes priority over OPENAI_API_KEY, sending the wrong credentials. This causes 401 errors on the main inference path and forces users to comment out OPENROUTER_API_KEY, which then breaks auxiliary clients (compression, vision). Fix: check whether base_url contains "openrouter" and swap the key priority accordingly. Also adds GLM-4.7 and GLM-5 context lengths to DEFAULT_CONTEXT_LENGTHS.
This commit is contained in:
parent
2af2f148ab
commit
3221818b6e
2 changed files with 20 additions and 6 deletions
|
|
@ -33,6 +33,8 @@ DEFAULT_CONTEXT_LENGTHS = {
|
||||||
"meta-llama/llama-3.3-70b-instruct": 131072,
|
"meta-llama/llama-3.3-70b-instruct": 131072,
|
||||||
"deepseek/deepseek-chat-v3": 65536,
|
"deepseek/deepseek-chat-v3": 65536,
|
||||||
"qwen/qwen-2.5-72b-instruct": 32768,
|
"qwen/qwen-2.5-72b-instruct": 32768,
|
||||||
|
"glm-4.7": 202752,
|
||||||
|
"glm-5": 202752,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,12 +72,24 @@ def _resolve_openrouter_runtime(
|
||||||
or OPENROUTER_BASE_URL
|
or OPENROUTER_BASE_URL
|
||||||
).rstrip("/")
|
).rstrip("/")
|
||||||
|
|
||||||
api_key = (
|
# When base_url points to a non-OpenRouter endpoint (e.g. Z.ai, local LLM),
|
||||||
explicit_api_key
|
# prefer OPENAI_API_KEY so the correct credentials reach the correct provider.
|
||||||
or os.getenv("OPENROUTER_API_KEY")
|
# This allows OPENROUTER_API_KEY to coexist for auxiliary tasks (compression
|
||||||
or os.getenv("OPENAI_API_KEY")
|
# summaries, vision, session search) without hijacking main inference.
|
||||||
or ""
|
if base_url and "openrouter" not in base_url.lower():
|
||||||
)
|
api_key = (
|
||||||
|
explicit_api_key
|
||||||
|
or os.getenv("OPENAI_API_KEY")
|
||||||
|
or os.getenv("OPENROUTER_API_KEY")
|
||||||
|
or ""
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
api_key = (
|
||||||
|
explicit_api_key
|
||||||
|
or os.getenv("OPENROUTER_API_KEY")
|
||||||
|
or os.getenv("OPENAI_API_KEY")
|
||||||
|
or ""
|
||||||
|
)
|
||||||
|
|
||||||
source = "explicit" if (explicit_api_key or explicit_base_url) else "env/config"
|
source = "explicit" if (explicit_api_key or explicit_base_url) else "env/config"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue