Skip to content

Add backward-compatible OpenAI Responses API support with opt-in env var#305

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/test-backward-compatibility
Draft

Add backward-compatible OpenAI Responses API support with opt-in env var#305
Copilot wants to merge 2 commits intomainfrom
copilot/test-backward-compatibility

Conversation

Copy link
Contributor

Copilot AI commented Feb 25, 2026

PR #277 proposed switching the default OpenAI endpoint from /chat/completions to /responses, but the change was incomplete: the Responses API has a different request format (input vs messages) and response shape (output[0].content[0].text vs choices[0].message.content), making the PR as-is a silent breaking change.

Changes

  • New export createOpenAIResponsesLanguageModel — mirrors createOpenAILanguageModel but targets the Responses API with the correct request/response handling:

    • Sends input (not messages) in the request body
    • Parses output[0].content[0].text from the response
    • Defaults to https://api.openai.com/v1/responses
  • createOpenAILanguageModel unchanged — still defaults to /chat/completions; no breakage for existing users or Azure OpenAI (which may not support /responses)

  • createLanguageModel opt-in flag — set OPENAI_USE_RESPONSES_API=true to route through the Responses API path; omitting it preserves the existing behavior

// Existing code — unchanged, backward compatible
const model = createOpenAILanguageModel(apiKey, "gpt-4");

// New: explicit Responses API
const model = createOpenAIResponsesLanguageModel(apiKey, "gpt-4");

// New: via env var in createLanguageModel
// OPENAI_USE_RESPONSES_API=true  →  uses /v1/responses
// (default)                      →  uses /v1/chat/completions
const model = createLanguageModel(process.env);
  • Tests — 16 unit tests added (typescript/tests/model.test.mjs) using Node's built-in node:test with mocked fetch, covering both API paths and createLanguageModel routing; "test" script added to package.json

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: robgruen <25374553+robgruen@users.noreply.github.com>
Copilot AI changed the title [WIP] Verify backward compatibility for PR#277 changes Add backward-compatible OpenAI Responses API support with opt-in env var Feb 25, 2026
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