Skip to main content

parse_openai_request

Function parse_openai_request 

Source
pub fn parse_openai_request(
    body: &[u8],
    carry_raw: bool,
) -> Option<ModelRequest>
Expand description

Parse an OpenAI Chat Completions request body into the normalized ModelRequest.

carry_raw: when true (all-OpenAI-dialect ladder), the original JSON is stored in raw for verbatim carry — only the model is swapped, every other field survives intact. When false (translation path to Anthropic ladder), raw is Null so anthropic_wire_body reconstructs from the translated normalized fields.

Returns None if:

  • the body isn’t valid JSON or lacks a messages array, OR
  • a user message contains an image_url with an http(s) URL (non-translatable; caller should have already fallen back via enforce_can_handle but this is a defense-in-depth guard — NoneBadRequest rather than silently dropping the image).