Skip to content

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

Open
dgageot wants to merge 1 commit intodocker:mainfrom
dgageot:board/fix-for-docker-agent-github-issue-2471-1ee6aaca
Open

fix(openai): send Copilot-Integration-Id header for github-copilot#2475
dgageot wants to merge 1 commit 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

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
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

1 participant