fix(oauth): reach Copilot models served only over the Responses API
Merged
FE
2mo ago+394+394+012345678901234567890123456789-76-76-01234567890123456789
Fixes #778.
copilot() built its model with createOpenAICompatible(...).chatModel(modelId) for every id, so a model the Copilot plan serves only over its Responses API (gpt-6-luna, gpt-5.3-codex, grok-4.5, mai-code-1.1-flash) could not be called: /chat/completions answers 400 unsupported_api_for_model, while /responses succeeds. #767 marked those models in the listing and scoped the invocation as a follow-up; this is that follow-up.
What changed
copilot(modelId)stays synchronous and makes no network call while constructing. It returns a delegate that settles the protocol on the firstdoGenerate/doStreamfrom the plan'sGET /models, then hands the call to@ai-sdk/openai-compatible's chat model or@ai-sdk/openai's Responses model (wrapped withstore: false, aschatgpt()is).- The protocol comes from the model's
supported_endpointsonly, as invscode-copilot-chat. No endpoints or/chat/completionsnamed means chat;/responseswithout chat means Responses; anything else stays on chat and the vendor's error explains it. Plan policy plays no part:grok-4.5andgpt-5.3-codexcarry nopolicyyet work over Responses, and a disabled model fails identically on both endpoints. - Only a listing that was read is remembered. An error status, non-JSON body, network failure, or the listing's own 10s timeout sends that call over chat and the next call asks again, so one blip does not pin a Responses-only model to chat for the whole run.
- One lookup serves concurrent calls under its own timeout; a caller that aborts stops waiting without failing the others.
- A revoked login fails on the listing with the sign-in command instead of being read as "no listing" and retried on chat.
@ai-sdk/openaiis imported lazily, only when a Responses model is called. Without it, the call fails withMISCONFIGUREDnaming the package.e2e initnow adds it for the Copilot gateway.sendCopilotRequestreads the initiator and vision flag from Responses bodies too (input[],input_image); before, every Responses turn was labelledx-initiator: agentwith no vision header.withoutServerStoragemoved tosrc/oauth/responses.ts, shared bychatgpt()andcopilot().e2e models github-copilotmarks uncallable modelsno chat or responses(wasno chat completions); a disabled Responses model now readsnot enabledonly.
Verified
pnpm checkpasses; e2e unit tests: 165 files, 2370 passed.- Live, through
copilot()against a real Copilot plan (tests/live/oauth.ts: image + forced tool call):
| Model | Endpoints listed | Routed to | Result |
|---|---|---|---|
gpt-6-luna | /responses | responses | tool call ok |
gpt-5.3-codex | /responses, no policy | responses | tool call ok |
grok-4.5 | /responses, no policy | responses | ok with a 256px image; xAI rejects the 8x8 test PNG on either path |
claude-sonnet-5 | chat + messages | chat | tool call ok |
gpt-5.4 | chat + responses | chat | tool call ok |
- A 4-step reasoning tool loop over Responses with
store: falsecompletes ongpt-6-luna,gpt-5.3-codex,grok-4.5,mai-code-1.1-flash.
Open
- When a model lists both endpoints (
gpt-5.4,gpt-5-mini), chat wins so working models do not move.vscode-copilot-chatprefers Responses there. @ai-sdk/openaidecides "reasoning model" by name, sogrok-*/mai-*get noinclude: reasoning.encrypted_content.forceReasoningfrom the listing'sreasoning_effortworks live but showed no measurable gain; left as follow-up.