feat(openai): add native Responses API transport - #1
Merged
Conversation
Add an explicit Responses transport for OpenAI BYOK endpoints, preserve opaque response items across streamed turns and resume, and route compaction through /v1/responses/compact. Keep Anthropic and generic Chat Completions behavior unchanged unless OPENAI_API_FORMAT=responses is selected. Validated with focused transport/provider tests, the existing Chat Completions suite, and bun run build.
Preserve opaque response items without replay duplication, validate terminal stream events, and translate structured output, refusals, media, and tool constraints. Use native input-token counting and carry finalized usage through live progress and compaction accounting. Verified with 55 focused and compact-adjacent tests plus bun run build.
Build a schema-specific native compaction payload, delay streamed tool release until a terminal event, preserve opaque metadata-only responses, and distinguish content filtering from token exhaustion. Reject incompatible provider switches after native compaction instead of silently losing conversation state. Verified with 71 isolated relevant tests, bun run build, the external package security audit, and git diff --check.
Translate locally loaded deferred tools into client-executed Responses tool-search records instead of forwarding Anthropic-only tool_reference blocks. Keep compaction provider-neutral so Responses sessions remain portable across inference backends. Validated with 78 focused tests and bun run build.
Handle disabled reasoning and terminal response statuses explicitly, retry transient OpenAI-compatible rate limits, and keep opaque Responses state scoped to compatible models and providers. Preserve readable summaries across provider switches and document the input-token endpoint requirement. Validated with 63 focused tests and bun run build.
Classify terminal Responses failures separately from transport errors so only known transient failures retry and semantic stream failures never trigger unary fallback. Parse structured HTTP errors consistently for Responses and Chat Completions, and scope persisted opaque response state to its endpoint, model, and credential identity. Validated with 110 focused tests and bun run build.
Keep provider-supplied error details out of retry analytics while preserving local diagnostics, classify top-level quota responses correctly, and migrate legacy unscoped Responses metadata without replaying opaque state or sending unsigned thinking to Anthropic. Validated with 115 focused tests and bun run build.
Allowlist provider error identifiers before telemetry, classify quota failures across nested and top-level envelopes, and preserve paragraph boundaries while migrating legacy reasoning summaries. Validated with the focused 116-test Responses/API suite, bun run build, and git diff --check.
Retry transient Responses API errors that arrive after the SSE connection is established, while preserving the existing request-opening retry path. Fail closed once assistant output is committed so tool calls cannot execute twice, and reset provisional stream state before replacement attempts. Validated with focused Responses and retry suites (61 passing) and bun run build.
rktmeister
marked this pull request as ready for review
July 22, 2026 13:57
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
OPENAI_API_FORMAT=responsestransport alongside the existing Anthropic and Chat Completions paths/v1/responses/compactand replay the returned canonical output unchangedWhy
OpenAI reasoning models have a first-class Responses lifecycle. Sending them through Chat Completions loses native response items and prevents correct opaque compaction replay. This adds the native transport without changing behavior for Anthropic models or generic/local OpenAI-compatible endpoints.
Validation
bun test src/services/api/openAIResponsesInferenceClient.test.ts src/services/api/inferenceClient.test.ts src/utils/model/providers.test.ts src/utils/managedEnvConstants.test.ts src/services/compact/autoCompact.ncodeModels.test.tsbun test src/services/api/openAICompatInferenceClient.test.tsbun run buildgit diff --checkThe external build completed successfully and its security audit passed.