feat(gateway): add OpenAI Responses API endpoints (#1656)

* feat(gateway): add OpenAI Responses API endpoints

Add POST /v1/responses and GET /v1/responses/{id} to the web gateway,
implementing the OpenAI Responses API. Unlike the existing Chat
Completions proxy which passes through to the raw LLM, the Responses
API routes requests through the full agent loop — giving external
clients access to tools, memory, safety, and server-side conversation
state via a standard OpenAI-compatible interface.

Key design decisions:
- Response IDs encode thread UUIDs statelessly (resp_{uuid_simple})
- previous_response_id enables multi-turn conversations
- Streaming maps AppEvent variants to Responses API SSE events
- Tool approval returns response.failed (no interactive approval flow)
- GET endpoint reconstructs ResponseObject from conversation_messages

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* fix(responses-api): address all review feedback on PR #1656

- Decouple response ID from thread ID: encode both a per-call
  response_uuid and the thread_uuid so each POST produces a unique ID
- Reject unsupported fields (instructions, tools, tool_choice,
  temperature, max_output_tokens, non-default model) with 400
- Add user_id to IncomingMessage metadata for user-scoped SSE events
- Add conversation_belongs_to_user() ownership check on GET endpoint
- Fix tool call parsing: handle both legacy array and object wrapper
  format; use call_id/tool_call_id/id key fallback chain
- Correlate tool role messages to preceding FunctionCall call_id
- Stabilize created_at (capture once in accumulator, reuse everywhere)
- Surface error_message via new ResponseObject.error field
- Handle streaming tool failures (emit FunctionCallOutput on error)
- Remove dead Incomplete status variant
- Fix formatting (cargo fmt)

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
This commit is contained in:
Illia Polosukhin
2026-03-27 00:00:25 -07:00
committed by GitHub
co-authored by Claude Opus 4.6
parent 45cd6682d3
commit 9c5ba43ccd
3 changed files with 1421 additions and 0 deletions
+1
View File
@@ -18,6 +18,7 @@ pub mod auth;
pub(crate) mod handlers; pub(crate) mod handlers;
pub mod log_layer; pub mod log_layer;
pub mod openai_compat; pub mod openai_compat;
pub mod responses_api;
pub mod server; pub mod server;
pub mod sse; pub mod sse;
pub mod types; pub mod types;
File diff suppressed because it is too large Load Diff
+9
View File
@@ -520,6 +520,15 @@ pub async fn start_server(
post(super::openai_compat::chat_completions_handler), post(super::openai_compat::chat_completions_handler),
) )
.route("/v1/models", get(super::openai_compat::models_handler)) .route("/v1/models", get(super::openai_compat::models_handler))
// OpenAI Responses API (routes through the full agent loop)
.route(
"/v1/responses",
post(super::responses_api::create_response_handler),
)
.route(
"/v1/responses/{id}",
get(super::responses_api::get_response_handler),
)
.route_layer(middleware::from_fn_with_state( .route_layer(middleware::from_fn_with_state(
auth_state.clone(), auth_state.clone(),
auth_middleware, auth_middleware,