Skip to content

feat(openai): add native Responses API transport - #1

Merged
rktmeister merged 9 commits into
mainfrom
feat/openai-responses-api
Jul 22, 2026
Merged

feat(openai): add native Responses API transport#1
rktmeister merged 9 commits into
mainfrom
feat/openai-responses-api

Conversation

@rktmeister

Copy link
Copy Markdown
Owner

Summary

  • add an explicit OPENAI_API_FORMAT=responses transport alongside the existing Anthropic and Chat Completions paths
  • translate ncode messages, tools, tool results, streaming events, reasoning summaries, and usage to and from the Responses API
  • preserve opaque Responses output items in session transcripts so reasoning state survives subsequent turns and resume
  • route ncode compaction through /v1/responses/compact and replay the returned canonical output unchanged
  • keep the existing Chat Completions adapter and generic context-budget behavior unchanged

Why

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.ts
  • bun test src/services/api/openAICompatInferenceClient.test.ts
  • bun run build
  • git diff --check

The external build completed successfully and its security audit passed.

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
rktmeister marked this pull request as ready for review July 22, 2026 13:57
@rktmeister
rktmeister merged commit fa5212d into main Jul 22, 2026
3 checks passed
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.

1 participant