pig_protocol/codec/responses
Codec for the OpenAI Responses API (/v1/responses) and the
equivalent ChatGPT Codex route (/codex/responses).
Pure JSON in, structured Gleam out. No IO. Composed by callers
with pig_protocol/auth, pig_protocol/transport, and pig_protocol/sse.
Values
pub fn build_request_body(
messages: List(message.Message),
tools: List(tool_definition.ToolDefinition),
model: String,
instructions: option.Option(String),
) -> String
Build the JSON request body for the OpenAI Responses API.
Messages are mapped to the Responses input format:
User->inputmessage withinput_textcontent.System-> ignored; pass system prompt viainstructions.Assistant->inputassistant message withoutput_textcontent.Tool->function_call_outputitem. Pure function — no IO.
pub fn parse_response(
raw: String,
) -> Result(inference.InferenceResult, error.AiError)
Parse an OpenAI Responses API JSON response into an InferenceResult. Pure function — no IO.