Skip to content

fix(providers): support GPT-5 models on GitHub Copilot backend - #3380

Merged
Re-bin merged 1 commit into
HKUDS:mainfrom
gongpx20069:fix/github-copilot-gpt5-support
Apr 22, 2026
Merged

Re-bin merged 1 commit into
HKUDS:mainfrom
gongpx20069:fix/github-copilot-gpt5-support

Conversation

@gongpx20069

@gongpx20069 gongpx20069 commented Apr 22, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Calling GitHub Copilot with gpt-5.* / o* models (e.g. github_copilot/gpt-5.4, github_copilot/gpt-5.4-mini) failed with a chain of misleading errors:

  1. Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead.
  2. model "gpt-5.4-mini" is not accessible via the /chat/completions endpoint (unsupported_api_for_model)
  3. The requested model is not supported. (model_not_supported) even after routing to /responses

Each error masked the next, making it impossible to use any GPT-5/o-series model through the GitHub Copilot backend.

Root causes

  • max_tokens parameter: The github_copilot ProviderSpec did not opt into supports_max_completion_tokens, so _build_kwargs always sent the legacy max_tokens parameter that GPT-5/o-series reject.
  • Wrong endpoint: _should_use_responses_api was hard-gated to spec.name == "openai" plus a direct-OpenAI base URL, so the GitHub Copilot backend always went through /chat/completions even for models the Copilot gateway exposes only via /responses (e.g. gpt-5.4-mini, gpt-5.*-codex).
  • Silent fallback hid real errors: When /responses failed on github_copilot, the existing "compatibility marker" heuristic silently fell back to /chat/completions — which can never succeed for these models — so the real upstream error was hidden.
  • Model prefix not stripped on /responses: _build_responses_body did not honour spec.strip_model_prefix, so the request body sent model="github_copilot/gpt-5.4-mini" (with the routing prefix), which the Copilot gateway rejects with model_not_supported. (_build_kwargs already stripped it; this branch was missed.)

Fix

nanobot/providers/registry.py

  • Set supports_max_completion_tokens=True on the github_copilot spec so requests use max_completion_tokens.

nanobot/providers/openai_compat_provider.py

  • _should_use_responses_api now also allows the github_copilot spec, and skips the direct-OpenAI base check for it (the Copilot gateway is its own base URL).
  • _build_responses_body now strips the model routing prefix when spec.strip_model_prefix is set, matching _build_kwargs.
  • chat / chat_stream no longer fall back from /responses to /chat/completions on the github_copilot spec: the fallback cannot succeed for GPT-5/o-series and would mask the real gateway error.

Tests

  • tests/cli/test_commands.py: switched the test_github_copilot_provider_refreshes_client_api_key_before_chat fixture model from gpt-5.1 to gpt-4 so it continues to exercise the /chat/completions code path it was designed for (gpt-5.1 now correctly routes to /responses on github_copilot).

  • pytest tests/providers/ tests/cli/test_commands.py — 314 passed.

  • Verified end-to-end against the live Copilot gateway with all GPT-5 family models:

    Model Endpoints exposed by Copilot Result
    gpt-5-mini chat + responses ✅
    gpt-5.2 chat + responses ✅
    gpt-5.4 chat + responses ✅
    gpt-5.4-mini responses only ✅
    gpt-5.2-codex responses only ✅
    gpt-5.3-codex responses only ✅

…models

Calling GitHub Copilot with `gpt-5.*` / `o*` models (e.g.
`github_copilot/gpt-5.4`, `github_copilot/gpt-5.4-mini`) failed with a
chain of misleading errors:

  1. `Unsupported parameter: 'max_tokens' is not supported with this
     model. Use 'max_completion_tokens' instead.`
  2. `model "gpt-5.4-mini" is not accessible via the /chat/completions
     endpoint` (`unsupported_api_for_model`).
  3. `The requested model is not supported.` (`model_not_supported`)
     even after routing to /responses.

Root causes (each one masked the next):

  * The `github_copilot` ProviderSpec did not opt into
    `supports_max_completion_tokens`, so `_build_kwargs` always sent the
    legacy `max_tokens` parameter that GPT-5/o-series reject.
  * `_should_use_responses_api` was hard-gated to
    `spec.name == "openai"` plus a direct-OpenAI base URL, so the
    GitHub Copilot backend always went through /chat/completions even
    for models the Copilot gateway exposes only via /responses
    (e.g. `gpt-5.4-mini`).
  * When /responses did fail on github_copilot, the existing
    "compatibility marker" heuristic silently fell back to
    /chat/completions — which can never succeed for these models — so
    the real upstream error was hidden.
  * `_build_responses_body` did not honour `spec.strip_model_prefix`,
    so the request body sent `model="github_copilot/gpt-5.4-mini"`
    (with the routing prefix), which the Copilot gateway rejects with
    `model_not_supported`. (`_build_kwargs` already stripped it; this
    branch was missed.)

Fix:

  * registry.py: set `supports_max_completion_tokens=True` on the
    `github_copilot` spec so requests use `max_completion_tokens`.
  * openai_compat_provider.py:
      - `_should_use_responses_api` now also allows the
        `github_copilot` spec, and skips the direct-OpenAI base check
        for it (the Copilot gateway is its own base URL).
      - `_build_responses_body` now strips the model routing prefix
        when `spec.strip_model_prefix` is set, matching `_build_kwargs`.
      - `chat` / `chat_stream` no longer fall back from /responses to
        /chat/completions on the `github_copilot` spec: the fallback
        cannot succeed for GPT-5/o-series and would mask the real
        gateway error.

Tests:

  * tests/cli/test_commands.py: switched the
    `test_github_copilot_provider_refreshes_client_api_key_before_chat`
    fixture model from `gpt-5.1` to `gpt-4` so it continues to exercise
    the /chat/completions code path it was designed for (gpt-5.1 now
    correctly routes to /responses on github_copilot).
  * `pytest tests/providers/ tests/cli/test_commands.py` — 314 passed.
  * Verified end-to-end against the live Copilot gateway with both
    `github_copilot/gpt-5.4` and `github_copilot/gpt-5.4-mini`.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@gongpx20069

Copy link
Copy Markdown
Contributor Author

Hi @Re-bin could you help review this PR? the nanobot won't work by gpt-5x models of gh copilot provider without the fix. Thanks

Re-bin added a commit that referenced this pull request Apr 22, 2026
…port

fix(providers): support GPT-5 models on GitHub Copilot backend

Co-authored-by: gongpx20069 <21985921+gongpx20069@users.noreply.github.com>
@Re-bin
Re-bin merged commit dd26b44 into HKUDS:main Apr 22, 2026
8 checks passed
@gongpx20069
gongpx20069 deleted the fix/github-copilot-gpt5-support branch April 22, 2026 06:59
MaoChen1980 pushed a commit to MaoChen1980/nanobot-mg that referenced this pull request May 18, 2026
…5-support

fix(providers): support GPT-5 models on GitHub Copilot backend

Co-authored-by: gongpx20069 <21985921+gongpx20069@users.noreply.github.com>
StefanoParadisi pushed a commit to StefanoHernandez/nanobot that referenced this pull request Oct 16, 2026
…5-support

fix(providers): support GPT-5 models on GitHub Copilot backend

Co-authored-by: gongpx20069 <21985921+gongpx20069@users.noreply.github.com>
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.

2 participants