Skip to content

openaiResponses

OpenAI Responses API <-> Chat Completions translation.

Some clients speak only the Responses API (POST /v1/responses) - the Codex CLI is the motivating one. Databricks now also exposes native Responses surfaces (/serving-endpoints/responses and /serving-endpoints/open-responses), while most endpoints still speak Chat Completions at /invocations. This module bridges the two, in both directions:

  • responsesToChat lowers a Responses request body to a chat completions body (instructions -> system message, typed input items -> messages, tools/tool_choice carried through, function-call outputs folded back into the transcript).
  • chatToResponsesRequest raises a chat-completions request into a Responses request (the inverse of responsesToChat), for routing a chat client at a Responses-only model like Codex.
  • chatToResponse lifts a non-streaming chat completion back into a Responses response object.
  • responseToChatCompletion lifts a native Responses response back into a chat-completions body (the inverse of chatToResponse).
  • createResponsesStreamTranslator lifts a streaming chat completion (an OpenAI SSE chat.completion.chunk stream) into the Responses SSE event stream those clients consume (response.created, response.output_text.delta, function-call argument deltas, response.completed).
  • readResponsesOutput reads the other direction: pull the answer text and citations out of a response object returned by an endpoint that speaks Responses natively (the Databricks native web-search tool).
  • sanitizeResponsesTools keeps only function tools on a Responses request body (for /open-responses / Anthropic, which reject Codex built-ins like web_search).
  • sanitizeOpenResponsesInput rewrites output_* content part types in input to input_*, and drops Claude thinking / reasoning blocks that Open Responses rejects on replay (redacted_thinking, …).
  • repairTrailingAssistantInput drops a trailing assistant turn that Anthropic reads as a prefill request, the Responses-side counterpart to @dbx-tools/appkit-mastra’s repairAssistantPrefill.

Only the surface real clients exercise is translated; unknown fields are ignored rather than rejected, so a newer client degrades instead of breaking.

Browser-safe: pure functions over plain JSON, no transport and no Node built-ins, so the same translation runs in a proxy, a server route, or a test.