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
2 changes: 1 addition & 1 deletion src/components/settings/ProviderForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { useTranslation } from "@/hooks/useTranslation";

const PROVIDER_PRESETS: Record<string, { base_url: string; extra_env: string; protocol: string }> = {
anthropic: { base_url: "https://api.anthropic.com", extra_env: "{}", protocol: "anthropic" },
openrouter: { base_url: "https://openrouter.ai/api", extra_env: '{"ANTHROPIC_API_KEY":""}', protocol: "openrouter" },
openrouter: { base_url: "https://openrouter.ai/api", extra_env: '{}', protocol: "openrouter" },
bedrock: { base_url: "", extra_env: '{"CLAUDE_CODE_USE_BEDROCK":"1","AWS_REGION":"us-east-1","CLAUDE_CODE_SKIP_BEDROCK_AUTH":"1"}', protocol: "bedrock" },
vertex: { base_url: "", extra_env: '{"CLAUDE_CODE_USE_VERTEX":"1","CLOUD_ML_REGION":"us-east5","CLAUDE_CODE_SKIP_VERTEX_AUTH":"1"}', protocol: "vertex" },
custom: { base_url: "", extra_env: "{}", protocol: "openai-compatible" },
Expand Down
19 changes: 6 additions & 13 deletions src/components/settings/ProviderManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const QUICK_PRESETS: QuickPreset[] = [
provider_type: "anthropic",
protocol: "anthropic",
base_url: "",
extra_env: '{"ANTHROPIC_API_KEY":""}',
extra_env: "{}",
fields: ["name", "api_key", "base_url", "model_mapping"],
},
{
Expand Down Expand Up @@ -458,26 +458,19 @@ function PresetConnectDialog({
return;
}

// For anthropic-thirdparty, inject the correct auth key into extra_env
// while preserving any other user-specified env vars (e.g. API_TIMEOUT_MS)
// For anthropic-thirdparty, strip auth key placeholders from extra_env.
// Auth is handled via the api_key field — storing empty ANTHROPIC_API_KEY /
// ANTHROPIC_AUTH_TOKEN placeholders in extra_env causes toClaudeCodeEnv()
// to infer the wrong authStyle and can override freshly-injected credentials.
let finalExtraEnv = extraEnv;
if (preset.key === "anthropic-thirdparty") {
try {
const parsed = JSON.parse(extraEnv || "{}");
// Remove both auth keys, then set the correct one
delete parsed["ANTHROPIC_API_KEY"];
delete parsed["ANTHROPIC_AUTH_TOKEN"];
if (authStyle === "auth_token") {
parsed["ANTHROPIC_AUTH_TOKEN"] = "";
} else {
parsed["ANTHROPIC_API_KEY"] = "";
}
finalExtraEnv = JSON.stringify(parsed);
} catch {
// If parse fails, fall back to simple replacement
finalExtraEnv = authStyle === "auth_token"
? '{"ANTHROPIC_AUTH_TOKEN":""}'
: '{"ANTHROPIC_API_KEY":""}';
finalExtraEnv = "{}";
}
}
// In edit mode, preserve existing role_models_json unless the user modifies mapping fields
Expand Down