199199
200200--- @class CopilotChat.config.providers.Provider
201201--- @field disabled nil | boolean
202+ --- @field config table<string , any> ?
202203--- @field get_headers nil | fun (): table<string , string>,number ?
203204--- @field get_info nil | fun ( headers : table ): string[]
204205--- @field get_models nil | fun ( headers : table ): table<CopilotChat.client.Model>
210211local M = {}
211212
212213M .copilot = {
214+ config = {
215+ url = ' https://api.githubcopilot.com' ,
216+ },
217+
213218 get_headers = function ()
214219 local response , err = utils .curl_get (' https://api.github.com/copilot_internal/v2/token' , {
215220 json_response = true ,
@@ -222,6 +227,12 @@ M.copilot = {
222227 error (err )
223228 end
224229
230+ if response .body .endpoints and response .body .endpoints .api then
231+ M .copilot .config .url = response .body .endpoints .api
232+ else
233+ M .copilot .config .url = ' https://api.githubcopilot.com'
234+ end
235+
225236 return {
226237 [' Authorization' ] = ' Bearer ' .. response .body .token ,
227238 [' Editor-Version' ] = EDITOR_VERSION ,
@@ -231,7 +242,7 @@ M.copilot = {
231242 response .body .expires_at
232243 end ,
233244
234- get_info = function (headers )
245+ get_info = function ()
235246 local response , err = utils .curl_get (' https://api.github.com/copilot_internal/user' , {
236247 json_response = true ,
237248 headers = {
@@ -282,7 +293,7 @@ M.copilot = {
282293 end ,
283294
284295 get_models = function (headers )
285- local response , err = utils .curl_get (' https://api.githubcopilot.com /models' , {
296+ local response , err = utils .curl_get (M . copilot . config . url .. ' /models' , {
286297 json_response = true ,
287298 headers = headers ,
288299 })
@@ -322,7 +333,7 @@ M.copilot = {
322333
323334 for _ , model in ipairs (models ) do
324335 if not model .policy then
325- utils .curl_post (' https://api.githubcopilot.com /models/' .. model .id .. ' /policy' , {
336+ utils .curl_post (M . copilot . config . url .. ' /models/' .. model .id .. ' /policy' , {
326337 headers = headers ,
327338 json_request = true ,
328339 body = { state = ' enabled' },
@@ -448,7 +459,7 @@ M.copilot = {
448459 end ,
449460
450461 get_url = function ()
451- return ' https://api.githubcopilot.com /chat/completions'
462+ return M . copilot . config . url .. ' /chat/completions'
452463 end ,
453464}
454465
0 commit comments