Skip to content

feat(providers): translate chat completions onto Responses-only upstreams - #1086

Draft
weselben wants to merge 6 commits into
mainfrom
feat/chat-via-responses
Draft

weselben wants to merge 6 commits into
mainfrom
feat/chat-via-responses

Conversation

@weselben

@weselben weselben commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

TL;DR

The chatgpt provider answers every chat completions request with 501 unsupported_provider_operation, so chat-only harnesses and mixed virtual-model pools cannot use ChatGPT subscription models. Adds the inverse of the existing ResponsesViaChat adapter: chat requests translate onto the Responses API upstream, and Responses streams translate back to chat chunks.

Closes #1084. Part of #723. Follow-up for the Messages ingress: #1085.

Files to review (12, +3228 / -26):

File Why
internal/providers/chat_via_responses.go (start here) Entry points ChatViaResponses / StreamChatViaResponses, request mapping, and the rejection rules.
internal/providers/chat_via_responses_input.go Messages to Responses input items. System messages become instructions. Tool calls become function_call items.
internal/providers/chat_via_responses_output.go Responses output back to one chat choice. Mints the chatcmpl- ID. Renames usage fields.
internal/providers/chat_via_responses_stream.go Responses SSE to chat chunks. The state machine lives here.
internal/providers/chatgpt/chatgpt.go Wiring. Chat surface delegates to the adapter. Embeddings stay 501.
docs/providers/chatgpt.mdx, docs/providers/overview.mdx Rejection list, drop table, capability matrix.
*_test.go (4 files) Mapping, rejection, and streaming cases.

How

  • Translation follows the mirror adapter. Same package, same naming, same error style.
  • Parameters without a Responses equivalent fail with a 400 that names the field, before any upstream call: n > 1, logit_bias, stop, seed, both penalties, logprobs, top_logprobs, modalities, audio, web_search_options, deprecated functions / function_call. Explicit JSON nulls pass. prediction and n: 1 are stripped, not rejected.
  • The Codex backend pins store: false and rejects previous_response_id. Minted chatcmpl- IDs are labels, not handles. No chaining exists. Chat clients resend full history as usual.

Reviewer notes

  • Fast-fail 400 is not failover-eligible. Default policy retries 429 and 5xx only. A bad request fails once, in place.
  • response.failed on the non-streaming path returns a 502 provider error. Without the check it would surface as a 200 with empty content.
  • temperature and max_tokens map to valid Responses fields, then Codex drops them upstream. Same behavior as the native Responses path onto this backend. Documented in docs/providers/chatgpt.mdx.
  • Usage accounting works on both paths. The stream converter emits the usage chunk only when the client asked or the enforcement flag is on.
  • Focus area: the item tracking in chat_via_responses_stream.go — item_id to dense tool_calls[].index mapping under interleaved parallel calls.

Tests

go build ./... and go test ./... pass. New tests cover every mapped field, every rejected field (typed and via ExtraFields), null tolerance, parallel tool calls, refusal, the finish-reason table, truncation, mid-stream failure, usage gating, and ID stability. A wiring test locks the chatgpt delegation with zero network calls.

One pre-existing local failure is unrelated: internal/testconventions scans .worktrees/ directories and lints other branches' files. Fixed separately in #1087.

Follow-up


This PR description was generated with AI assistance.

@mintlify

mintlify Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
gomodel 🟢 Ready View Preview Sep 30, 2026, 6:37 PM

💡 Tip: Enable Automations to automatically generate PRs for you.

@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov-commenter

codecov-commenter commented Sep 23, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 96.93593% with 22 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/providers/chat_via_responses_stream.go 94.98% 15 Missing ⚠️
internal/providers/chat_via_responses.go 97.59% 4 Missing ⚠️
internal/providers/chat_via_responses_input.go 98.83% 2 Missing ⚠️
internal/providers/chat_via_responses_output.go 98.73% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

This branch was successfully deployed

1 active deployment
staging - docs — c72ac355 Deployed Sep 30, 2026 by mintlify[bot]
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.

feat(providers): translate chat completions onto Responses-only upstreams (chatgpt/Codex backend)

2 participants