Skip to content

feat: Support OpenAI Responses API (/v1/responses)#34

Open
shohei81 wants to merge 7 commits into
RichardAtCT:mainfrom
shohei81:feat/responses-api
Open

feat: Support OpenAI Responses API (/v1/responses)#34
shohei81 wants to merge 7 commits into
RichardAtCT:mainfrom
shohei81:feat/responses-api

Conversation

@shohei81

Copy link
Copy Markdown

Summary

This PR adds basic support for the OpenAI /v1/responses API, including
optional streaming support, to improve compatibility with newer OpenAI-based
tooling.

The implementation is intentionally minimal and scoped to:

  • Mapping /v1/responses requests into the existing Claude execution flow
  • Handling streaming responses in an SSE-compatible manner

This work addresses the feature request discussed in #21.

What’s included

  • /v1/responses endpoint support
  • Streaming responses (SSE-style)
  • No breaking changes to existing endpoints

Testing

  • Automated tests: Existing pytest suite passes successfully

No new tests were added in this PR; the change is covered by existing tests.

Notes

If this direction aligns with the project’s design goals, I’m happy to:

  • Adjust the API surface or naming
  • Reduce or expand the supported response fields
  • Split this work into smaller PRs if preferred

Fixes #21

shohei81 and others added 7 commits January 17, 2026 12:57
Why: CI lint step (`black --check src tests`) was failing on src/main.py,
which blocked the rest of the matrix (test/type-check/security/pytest all
got skipped on Python 3.10/3.11/3.12).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…es API

Minimum spec-compliance fixes for /v1/responses:

- Streaming: emit the full SSE event sequence per spec
  (response.created → in_progress → output_item.added →
   content_part.added → output_text.delta×N → output_text.done →
   content_part.done → output_item.done → completed). Each event now
  carries `type` + monotonic `sequence_number`, and the response object
  is nested under the `response` key as required by OpenAI SDK clients.
- Add `output_text` to the final streaming response object so clients
  see the same flattened text field they get from non-streaming.
- Map `previous_response_id` → internal session_id so real Responses
  API clients can chain conversations without using our custom
  `session_id` field.
- `_build_responses_output` now includes `status` and `annotations`
  on the message/output_text items (used by both streaming and
  non-streaming responses).

Why minimum: refactoring the duplicated chat/responses pipeline is out
of scope here; these changes only shift the surface to match what
OpenAI clients actually expect, without touching the core Claude
execution path.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Non-streaming response was returning `created` (Chat Completions field
name), causing the OpenAI SDK Responses model to fail validation since
it expects `created_at`. Streaming already uses `created_at`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

Support /v1/responses API

1 participant