Config: remove --api-key CLI flag

This commit is contained in:
Adrià Arrufat
2026-04-07 08:34:15 +02:00
parent e6228cafaf
commit 3fde7fb6b5
2 changed files with 5 additions and 15 deletions

View File

@@ -220,7 +220,6 @@ pub const Agent = struct {
common: Common = .{},
provider: AiProvider = .anthropic,
model: ?[:0]const u8 = null,
api_key: ?[:0]const u8 = null,
system_prompt: ?[:0]const u8 = null,
repl: bool = true,
script_file: ?[]const u8 = null,
@@ -501,11 +500,11 @@ pub fn printUsageAndExit(self: *const Config, success: bool) void {
\\--model The model name to use.
\\ Defaults to a sensible default per provider.
\\
\\--api-key The API key. Can also be set via environment variable:
\\ ANTHROPIC_API_KEY, OPENAI_API_KEY, or GOOGLE_API_KEY.
\\
\\--system-prompt Override the default system prompt.
\\
\\The API key is read from the environment:
\\ANTHROPIC_API_KEY, OPENAI_API_KEY, or GOOGLE_API_KEY.
\\
++ common_options ++
\\
\\version command
@@ -927,15 +926,6 @@ fn parseAgentArgs(
continue;
}
if (std.mem.eql(u8, "--api-key", opt) or std.mem.eql(u8, "--api_key", opt)) {
const str = args.next() orelse {
log.fatal(.app, "missing argument value", .{ .arg = opt });
return error.InvalidArgument;
};
result.api_key = try allocator.dupeZ(u8, str);
continue;
}
if (std.mem.eql(u8, "--repl", opt)) {
result.repl = true;
continue;

View File

@@ -84,9 +84,9 @@ pub fn init(allocator: std.mem.Allocator, app: *App, opts: Config.Agent) !*Self
const is_script_mode = opts.script_file != null;
// API key is only required for REPL mode and self-healing
const api_key: ?[:0]const u8 = opts.api_key orelse getEnvApiKey(opts.provider) orelse if (!is_script_mode) {
const api_key: ?[:0]const u8 = getEnvApiKey(opts.provider) orelse if (!is_script_mode) {
log.fatal(.app, "missing API key", .{
.hint = "Set the API key via --api-key or environment variable",
.hint = "Set ANTHROPIC_API_KEY, OPENAI_API_KEY, or GOOGLE_API_KEY",
});
return error.MissingApiKey;
} else null;