Expand description
The OpenAI-compatibility facade (DW-075).
The CLIENT-facing dialect: every AI route accepts an OpenAI
chat-completions request and answers in the OpenAI response shape,
regardless of which provider actually served the call. This module
owns that dialect’s parse (parse_chat_request) and serialization
(response_to_openai, stream_event_to_openai_chunk,
error_body) — the inverse of crate::ai::adapters::openai,
which speaks the SAME dialect but toward the provider (where the
model identifier is the mapped provider model, not the alias).
Errors are emitted in an OpenAI-client-compatible shape
({"error":{"message","type","code","request_id"}}): the standard
OpenAI SDKs parse error.message/type/code, and the extra
request_id member carries the gateway’s correlation ID without
breaking those parsers.
Functions§
- error_
body - Build the OpenAI-shaped error body every AI-route failure answers
with.
error_typefollows the OpenAI taxonomy (invalid_request_error,model_error,api_error, …). - error_
type_ of - The OpenAI error-type token for an
AiError, for pass-through error mapping. - parse_
chat_ request - Parse an OpenAI chat-completions request body into the canonical
ChatRequest. Unknown top-level parameters are preserved inother(the OpenAI provider adapter re-emits them; other dialects drop them — see the types docs). - response_
to_ openai - Serialize a canonical
ChatResponseinto the OpenAI response shape.model_aliasis echoed as the model (the provider’s internal identifier never leaks);request_idrides along for correlation. - stream_
event_ to_ openai_ chunk - Serialize one canonical stream event as an OpenAI
chat.completion.chunk(DW-077 wires the gateway SSE pipeline; shape verified here and in the adapter stream tests). - unix_
now - Current Unix seconds (response
createdfields).