feat(responses): pad shape for openresponses spec#2173
feat(responses): pad shape for openresponses spec#2173steebchen merged 2 commits intotheopenco:mainfrom
Conversation
Pad the Responses API response object with all fields required by the Open Responses spec (openresponses.org): tools, tool_choice, truncation, parallel_tool_calls, text.format, top_p, temperature, reasoning, completed_at, incomplete_details, store, background, service_tier, safety_identifier, prompt_cache_key, and others. usage now always emits input_tokens_details.cached_tokens and output_tokens_details.reasoning_tokens. Streaming response.created, response.completed, and response.failed events share the same padded shape via a buildResponsePayload helper. The GET handler pads stored responses on read. Accepts the optional `phase` field on input messages. Adds openresponses-compliance.spec.ts with a vendored Zod schema mirroring the spec's ResponseResource required-fields list, exercising both conversion paths and the upstream mock fixture. Additive only — no field removals or type narrowings on existing fields.
|
Caution Review failedFailed to post review comments WalkthroughThis PR introduces Open Responses API compliance by expanding response shapes and conversion logic. Schema definitions gain optional message item fields; conversion functions are reworked to accept a request parameter and populate expanded response structures with echoed fields, detailed usage, and metadata; streaming state is enriched to track request context; and comprehensive compliance tests validate the new shapes. ChangesOpen Responses API Compliance
Sequence DiagramsequenceDiagram
participant Client
participant Gateway as /v1/responses
participant Converter as convertChatResponseToResponses
participant StreamState as createStreamingState
participant StateBuilder as buildResponsePayload
rect rgba(100, 150, 200, 0.5)
Note over Client,StateBuilder: Non-Streaming Path
Client->>Gateway: POST with chat completion + request fields
Gateway->>Converter: convertChatResponseToResponses(chatResp, responseId, request)
Converter->>Converter: Extract created timestamp
Converter->>Converter: Build ResponsesApiUsage with details
Converter->>Converter: Map echo fields from request
Converter-->>Gateway: ResponsesApiResponse
Gateway-->>Client: Response with echoed fields + usage details
end
rect rgba(150, 200, 100, 0.5)
Note over Client,StateBuilder: Streaming Path
Client->>Gateway: POST stream with chat completion + request fields
Gateway->>StreamState: createStreamingState(model, responseId, request)
StreamState-->>Gateway: StreamingState(request, usage)
loop Stream chunks
Gateway->>StateBuilder: buildResponsePayload(state, { status, output })
StateBuilder->>StateBuilder: Merge state.request fields into payload
StateBuilder->>StateBuilder: Populate usage with token details
StateBuilder-->>Gateway: response.created/response.completed payload
Gateway-->>Client: SSE event
end
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Summary
Pads the
/v1/responsesAPI output to satisfy the Open Responses spec’sResponseResourcerequired-fields list. Adds ~25 fields that were previously missing (tools,tool_choice,truncation,parallel_tool_calls,text.format,top_p,temperature,reasoning,completed_at,incomplete_details,store,background,service_tier,safety_identifier,prompt_cache_key, etc.) and always emitsusage.input_tokens_details.cached_tokensandusage.output_tokens_details.reasoning_tokens.Same padding applied to:
convertChatResponseToResponses)response.created/response.completed/response.failedpayloadsGET /v1/responses/:idAccepts the optional
phasefield on input messages.Compatibility
Additive only. No existing fields removed or retyped. Standard JSON / OpenAI-SDK clients are unaffected.
Summary by CodeRabbit
New Features
Tests