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

zachdaniel
Hey folks! AshEvents Release We’ve just released the first version of AshEvents, an Event Sourcing tool for Ash Framework apps. Check o...
New
Schultzer
Hey there, I wrote this low-level library recently, its goal is simply to lower the barrier between Elixir and SQL, and it does that by p...
New
alvises
Hello everyone! :waving_hand: I’m excited to introduce my first Elixir library: YOLO, a library designed to make real-time object detect...
New
MRdotB
Greetings Elixir community! Today, I’m thrilled to present you with resvg_nif, an open-source project that provides Elixir bindings for ...
New
kasvith
Hello Everyone, I was working with some HTML-to-Markdown libraries and ran into a few issues when converting a complex markup file to Ma...
New
Zurga
Subscribe to events emitted by EctoWatch, and cache the changed row. Use the sync/3 function to update an in-memory row or list of rows u...
New
johantell
Ever struggled with mocking external HTTP services in Elixir tests? Found yourself writing brittle mocks that don’t catch real-world enco...
New
victor23k
LiveViewPortal is a small library that allows third-party sites to embed LiveView apps. The library is distributed as an NPM package. On...
New
leandrocp
MDEx is a fast and extensible Markdown parser and formatter. Fast Leverage Rust to parse, manipulate and render documents using: comra...
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

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

We're in Beta

About us Mission Statement