vkryukov

vkryukov

Responses - LLM library supporting OpenAI's and xAI's Responses API

Responses is a new client library that supports Responses API by OpenAI and xAI. It’s a successor to my previous library openai_responses, which only supported OpenAI - hence the name change.

What is Responses API?

Conveniently, OpenAI just published a blog titled “Why we built Responses API”. In short, it’s a modern (launched this spring), stateful, multimodal, efficient API, an upgrade to Chat Completions, a de-facto industry standard, that was designed by OpenAI in just a weekend back in 2023.

And xAI just launched their own support of Responses API last week.

Why a dedicated library?

There is no shortage of Elixir libraries that support a broad range of LLM providers - from the battle tested LangChain, to ReqLLM that was announced couple of week ago. However, I think there is still space for a small, dedicated library that doesn’t need to bring many different providers to a common denominator. And now that xAI supports the same standard, users of Responses will get additional flexibility in avoiding a vendor lock-in.

Some examples of usage

The simple usage is, well, simple:

# Explicit input and model are required
{:ok, response} = Responses.create(input: "Write me a haiku about Elixir", model: "gpt-4.1-mini")
# -> {:ok, %Responses.Response{text: ..., ...}}

IO.puts(response.text)

You also get automatic cost calculations,

response =
  Responses.create!(
    input: [
      %{role: :developer, content: "Talk like a pirate."},
      %{role: :user, content: "Write me a haiku about Elixir"}
    ],
    model: "grok-4-fast"
  )

IO.puts("#{response.text}\n\nCost: $#{response.cost.total_cost}")
# Arrr, Elixir's code,
# Functional waves crash concurrent,
# Phoenix rises strong.
#
# Cost: $0.00015560

streaming and structured output support,

Responses.stream(
  input: "Tell me about the first 2 U.S. Presidents",
  schema: %{presidents: {:array, %{name: :string, birth_year: :integer}}},
  model: "gpt-4.1-mini"
)
|> Responses.Stream.json_events()
|> Stream.each(&IO.inspect/1)
|> Stream.run()

function calls, web search with OpenAI, prompt helpers, and more.

Please try it out and tell me what you think!

Where Next?

Popular in Announcing Top

metehan
ExTerm is a minimal Elixir library that lets you expose your terminal in a web browser. It’s mostly a toy project for learning and experi...
New
lud
Hello! I’ve been working on the Oaskit library for a while now, and just released a first version. Since I’ve built JSV I wanted to be ...
New
mikehostetler
Hey everyone! I’m excited to share ReqLLM - a new approach to LLM interactions in Elixir that I’ve been working on. After building agent...
New
wingyplus
I just did a dirty hack after seeing Zoi on x.com a few hours ago. Quick Introduction The zoi_defstruct is a library to help you generat...
New
webofbits
Helix is a visual workflow designer for AI agents and multi-agent systems, built with Phoenix and React Flow. It provides an intuitive dr...
#ai
New
anuaralfetahe
Hello Published a new library - ProcessHub! ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New
kraleppa
I’m happy to announce LiveDebugger v0.1.0! :mega: LiveDebugger is a browser-based tool for debugging LiveView applications, designed to ...
New
corka149
A JSON patch is a way to define a sequence of manipulating operations on a JavaScript object. The IETF published the RFC 6902 - found he...
New
jstimps
I’ve started development on an Ecto Adapter for FoundationDB: GitHub - ecto_foundationdb. FoundationDB is a distributed database with AC...
New
jallum
Hey folks :waving_hand: I’ve been building a distributed key-value store in Elixir/OTP called Bedrock. It implements FoundationDB’s arch...
New

Other popular topics Top

pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New

We're in Beta

About us Mission Statement