Skip to content

feat(gateway): OpenAI-compatible /v1/chat/completions HTTP endpoint - #680

Closed
steipete wants to merge 7 commits into
mainfrom
feat/gateway-openai-http-api
Closed

steipete wants to merge 7 commits into
mainfrom
feat/gateway-openai-http-api

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Adds an OpenAI-compatible Chat Completions HTTP endpoint on the gateway (same port), including SSE streaming.\n\n- New handler: src/gateway/openai-http.ts\n- Wired into HTTP server: src/gateway/server-http.ts\n- Docs: docs/gateway/openai-http-api.md (+ index link)\n- E2E tests hitting the real HTTP endpoint: src/gateway/openai-http.e2e.test.ts\n\nAuth: uses existing gateway auth via Authorization: Bearer <token/password>.\nAgent targeting: x-clawdbot-agent-id header (default main); optional x-clawdbot-session-key override; OpenAI user enables stable session key.

@cursor

cursor Bot commented Jan 10, 2026 •

Copy link
Copy Markdown

PR Summary

Introduces an OpenAI-compatible Chat Completions endpoint on the Gateway (same port, /v1/chat/completions) with authentication, agent selection, session handling, and SSE streaming.

  • New gateway/openai-http.ts handler; integrated into server-http.ts and server.ts (auth, 405 for non-POST, JSON validation, non-stream and SSE responses, agent via model or x-clawdbot-agent-id, session via x-clawdbot-session-key or stable user)
  • End-to-end tests for routing, auth errors, session keys, content extraction, non-stream response, SSE deltas and fallback: gateway/openai-http.e2e.test.ts
  • Docs: new gateway/openai-http-api.md, linked from gateway/index.md and navigation in docs.json
  • Provider patch updates (patches/@[email protected]): avoid replaying standalone reasoning for tool-only turns, set OpenAI tool strict:false, early-fail Gemini 429; corresponding test tweaks in agents/openai-responses.reasoning-replay.test.ts
  • Dependency state adjusted (lockfile and patchedDependencies cleaned up to only patch pi-ai)

Written by Cursor Bugbot for commit 8ecb0a8. This will update automatically on new commits. Configure here.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 97bd183c1a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +315 to +318
req.on("close", () => {
closed = true;
unsubscribe();
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Abort agent runs when HTTP client disconnects

The streaming handler only marks the request as closed and unsubscribes from events on req.close, but it never cancels the in-flight agentCommand that was started for the same request. If a client drops the SSE connection mid-run (network blip, user cancels, load balancer timeout), the agent continues executing tools and generating events anyway, wasting resources and potentially holding session locks longer than necessary. Other gateway chat paths pass an AbortSignal to agentCommand and cancel on disconnect; you should mirror that here by wiring an AbortController to the request close and passing abortSignal into agentCommand.

Useful? React with 👍 / 👎.

Comment thread src/gateway/openai-http.ts Resolved
}
if (role === "user") {
lastUser = content;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Multi-turn conversation history discarded in prompt building

Medium Severity

The buildAgentPrompt function only captures the last user message (via lastUser = content which overwrites previous user messages) and completely ignores assistant messages. When clients send multi-turn conversation history as expected in the OpenAI Chat Completions API, all prior context except system prompts and the final user message is silently discarded. This breaks conversational continuity for clients expecting standard OpenAI-compatible behavior.

Fix in Cursor Fix in Web

.map((p) => (typeof p.text === "string" ? p.text : ""))
.filter(Boolean)
.join("\n\n")
: "No response from Clawdbot.";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Empty response when payloads contain only empty text

Low Severity

The fallback message "No response from Clawdbot." is bypassed when payloads is a non-empty array but all payload texts are empty strings. The condition Array.isArray(payloads) && payloads.length > 0 checks if payloads exist, but after .filter(Boolean) removes empty strings, the resulting content becomes "". For example, if payloads = [{ text: "" }], the condition is true, but the processed result is an empty string instead of the intended fallback message. The same pattern appears in both the non-streaming and streaming fallback code paths.

Additional Locations (1)

Fix in Cursor Fix in Web

@steipete

Copy link
Copy Markdown
Contributor Author

Landed on \ via:\n- dafa8a2 feat(gateway): add OpenAI-compatible HTTP endpoint\n- 6d01d70 docs(gateway): add OpenAI HTTP API to docs nav\n- 72d4317 fix(docs): dedupe /sandbox redirects\n- 6546a1a feat(gateway): allow agent via model\n- 0d00d6d style(gateway): format openai-http\n- 67fdee6 docs(changelog): note OpenAI HTTP endpoint\n- d45c27e chore(protocol): regenerate GatewayModels.swift (fix protocol:check)\n\nNot landed: 96a6635 fix(pnpm): sync patchedDependencies (conflicted / not needed after upstream moved).\n

@steipete steipete closed this Jan 10, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Correction: that was main (previous comment ate backticks via shell).

@shakkernerd
shakkernerd deleted the feat/gateway-openai-http-api branch January 26, 2026 18:07
heatherstew44-maker pushed a commit to heatherstew44-maker/openclaw that referenced this pull request Mar 8, 2026

@andersoncollab andersoncollab 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.

Architect Review: APPROVED

@andersoncollab andersoncollab 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.

Architect Review: APPROVED

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.

2 participants