diff --git a/plugin/gemini/api.lua b/plugin/gemini/api.lua index 00bb741..d219e29 100644 --- a/plugin/gemini/api.lua +++ b/plugin/gemini/api.lua @@ -2,12 +2,28 @@ local M = {} -local api_key = vim.g.gemini_api_key -- Get API key from global variable +local function get_api_key() + -- Check for environment variable + local api_key = os.getenv("GEMINI_API_KEY") + if api_key then + return api_key + end + + -- Check for Neovim global variable + api_key = vim.g.gemini_api_key + if api_key then + return api_key + end + + return nil -- API key not found +end local function make_request(prompt) + local api_key = get_api_key() -- Get API key from environment or global variable + if not api_key then vim.notify( - "Google AI API key not set. Set g.gemini_api_key in your init.vim or init.lua.", + "Google AI API key not set. Set GEMINI_API_KEY environment variable or g.gemini_api_key in your init.vim or init.lua.", vim.log.levels.ERROR ) return nil