ReqAI

CI Hex version Hex Docs

ReqAI is a lightweight Elixir client for LLM APIs, built on Req.

{:ok, %Req.Response{}, body} =
ReqAI.Provider.OpenAI
|> ReqAI.Provider.new()
|> ReqAI.generate(model: "gpt-5.4-mini", input: "Say hello")
%{"output" => [%{"content" => [%{"text" => text}]}]} = body
IO.puts(text)

See the Getting Started guide for configuration and usage examples.

Philosophy

Features

Streaming

Use the same provider and request with a callback that receives each decoded event and updates an accumulator:

{:ok, response, events} =
ReqAI.stream(provider, request, [], fn event, _response, events ->
{:cont, [event | events]}
end)
events = Enum.reverse(events)

Return {:halt, acc} to stop consuming the stream. Events retain the provider's structure, with SSE JSON payloads decoded in event.data.

Installation

Add ReqAI to your dependencies in mix.exs:

{:req_ai, ">= 0.0.0"}

Requires Elixir 1.18 or later and Req 0.8.0 or later.