@@ -205,11 +205,14 @@ end
205205--- @field prepare_input nil | fun ( inputs : table<CopilotChat.client.Message> , opts : CopilotChat.config.providers.Options ): table
206206--- @field prepare_output nil | fun ( output : table , opts : CopilotChat.config.providers.Options ): CopilotChat.config.providers.Output
207207--- @field get_url nil | fun ( opts : CopilotChat.config.providers.Options ): string
208+ --- @field endpoints_api string ?
208209
209210--- @type table<string , CopilotChat.config.providers.Provider>
210211local M = {}
211212
212213M .copilot = {
214+ endpoints_api = ' ' ,
215+
213216 get_headers = function ()
214217 local response , err = utils .curl_get (' https://api.github.com/copilot_internal/v2/token' , {
215218 json_response = true ,
@@ -222,6 +225,20 @@ M.copilot = {
222225 error (err )
223226 end
224227
228+ if response .body and response .body .endpoints and response .body .endpoints .api then
229+ log .info (' get_headers ok, authenticated. Use api endpoint: ' .. response .body .endpoints .api )
230+ M .endpoints_api = response .body .endpoints .api
231+ else
232+ log .error (
233+ ' get_headers authenticated, but missing key "endpoints.api" in server response. response: '
234+ .. utils .to_string (response )
235+ )
236+ error (
237+ ' get_headers authenticated, but missing key "endpoints.api" in server response. Check log for details: '
238+ .. MC .config .log_path
239+ )
240+ end
241+
225242 return {
226243 [' Authorization' ] = ' Bearer ' .. response .body .token ,
227244 [' Editor-Version' ] = EDITOR_VERSION ,
@@ -283,6 +300,7 @@ M.copilot = {
283300
284301 get_models = function (headers )
285302 local response , err = utils .curl_get (' https://api.githubcopilot.com/models' , {
303+ local response , err = utils .curl_get (M .endpoints_api .. ' /models' , {
286304 json_response = true ,
287305 headers = headers ,
288306 })
@@ -322,7 +340,7 @@ M.copilot = {
322340
323341 for _ , model in ipairs (models ) do
324342 if not model .policy then
325- utils .curl_post (' https://api.githubcopilot.com /models/' .. model .id .. ' /policy' , {
343+ utils .curl_post (M . endpoints_api .. ' /models/' .. model .id .. ' /policy' , {
326344 headers = headers ,
327345 json_request = true ,
328346 body = { state = ' enabled' },
@@ -448,7 +466,7 @@ M.copilot = {
448466 end ,
449467
450468 get_url = function ()
451- return ' https://api.githubcopilot.com /chat/completions'
469+ return M . endpoints_api .. ' /chat/completions'
452470 end ,
453471}
454472
0 commit comments