Revised GitHub Issue: Configurable Fallback Base URL
Problem
Currently, the fallback model's API base URL is hardcoded to https://api.z.ai/api/anthropic in src/runner.ts. This restricts users to using only GLM as a fallback and prevents the use of other Anthropic-compatible providers like OpenRouter, LiteLLM, or custom local proxies.
Additionally, the current logic is gated behind the hardcoded string "glm". This means even if a user wants to use a different provider (like Gemini or DeepSeek via a proxy), they are currently forced to name their model "glm" in settings.json just to trigger the custom fallback address.
Proposed Solution
Add an optional baseUrl field to the configuration and refactor the environment building logic to be provider-agnostic. If a baseUrl is provided in the configuration, it should be used for the ANTHROPIC_BASE_URL regardless of what the model is named.
Proposed Changes
1. src/config.ts
Add an optional baseUrl property to the ModelConfig interface so both primary and fallback models can use custom endpoints:
export interface ModelConfig {
model: string;
api: string;
baseUrl?: string; // New optional field
}
2. src/runner.ts
Update buildChildEnv to prioritize the user-defined baseUrl. This removes the rigid dependency on the "glm" string while maintaining backward compatibility:
function buildChildEnv(baseEnv: Record<string, string>, config: ModelConfig): Record<string, string> {
const childEnv: Record<string, string> = { ...baseEnv };
const normalizedModel = config.model.trim().toLowerCase();
if (config.api.trim()) childEnv.ANTHROPIC_AUTH_TOKEN = config.api.trim();
// Priority 1: User-defined baseUrl from settings.json
// Priority 2: Legacy hardcoded fallback for "glm" model
if (config.baseUrl) {
childEnv.ANTHROPIC_BASE_URL = config.baseUrl;
childEnv.API_TIMEOUT_MS = "3000000";
} else if (normalizedModel === "glm") {
childEnv.ANTHROPIC_BASE_URL = "https://api.z.ai/api/anthropic";
childEnv.API_TIMEOUT_MS = "3000000";
}
return childEnv;
}
3. Execution Logic
Ensure that both the primary and fallback execution paths in execClaude and runClaudeStream pass their respective ModelConfig objects to the environment builder.
Benefits
- Flexibility: Support for any Anthropic-compatible API provider (OpenRouter, DeepSeek, Gemini-via-proxy, etc.).
- Improved DX: No need to "trick" the system by naming models "glm" to get a custom URL.
- Backward Compatibility: Existing GLM configurations remain fully functional.
Revised GitHub Issue: Configurable Fallback Base URL
Problem
Currently, the fallback model's API base URL is hardcoded to
https://api.z.ai/api/anthropicinsrc/runner.ts. This restricts users to using only GLM as a fallback and prevents the use of other Anthropic-compatible providers like OpenRouter, LiteLLM, or custom local proxies.Additionally, the current logic is gated behind the hardcoded string
"glm". This means even if a user wants to use a different provider (like Gemini or DeepSeek via a proxy), they are currently forced to name their model "glm" insettings.jsonjust to trigger the custom fallback address.Proposed Solution
Add an optional
baseUrlfield to the configuration and refactor the environment building logic to be provider-agnostic. If abaseUrlis provided in the configuration, it should be used for theANTHROPIC_BASE_URLregardless of what the model is named.Proposed Changes
1.
src/config.tsAdd an optional
baseUrlproperty to theModelConfiginterface so both primary and fallback models can use custom endpoints:2.
src/runner.tsUpdate
buildChildEnvto prioritize the user-definedbaseUrl. This removes the rigid dependency on the "glm" string while maintaining backward compatibility:3. Execution Logic
Ensure that both the primary and fallback execution paths in
execClaudeandrunClaudeStreampass their respectiveModelConfigobjects to the environment builder.Benefits