From 01e05a538b4b7f20fb922016d72be8c42d400b0e Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 18 Dec 2024 23:16:41 +0800 Subject: [PATCH] fix: more reasonable error reporting (#965) --- lua/avante/providers/openai.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lua/avante/providers/openai.lua b/lua/avante/providers/openai.lua index ec6b1f2..56fd627 100644 --- a/lua/avante/providers/openai.lua +++ b/lua/avante/providers/openai.lua @@ -142,7 +142,13 @@ M.parse_curl_args = function(provider, code_opts) ["Content-Type"] = "application/json", } - if P.env.require_api_key(base) then headers["Authorization"] = "Bearer " .. provider.parse_api_key() end + if P.env.require_api_key(base) then + local api_key = provider.parse_api_key() + if api_key == nil then + error(Config.provider .. " API key is not set, please set it in your environment variable or config file") + end + headers["Authorization"] = "Bearer " .. api_key + end -- NOTE: When using "o1" set the supported parameters only local stream = true