Skip to content

feat(ai): support OpenAI Responses API channels - #15

Merged
gopkg-dev merged 1 commit into
mainfrom
fix/openai-responses-api
Nov 26, 2026
Merged

gopkg-dev merged 1 commit into
mainfrom
fix/openai-responses-api

Conversation

@gopkg-dev

@gopkg-dev gopkg-dev commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Why

Closes #14.

The AI assistant's OpenAI channel always called {Base URL}/chat/completions and sent tools together with reasoning_effort. Models such as gpt-6.2-sol reject that combination on Chat Completions and return 400, asking for /v1/responses instead. There was no way to pick the Responses API.

What

New channel provider: OpenAI Responses

  • New provider openai-responses, which calls {Base URL}/responses and /models.
  • The existing chat-completions provider is relabelled OpenAI Chat and behaves as before; stored channels need no migration.

AI assistant

  • Streaming Responses loop: text, reasoning summaries, function calls and usage.
  • Multi-round tool calls with store: false. Model output items (reasoning, messages, function calls) are passed back, followed by function_call_output.
  • reasoning and include: ['reasoning.encrypted_content'] are sent only when an effort is set, since non-reasoning models reject them.
  • Concurrency slots, rate-limit pauses, aborts, per-round usage records and the round limit work the same as the Chat loop.

Other AI features

  • Classification, summaries, JSON generation, the connection test and model listing support the new provider.
  • In JSON mode the system prompt goes into input as a developer message. The Responses API requires the word "json" in the input messages, and instructions doesn't count.

Official SDK

  • Both OpenAI providers now use the official openai SDK instead of hand-written HTTP and SSE parsing, the same way Anthropic already uses @anthropic-ai/sdk.
  • OpenAI Chat still reads the non-standard reasoning_content / reasoning deltas that OpenAI-compatible endpoints (DeepSeek, Qwen, etc.) send.
  • When no API key is set (e.g. local Ollama), no Authorization header is sent.
  • Requests now retry twice on 429 / 5xx / connection errors, like the Anthropic client. Model listing doesn't retry.
  • Error messages no longer repeat the HTTP status (502: 502 …).

UI and docs

  • Provider select, Base URL hint and effort options in the settings page; zh/en strings.
  • README and zh/en model docs updated.

Testing

  • pnpm typecheck passes.
  • pnpm test passes: server 189, web 18.
  • server/test/openai-responses.test.ts covers:
    • Responses request shape, including the JSON-mode developer message, and reasoning / include only when an effort is set
    • streamed text and reasoning, and a tool-call round trip that passes reasoning items back
    • response.failed / response.incomplete errors
    • non-streaming helpers and model listing
    • the OpenAI Chat streaming loop: reasoning_content, a tool call, and no auth header without a key
  • Checked locally against a real OpenAI-compatible relay: OpenAI Chat works (connection test passes with gemini-3.5-flash-lite). That relay doesn't support /responses (502 even for a minimal request). OpenAI Responses has not yet been verified end to end against a real gpt-6.2-sol endpoint.

Add an "OpenAI Responses" channel provider (openai-responses) that calls
{Base URL}/responses, so models such as gpt-6.2-sol can use function tools
with reasoning effort in the AI assistant. The existing chat completions
provider is relabelled "OpenAI Chat" and keeps working unchanged.

- Assistant: streaming Responses loop with multi-round function calls,
  store: false, and reasoning (plus encrypted reasoning content) only when
  an effort is set
- Classify / summaries / JSON generation / connection test / model list
  support the new provider; JSON mode puts the instructions in the input
  messages as required by the Responses API
- Use the official openai SDK for both OpenAI providers instead of
  hand-written HTTP and SSE parsing; keep reading reasoning_content from
  OpenAI-compatible endpoints and skip the auth header when no key is set
- Error messages no longer repeat the HTTP status code
- Settings UI, zh/en strings and docs updated; tests added

Closes #14
@gopkg-dev
gopkg-dev force-pushed the fix/openai-responses-api branch from 4ceb3ba to 163aedf Compare November 26, 2026 05:07
@gopkg-dev
gopkg-dev merged commit 151b7ef into main Nov 26, 2026
1 check passed
@gopkg-dev
gopkg-dev deleted the fix/openai-responses-api branch November 26, 2026 05:10
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.

使用 AI 助手时,工具调用返回 HTTP 400,OpenAI API

1 participant