Skip to content

Support the OpenAI Responses API - #67

Merged
alexey-milovidov merged 8 commits into
mainfrom
openai-responses-api
Nov 27, 2026
Merged

alexey-milovidov merged 8 commits into
mainfrom
openai-responses-api

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Adds support for the OpenAI Responses API (POST /v1/responses). The current OpenAI frontier models (gpt-6.2-astra, gpt-6.2-sol, gpt-6.1-terra, gpt-6-luna) support tool calling only through the Responses API, and until now the SDK only spoke Chat Completions.

Depends on: #64 (the model catalog update). This branch is based on it, so its commits show up here until it is merged.

Closes: #44

How you pick the API

  • New ai::openai::create_responses_client(...) overloads, the same set as create_client, plus try_create_responses_client. They return an OpenAIResponsesClient with its own request builder, response parser and SSE stream (openai_responses_*.cpp).
  • create_client stays on Chat Completions, so OpenAI-compatible providers (OpenRouter and others) keep working. Neither client falls back to the other API.
  • New models::kDefaultResponsesModel = kGpt62Sol. kDefaultModel does not change.

Request mapping

  • input items: the messages, function_call items and function_call_output items. system goes to instructions.
  • Tools are flat: {type: "function", name, description, parameters, strict: false}. strict: false keeps the non-strict Chat Completions behaviour, because otherwise the API attempts strict mode.
  • tool_choice maps to auto, required, none or {type: "function", name}.
  • max_tokens becomes max_output_tokens. response_format becomes text.format, and the Chat Completions json_schema wrapper is flattened.
  • reasoning.effort uses the lowest accepted effort. That helper and the rule that leaves out temperature/top_p for GPT-5/6 now live in openai_model_traits.cpp and are shared with the Chat Completions builder.
  • frequency_penalty, presence_penalty and seed do not exist in the Responses API. They are left out and a warning is logged.

How reasoning items are carried

  • Requests are stateless (store: false). In that mode the API returns encrypted_content on reasoning items by default, and the current docs call include: ["reasoning.encrypted_content"] legacy, so it is not sent.
  • The parser returns the assistant turn in response_messages with the output items in their original order: TextContentPart, ToolCallContentPart, and a new ai::ProviderContentPart{provider, data}. That new part holds each reasoning item verbatim, plus the fc_... item ID of each function call.
  • The Responses builder replays these parts. Other providers ignore them.
  • MultiStepCoordinator now feeds back a provider-built turn as is when that turn contains the tool calls. Chat Completions and Anthropic never return tool calls in response_messages, so they behave as before.
  • A turn that has only reasoning is dropped, because a replayed reasoning item has to be followed by the item it produced.

Response parsing and streaming

  • status/incomplete_details.reason map to the finish reason: max_output_tokens → length, content_filter → content filter, function calls → tool_calls. failed and other incomplete reasons become errors.
  • Usage comes from input_tokens/output_tokens/total_tokens.
  • The stream handles response.output_text.delta, response.output_item.added/.done, response.function_call_arguments.delta/.done, response.completed/.incomplete/.failed and error. A stream that ends without a terminal event is reported as an error.

Tests, example, docs

  • Unit tests in tests/unit/openai_responses_test.cpp: request building, parsing, stream events, and a multi-step loop that checks the reasoning item reaches the follow-up request.
  • Integration tests in tests/integration/openai_responses_integration_test.cpp: tool calling on gpt-6.2-sol, a multi-step tool loop with a follow-up turn, structured output, streaming text and tool calls.
  • The parameterized ToolCallingIntegrationTest suite now also runs on openai_responses with gpt-6-luna.
  • New examples/openai_responses.cpp and a README section.

🤖 Generated with Claude Code


Note

Medium Risk
Touches core multi-step tool orchestration and adds a second OpenAI wire protocol; bugs could break GPT-6 tool loops or conversation replay, though Chat Completions and other providers are largely isolated.

Overview
Adds a parallel OpenAI integration path via ai::openai::create_responses_client (and matching overloads / try_create_responses_client) that talks to POST /v1/responses instead of Chat Completions. Chat Completions create_client is unchanged; neither client falls back to the other, which keeps OpenAI-compatible providers on the existing API.

The Responses stack includes dedicated client, request builder, response parser, and SSE stream code. Requests are stateless (store: false), map SDK options to Responses fields (instructions, input, max_output_tokens, text.format, flat function tools with strict: false), and shared openai_model_traits logic for GPT-5/6 reasoning effort and sampling omissions.

Reasoning replay for multi-step tools: responses can include reasoning and function-call item IDs, stored in a new ProviderContentPart on assistant messages. The Responses builder replays them in order on follow-up requests; MultiStepCoordinator now forwards provider-built assistant turns (with tool calls) verbatim instead of reconstructing them, so reasoning state survives max_steps loops and manual continuations from response_messages.

Also refreshes model constants (GPT-6, Anthropic 5.5 defaults), Anthropic refusal → content-filter finish reasons, docs/example openai_responses.cpp, and unit/integration tests for the Responses path.

Reviewed by Cursor Bugbot for commit 99508bd. Bugbot is set up for automated code reviews on this repo. Configure here.

alexey-milovidov and others added 6 commits November 27, 2026 00:30
Anthropic:
- Add `claude-fable-5-2`, `claude-opus-5-5`, `claude-sonnet-5-5`,
  `claude-haiku-5-5` and `claude-fable-5-1`; the default model is now
  `claude-sonnet-5-5`.
- Omit sampling parameters for `claude-haiku-5-5`, which rejects
  non-default values; the existing prefixes already cover the point
  releases of Opus 5, Fable 5 and Sonnet 5.
- Map the `refusal` stop reason to `kFinishReasonContentFilter` instead
  of `kFinishReasonStop`, both in responses and in streams.
- Document that the newest models reject a forced tool choice.

OpenAI:
- Add `gpt-6.2-astra`, `gpt-6.2-sol`, `gpt-6.1-terra` and `gpt-6-luna`.
- Treat the GPT-6 family as reasoning-first: omit sampling parameters,
  and send the lowest accepted `reasoning_effort` (`low`; `none` for
  `gpt-6-luna` and `gpt-6.1-terra`; GPT-6.2 rejects `none`).
- Note the shutdown dates of `gpt-5-mini`, `gpt-5-nano`, `gpt-4.1`,
  `gpt-4.1-mini` and `gpt-5.4-nano`.
- Keep `gpt-5.6` as the default: GPT-6 models support tool calling only
  through the Responses API, not Chat Completions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The GPT-6 models (`gpt-6.2-astra`, `gpt-6.2-sol`, `gpt-6.1-terra`,
`gpt-6-luna`) call tools only through the Responses API
(`POST /v1/responses`), while the SDK only spoke Chat Completions.

`ai::openai::create_responses_client` (with the same overloads as
`create_client`, plus `try_create_responses_client`) creates a client with
its own request builder, response parser, and SSE stream for the Responses
API. `create_client` stays on Chat Completions, which OpenAI-compatible
providers implement; neither falls back to the other API.

Requests are stateless (`store: false`). The `reasoning` items that a
reasoning model returns with its function calls must be sent back with the
tool outputs, so the parser returns the assistant turn in
`response_messages` with its items in their original order, carrying the
reasoning items (and the item IDs of the function calls) as a new
`ProviderContentPart`, which other providers ignore. The multi-step
coordinator feeds that turn back as is when it carries the tool calls.

The lowest accepted reasoning effort and the sampling parameter omission are
shared with the Chat Completions builder.

Closes: #44

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ersion in a test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 78171ee. Configure here.

alexey-milovidov and others added 2 commits November 27, 2026 02:44
… test

The step stops at the tool calls, so `TestAssertions::assertSuccess`, which
requires text, failed in CI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`max_output_tokens` counts reasoning tokens too, so a response can end as
`incomplete` after some of its function calls were completed. Those calls
are now executed and answered (finish reason `tool_calls`), while the
truncated ones (`status: incomplete`) are dropped instead of failing on
their cut-off arguments. A terminal step no longer keeps a provider-built
turn with tool calls in `response_messages`, because an unanswered
`function_call` cannot be replayed.

Reported by Cursor Bugbot in #67

Co-Authored-By: Claude Opus 5.5 <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.

Is support for OpenAI /v1/responses API planned?

1 participant