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 -> input message with input_text content.
  • System -> ignored; pass system prompt via instructions.
  • Assistant -> input assistant message with output_text content.
  • Tool -> function_call_output item. 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.

Search Document