detached 1b17517

Fix GitHub Copilot completions path

commit
1b17517ac2ce6f340f8779d6dc6d6bf5b6f771f2
author
patriceckhart · · 2026-07-12 19:29 UTC
parent
37f8c5c
signature
unsigned
refs
tag: v0.2.80
3 files · +32 -11
M packages/provider/github_copilot.go +5 -4
@@ -190,9 +190,10 @@ func NewGithubCopilotClient(pat string) Client {
190190 // Initial baseURL is a sane default; copilotRefreshTransport rewrites
191191 // the host on every request based on the freshly-issued token.
192192 return &openaiClient{
193- apiKey: pat, // unused at the wire level (transport overrides Auth) but kept for parity
194- baseURL: "https://api.individual.githubcopilot.com",
195- name: "github-copilot",
196- http: httpClient,
193+ apiKey: pat, // unused at the wire level (transport overrides Auth) but kept for parity
194+ baseURL: "https://api.individual.githubcopilot.com",
195+ chatCompletionsPath: "/chat/completions",
196+ name: "github-copilot",
197+ http: httpClient,
197198 }
198199 }
@@ -190,9 +190,10 @@ func NewGithubCopilotClient(pat string) Client {
190 // Initial baseURL is a sane default; copilotRefreshTransport rewrites190 // Initial baseURL is a sane default; copilotRefreshTransport rewrites
191 // the host on every request based on the freshly-issued token.191 // the host on every request based on the freshly-issued token.
192 return &openaiClient{192 return &openaiClient{
193- apiKey: pat, // unused at the wire level (transport overrides Auth) but kept for parity193+ apiKey: pat, // unused at the wire level (transport overrides Auth) but kept for parity
194- baseURL: "https://api.individual.githubcopilot.com",194+ baseURL: "https://api.individual.githubcopilot.com",
195- name: "github-copilot",195+ chatCompletionsPath: "/chat/completions",
196- http: httpClient,196+ name: "github-copilot",
197+ http: httpClient,
197 }198 }
198 }199 }
M packages/provider/openai.go +15 -7
@@ -35,12 +35,13 @@ func chatCompletionsURL(baseURL string) string {
3535 }
3636
3737 type openaiClient struct {
38- apiKey string
39- baseURL string
40- name string
41- oauth bool // when true, apiKey actually holds an OAuth access token
42- headers map[string]string
43- http *http.Client
38+ apiKey string
39+ baseURL string
40+ chatCompletionsPath string
41+ name string
42+ oauth bool // when true, apiKey actually holds an OAuth access token
43+ headers map[string]string
44+ http *http.Client
4445 }
4546
4647 // NewOpenAI creates an OpenAI client using an API key. baseURL may be empty.
@@ -431,8 +432,15 @@ func buildOAIContentBlocks(blocks []Content, isError bool) []interface{} {
431432
432433 // ---- streaming ----
433434
435+func (c *openaiClient) chatCompletionsURL() string {
436+ if c.chatCompletionsPath != "" {
437+ return strings.TrimRight(c.baseURL, "/") + "/" + strings.TrimLeft(c.chatCompletionsPath, "/")
438+ }
439+ return chatCompletionsURL(c.baseURL)
440+}
441+
434442 func (c *openaiClient) Stream(ctx context.Context, req Request) (<-chan Event, error) {
435- endpoint := chatCompletionsURL(c.baseURL)
443+ endpoint := c.chatCompletionsURL()
436444 wire, err := c.buildRequest(req)
437445 if err != nil {
438446 return nil, err
@@ -35,12 +35,13 @@ func chatCompletionsURL(baseURL string) string {
35 }35 }
36 36
37 type openaiClient struct {37 type openaiClient struct {
38- apiKey string38+ apiKey string
39- baseURL string39+ baseURL string
40- name string40+ chatCompletionsPath string
41- oauth bool // when true, apiKey actually holds an OAuth access token41+ name string
42- headers map[string]string42+ oauth bool // when true, apiKey actually holds an OAuth access token
43- http *http.Client43+ headers map[string]string
44+ http *http.Client
44 }45 }
45 46
46 // NewOpenAI creates an OpenAI client using an API key. baseURL may be empty.47 // NewOpenAI creates an OpenAI client using an API key. baseURL may be empty.
@@ -431,8 +432,15 @@ func buildOAIContentBlocks(blocks []Content, isError bool) []interface{} {
431 432
432 // ---- streaming ----433 // ---- streaming ----
433 434
435+func (c *openaiClient) chatCompletionsURL() string {
436+ if c.chatCompletionsPath != "" {
437+ return strings.TrimRight(c.baseURL, "/") + "/" + strings.TrimLeft(c.chatCompletionsPath, "/")
438+ }
439+ return chatCompletionsURL(c.baseURL)
440+}
441+
434 func (c *openaiClient) Stream(ctx context.Context, req Request) (<-chan Event, error) {442 func (c *openaiClient) Stream(ctx context.Context, req Request) (<-chan Event, error) {
435- endpoint := chatCompletionsURL(c.baseURL)443+ endpoint := c.chatCompletionsURL()
436 wire, err := c.buildRequest(req)444 wire, err := c.buildRequest(req)
437 if err != nil {445 if err != nil {
438 return nil, err446 return nil, err
M packages/provider/openai_url_test.go +12 -0
@@ -38,3 +38,15 @@ func TestChatCompletionsURL(t *testing.T) {
3838 })
3939 }
4040 }
41+
42+func TestGithubCopilotChatCompletionsURL(t *testing.T) {
43+ client, ok := NewGithubCopilotClient("test-token").(*openaiClient)
44+ if !ok {
45+ t.Fatal("NewGithubCopilotClient did not return an openaiClient")
46+ }
47+
48+ const want = "https://api.individual.githubcopilot.com/chat/completions"
49+ if got := client.chatCompletionsURL(); got != want {
50+ t.Errorf("GitHub Copilot chat completions URL = %q, want %q", got, want)
51+ }
52+}
@@ -38,3 +38,15 @@ func TestChatCompletionsURL(t *testing.T) {
38 })38 })
39 }39 }
40 }40 }
41+
42+func TestGithubCopilotChatCompletionsURL(t *testing.T) {
43+ client, ok := NewGithubCopilotClient("test-token").(*openaiClient)
44+ if !ok {
45+ t.Fatal("NewGithubCopilotClient did not return an openaiClient")
46+ }
47+
48+ const want = "https://api.individual.githubcopilot.com/chat/completions"
49+ if got := client.chatCompletionsURL(); got != want {
50+ t.Errorf("GitHub Copilot chat completions URL = %q, want %q", got, want)
51+ }
52+}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 476

↑↓ moveenter openesc close