ReqLLM.Providers.OpenAI.API behaviour (ReqLLM v1.0.0-rc.8)

View Source

Behaviour for OpenAI API endpoint drivers.

Defines the contract for modules that implement OpenAI API-specific request/response handling. The OpenAI provider uses this behaviour to support multiple API endpoints with different request/response formats.

Implementations

Callbacks

  • path/0 - Returns the API endpoint path
  • encode_body/1 - Transforms request into provider-specific JSON format
  • decode_response/1 - Parses API responses into ReqLLM structures
  • decode_sse_event/2 - Decodes server-sent events for streaming
  • attach_stream/4 - Builds Finch streaming request with proper headers/body

Summary

Callbacks

attach_stream(t, t, keyword, atom)

@callback attach_stream(
  ReqLLM.Model.t(),
  ReqLLM.Context.t(),
  keyword(),
  atom()
) :: {:ok, Finch.Request.t()} | {:error, Exception.t()}

decode_response({})

@callback decode_response({Req.Request.t(), Req.Response.t()}) ::
  {Req.Request.t(), Req.Response.t() | Exception.t()}

decode_sse_event(map, t)

@callback decode_sse_event(map(), ReqLLM.Model.t()) :: [ReqLLM.StreamChunk.t()]

encode_body(t)

@callback encode_body(Req.Request.t()) :: Req.Request.t()

path()

@callback path() :: String.t()