Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for the OpenAI Responses API (/v1/responses) in the compat-oai plugin, enabling integration with models served exclusively over this transport (such as gpt-5-pro and o3-pro). It refactors common utilities into utils.ts and adds comprehensive unit and live integration tests. The reviewer feedback suggests replacing generic Error instances with framework-specific GenkitError classes across several validation checks in responses.ts to ensure consistent error handling and telemetry integration.
f276a29 to
b468a84
Compare
b468a84 to
d3bfa43
Compare
| // Silently ignoring the request would hand back a Chat Completions response | ||
| // to a caller who asked for something else. This builder is shared by every | ||
| // OpenAI-compatible provider, so the message stays provider-neutral. | ||
| if (transport === 'responses') { |
There was a problem hiding this comment.
This fires for deepSeek/xai too - none of the providers on this builder can speak the responses transport, and stripping the key silently seemed worse than rejecting it. Hence the provider-neutral message.
| response, | ||
| request.output?.format === 'json' | ||
| ); | ||
| // The Responses event protocol is not mapped yet, so a streaming caller |
There was a problem hiding this comment.
Weakest part of the slice: streaming callers get the final response as one chunk. Rejecting streaming outright would have made all eight models unusable in the Dev UI, which always streams. Event mapping is #6004.
|
Note: unit and fake-server coverage is in (146 tests, including wire assertions for both transports and an end-to-end generate() with an output schema), but the live smoke tests against the real API have not been run yet. Keeping this as draft until that's done. |
d3bfa43 to
0fec9ca
Compare
19a2136 to
5e64a0c
Compare
aeb498f to
446b9e4
Compare
446b9e4 to
715afb6
Compare
715afb6 to
1ca24c3
Compare
1ca24c3 to
7d20f35
Compare
Hey thanks! Yes I ran the live smoke tests against the API across the whole stack, all green:
Screenshots below. Before the stack is ready for review, I still need to answer adesinah's open threads on #6160. The live run confirmed a few of them (injected text order with context + output schema, Once #7201 lands I'll rebase the stack straight away.
|
… API Prepares the plugin to route some models over /v1/responses without changing anything about the models it serves today. A `transport` config key joins the plugin-level keys that the shared Chat Completions body builder destructures away, so it can never reach a wire that 400s on unrecognised arguments. Asking a Chat Completions model for `transport: 'responses'` is rejected outright rather than silently ignored, since opting a dual-transport model onto Responses is not available yet. The OpenAI APIError to GenkitError mapping and the media-part helpers move to utils.ts so a second runner can share them rather than fork them. `UNSUPPORTED_MODEL_MATCHERS` matched 'codex' as a bare substring, which hid gpt-5-codex, gpt-5.1-codex-max and codex-mini-latest from the model list along with the legacy code-* completion models it was aimed at. The matchers are now anchored patterns.
Eight OpenAI models - gpt-5-pro, the gpt-5/gpt-5.1 codex family, codex-mini-latest, o1-pro and o3-pro - are served only over /v1/responses and so cannot be reached through this plugin at all today. `RESPONSES_ONLY_MODELS` names them, and a single predicate over that const drives both the runtime routing and the `openAI.model()` type union. Any suffixed form of a curated name matches, so o3-pro-2025-06-10 and gpt-5-pro-preview route like their base rather than failing with an opaque OpenAI 400; unknown suffixes fail toward the transport that works. The runner mirrors the Chat Completions one: genkit messages become `input` items with system messages hoisted into `instructions`, output formats map onto `text.format`, unrecognised config keys pass through, and the response `output` items become parts. Prior model turns are serialized part by part rather than flattened to their text, so a structured-output turn replays as its JSON instead of as an empty assistant message. The models declare `constrained: 'all'` so genkit sends the output schema through `text.format` instead of simulating it in the prompt. `store` is pinned to false unless the caller sets it, so this transport retains no more data than the existing one. All eight models register through it, and the resolver, listActions and `openAI.model()` all route by the same predicate. Streaming, tool calling and the encrypted reasoning round-trip are not implemented yet. A streaming caller gets the completed response delivered as a single chunk; a request carrying tools, a response asking for a tool call, and a failed response carrying an `error` are all raised rather than quietly returned as an ordinary answer.
… json and unexplained failures Json-mode output truncated by max_output_tokens or a content filter left partial JSON in output_text; JSON.parse threw a raw SyntaxError instead of letting the finish reason report the truncation. Parse is now best-effort (JSON.parse, then parsePartialJson, then a text part). A failed response with a null error slipped past the status/error guard and surfaced as a successful empty completion; failed responses now always throw, with a generic message when the API omits the payload.
…d system messages config.instructions rode the passthrough spread, which lands after the instructions built from system messages - setting both silently dropped the system prompt. The two sources are now joined in order.
… output The Responses API validates json_schema formats under strict mode unless strict: false is sent - unlike Chat Completions, where strict defaults off. Genkit output schemas carry no additionalProperties: false, so every schema-bearing request 400ed with invalid_json_schema. Found by live smoke against gpt-5-pro; the fix was verified the same way.
… config Either key through the passthrough changes the response envelope out from under the non-streaming runner: the SDK hands back a Stream or a queued response, which fromOpenAIResponse reads as an empty message with a clean stop finish. Streaming belongs to Genkit's own streaming API and background responses are not supported yet, so both are rejected.
…sponses usage The Responses usage payload details reasoning and cached prompt tokens, and genkit's usage schema has thoughtsTokens and cachedContentTokens for them; a reasoning model's dominant token cost was reported nowhere.
… config Assigning body.text wholesale silently discarded a passthrough text object, so structured output could not be combined with e.g. verbosity; the reasoning and instructions fields already compose for the same reason.
…l lineup Adds gpt-5.2-pro, gpt-5.5-pro, gpt-5.2-codex and gpt-5.3-codex, all served exclusively over /v1/responses; the suffix bias cannot catch them from the existing bases (gpt-5.2-codex does not extend gpt-5-codex-), so without listing they routed to Chat Completions and failed with an opaque 400.
…, transport policy and docs
…repo's current Prettier
7d20f35 to
c02348b
Compare



Part of #6002, closes #6003. Design rationale: design notes on the tracking issue.
Adds a second OpenAI transport to the existing
openAI()plugin: the thirteen models OpenAI serves only over/v1/responses(gpt-5-pro,gpt-5.2-pro,gpt-5.4-pro,gpt-5.5-pro,gpt-5-codex,gpt-5.1-codex,gpt-5.1-codex-mini,gpt-5.1-codex-max,gpt-5.2-codex,gpt-5.3-codex,codex-mini-latest,o1-pro,o3-pro) now register and run against that endpoint, in the same namespace with the same action-name scheme. They were unreachable via this plugin before.RESPONSES_ONLY_MODELSconst drives the runtime routing predicate and theopenAI.model()type union; suffixed names (o3-pro-2025-06-10,gpt-5-pro-preview) route like their base, deliberately biased toward the transport that works.client.responses.create.storeis pinned tofalseunless set, keeping retention behavior identical to Chat Completions.supports.constrained: 'all', so output schemas go natively throughtext.formatinstead of genkit's simulated-constrained prompt injection. Non-object schema roots are wrapped and unwrapped the same way as on Chat Completions (fix(js/plugins/compat-oai): wrap non-object output schema roots for OpenAI #7316), since/v1/responsesalso rejects them. Prior model turns replay part by part, so structured-output history survives multi-turn.instructions(joined with any passthroughinstructions) and later ones are sent asdeveloperitems; usage reports reasoning and cached tokens;config.timeoutis forwarded as an SDK request option;streamandbackgroundin config are rejected.function_calloutput items are rejected (INVALID_ARGUMENT/UNIMPLEMENTED) until the tool-calling slice, as is any other output item the runner can't represent (local_shell_call,computer_call,mcp_approval_request,image_generation_call, ...); afailedresponse throws itserrorinstead of returning an empty completion. Deliberate exception: a streaming caller gets the completed response as a single terminal chunk (the Dev UI always streams), with the event protocol in a follow-up.Usage
Shared-layer note (affects
deepSeek()/xai()/openAICompatible()):transportbecomes a reserved config key in the Chat Completions body builder - stripped from the wire (Chat Completions 400s on unknown args), withtransport: 'responses'rejected via a provider-neutralINVALID_ARGUMENTrather than silently ignored.No behavior change for existing models: nothing in
SUPPORTED_GPT_MODELSchanges transport,rawshape, or config;gpt.tsis untouched.Not in this slice (see #6002): streaming events, tool calling, encrypted reasoning round-trip, annotations,
responsesModel()opt-in for dual-transport models, background models.