Skip to content

fix(openai): send Copilot-Integration-Id header for github-copilot#2475

Merged
dgageot merged 2 commits intodocker:mainfrom
dgageot:board/fix-for-docker-agent-github-issue-2471-1ee6aaca
Apr 27, 2026
Merged

fix(openai): send Copilot-Integration-Id header for github-copilot#2475
dgageot merged 2 commits intodocker:mainfrom
dgageot:board/fix-for-docker-agent-github-issue-2471-1ee6aaca

Conversation

@dgageot
Copy link
Copy Markdown
Member

@dgageot dgageot commented Apr 21, 2026

Summary

Fixes #2471. The built-in github-copilot provider was unusable because https://api.githubcopilot.com rejects requests without a Copilot-Integration-Id header (Bad Request). This PR adds the missing header and introduces a generic escape hatch for setting custom headers on any OpenAI-compatible provider.

Changes

Feature

  • provider_opts.http_headers — new map of string→string for setting custom HTTP headers on any OpenAI-compatible provider. Applied to both the HTTP/SSE path and the WebSocket transport (Responses API) so behavior is consistent.
  • github-copilot default — when the user hasn't set one, Copilot-Integration-Id: vscode-chat is automatically injected. Header names are compared case-insensitively via http.CanonicalHeaderKey, so a user-provided header (in any casing) wins.

Security

  • Header-injection protection — header values are sanitized (CR/LF stripped, whitespace trimmed) before hitting the wire, preventing CRLF-smuggling via malicious YAML (RFC 7230 §3.2).

Docs

  • New docs/providers/github-copilot/index.md page (setup, config, models, default header, override).
  • docs/_data/nav.yml and docs/providers/overview/index.md updated to surface GitHub Copilot.
  • New "Custom HTTP Headers" section in docs/configuration/models/index.md.
  • agent-schema.json mentions http_headers in the provider_opts description.
  • examples/github-copilot.yaml documents the override.

Usage

Out-of-the-box (header injected automatically):

```yaml
models:
copilot:
provider: github-copilot
model: gpt-4o
```

With an override (e.g. a different integration id for an enterprise):

```yaml
models:
copilot:
provider: github-copilot
model: gpt-4o
provider_opts:
http_headers:
Copilot-Integration-Id: my-custom-integration
```

Tests

Unit tests cover:

  • `http_headers` parsing, including invalid types being logged & skipped.
  • Default `Copilot-Integration-Id` injection for `github-copilot`, and user-override winning case-insensitively.
  • Non-copilot providers never receive the default.
  • CRLF sanitization (unit + end-to-end via `httptest.Server`).
  • `buildHeaderMap` sharing between the HTTP and WebSocket paths.

Validation

  • `go build ./...` ✅
  • `go test ./...` ✅
  • `golangci-lint run ./...` — 0 issues

Fixes #2471


Assisted-By: docker-agent

gtardif
gtardif previously approved these changes Apr 23, 2026
dgageot added 2 commits April 27, 2026 13:34
GitHub Copilot's API (https://api.githubcopilot.com) rejects requests
that don't carry a `Copilot-Integration-Id` header with a `Bad Request`
error, making the built-in `github-copilot` provider unusable out of
the box.

This change:

- Adds a generic `provider_opts.http_headers` escape hatch on
  OpenAI-compatible providers for injecting custom HTTP headers,
  applied to both the HTTP/SSE and WebSocket transport paths.
- Automatically sets `Copilot-Integration-Id: vscode-chat` when the
  provider is `github-copilot` and the user has not overridden it
  (header names are compared case-insensitively via
  `http.CanonicalHeaderKey`).
- Sanitizes header values to strip CR/LF characters, preventing
  header injection via malicious YAML config (RFC 7230 §3.2).
- Documents the new option in a dedicated provider page, the
  providers overview, the Model Configuration reference, the agent
  schema, and the `examples/github-copilot.yaml` example.

Unit tests cover parsing, case-insensitive override, default
injection, sanitization, and an end-to-end assertion using an
`httptest.Server` to verify the headers actually reach the wire.

Fixes docker#2471

Assisted-By: docker-agent
Issue docker#2471 reporter confirmed that the previous default 'vscode-chat'

is rejected by the GitHub Copilot API when authenticating with a

Personal Access Token (the most common docker-agent setup).

'copilot-developer-cli' is accepted for both OAuth tokens and PATs,

so it makes the github-copilot provider usable out of the box without

any extra configuration. This also fixes interactive sessions where

switching between copilot models would otherwise hit Bad Request

responses on every freshly-instantiated client.

Users who need a different integration id can still override it via

provider_opts.http_headers (the override path is unchanged).

Assisted-By: docker-agent
@dgageot dgageot force-pushed the board/fix-for-docker-agent-github-issue-2471-1ee6aaca branch from ace3d13 to 1dd99e4 Compare April 27, 2026 11:36
@dgageot dgageot merged commit 65ffca2 into docker:main Apr 27, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ability to set the Copilot-Integration-Id header for github-copilot provider

2 participants