[PR #8900] feat(opencode): add copilot specific provider to properly handle copilot reasoning tokens #12906

Closed
opened 2026-02-16 18:17:47 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/8900

State: closed
Merged: Yes


What does this PR do?

This PR adds a copilot specific provider for the copilot completions API (there's already copilot specific code for the responses API). The code already states that this code is only meant for copilot, so I decided to rename the folder accordingly for clarity. While it would be great to not need this, I currently don't see a way to not have the copilot specifics (apart from extracting it into a separate repository).

It is similar to https://github.com/anomalyco/opencode/pull/5346, but it changes the completions code to properly store the reasoning_opaque field and send it back to the copilot API.

This PR is based on code I wrote for tidewave. I used Claude to implement the same changes based on a fresh copy of the upstream openai-compatible provider: https://github.com/vercel/ai/tree/%40ai-sdk/openai-compatible%401.0.30/packages/openai-compatible/src/chat

There are multiple small commits to make reviewing this easier and I also added tests for the important cases I encountered when handling the reasoning fields.

In the past, the Copilot API failed if the reasoning signature (reasoning_opaque) was not sent back for the Gemini 3 models. At some point GitHub seems to have changed this. Note though that the models still behave differently if the reasoning tokens are not passed back. For example, in Tidewave we've often seen Copilot's Gemini 2.5 spiral into a loop when omitting the reasoning, while it doesn't do that when including those.

How did you verify your code works?

You can chat with Gemini 2.5 Pro (3 Pro Preview is currently broken because of https://github.com/anomalyco/opencode/issues/8829, but it works in the Tidewave version of the code and all the fields are the same).

image

Closes https://github.com/anomalyco/opencode/issues/6864.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/8900 **State:** closed **Merged:** Yes --- ### What does this PR do? This PR adds a copilot specific provider for the copilot completions API (there's already copilot specific code for the responses API). The code already states that this code is only meant for copilot, so I decided to rename the folder accordingly for clarity. While it would be great to not need this, I currently don't see a way to not have the copilot specifics (apart from extracting it into a separate repository). It is similar to https://github.com/anomalyco/opencode/pull/5346, but it changes the completions code to properly store the `reasoning_opaque` field and send it back to the copilot API. This PR is based on code I wrote for [tidewave](https://tidewave.ai/). I used Claude to implement the same changes based on a fresh copy of the upstream openai-compatible provider: https://github.com/vercel/ai/tree/%40ai-sdk/openai-compatible%401.0.30/packages/openai-compatible/src/chat There are multiple small commits to make reviewing this easier and I also added tests for the important cases I encountered when handling the reasoning fields. In the past, the Copilot API failed if the reasoning signature (`reasoning_opaque`) was not sent back for the Gemini 3 models. At some point GitHub seems to have changed this. Note though that the models still behave differently if the reasoning tokens are not passed back. For example, in Tidewave we've often seen Copilot's Gemini 2.5 spiral into a loop when omitting the reasoning, while it doesn't do that when including those. ### How did you verify your code works? You can chat with Gemini 2.5 Pro (3 Pro Preview is currently broken because of https://github.com/anomalyco/opencode/issues/8829, but it works in the Tidewave version of the code and all the fields are the same). <img width="985" height="541" alt="image" src="https://github.com/user-attachments/assets/50e7332f-56ce-4808-b58f-6bffa607b071" /> Closes https://github.com/anomalyco/opencode/issues/6864.
yindo added the pull-request label 2026-02-16 18:17:47 -05:00
yindo closed this issue 2026-02-16 18:17:47 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12906