sonic182

sonic182

Llm_composer - Elixir library for building LLM-based applications

Hi everyone, at Doofinder we have been building llm_composer for some new apps, and we thought it could be useful to share it with the community.

llm_composer is an Elixir library that simplifies working with large language models (LLMs) like OpenAI’s GPT, OpenRouter, Ollama, AWS Bedrock, and Google (Gemini).

It provides a streamlined way to build and execute LLM-based applications or chatbots, with features such as:

  • Multi-provider support (OpenAI, OpenRouter, Ollama, Bedrock, Google Gemini/Vertex AI).
  • System prompts and message history management.
  • Streaming responses.
  • Function calls with auto-execution.
  • Structured outputs with JSON schema validation.
  • Built-in cost tracking (currently for OpenRouter).
  • Easy extensibility for custom use cases.

A key feature is the provider router that handles failover automatically.
It will use one provider until it fails, then fall back to the next provider in the list, applying an exponential backoff strategy. This makes it resilient in production environments where provider APIs can become temporarily unavailable.

Under the hood, llm_composer uses Tesla as the HTTP client.
For production setups, especially when using streaming, it is recommended to run it with Finch for optimal performance.


More info and docs:

HexDocs: LlmComposer — llm_composer v0.13.0
GitHub:

Most Liked

Jskalc

Jskalc

Thanks for your efforts! :raising_hands:

Could you highlight the differences from ReqLLM, discussed in this topic? I believe both libraries aim to solve the same problem.

sonic182

sonic182

We started this lib about a year ago (we’d been using it internally even before that) and only now decided to share it here.

Both libraries aim at the same thing: wrapping LLM APIs behind a unified HTTP client.

The main differences are:

  • HTTP layer: we use Tesla, ReqLLM builds on Req.

  • Routing: llm_composer includes a router with fallback + retries.

  • API style: each library exposes a slightly different way to configure and work with “bots” or requests, so it depends which style you prefer.

mercyf

mercyf

This looks great :slight_smile:

sonic182

sonic182

LlmComposer v0.12.0 released

This version removes deprecated configuration options and adds built-in cost tracking for multiple providers.

Removed (breaking changes)

  • Removed deprecated :provider and :provider_opts keys. Use the :providers list instead.
  • Removed global :api_key in Settings. Each provider should define its own key.
  • Dropped backward compatibility handling for these deprecated options.

Added

  • Automatic cost tracking for OpenAI, Google, and OpenRouter:
    • Fetches real-time pricing from provider APIs (models.dev and OpenRouter).
    • Adds a CostInfo struct in responses with token usage and cost breakdowns.
    • Supports both automatic and manual pricing configuration.

Changelog: https://github.com/doofinder/llm_composer/blob/master/CHANGELOG.md
Docs: https://hexdocs.pm/llm_composer/readme.html

Where Next?

Popular in Announcing Top

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
halostatue
Enviable is a small collection of functions to make working with environment variables easier when configuring Elixir projects. It is des...
New
roriholm
Hi! I just wanted to share my public release of something I’ve been working on. The Paradigm library provides some core utilities for a d...
New
tugayac
Hey Elixir Community! A few months back, I open sourced a link management system we had built into an app. It’s now got enough features ...
New
bentanweihao
Here’s a preview: Here’s the link to download: GenServer cheatsheet Tell me what you think!
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
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
kraleppa
I’m happy to announce LiveDebugger v0.1.0! :mega: LiveDebugger is a browser-based tool for debugging LiveView applications, designed to ...
New
fhunleth
Elixir Circuits is a set of libraries for interacting with hardware. We previously announced Circuits.UART, and now we’re ready to announ...
New
fuelen
Hey folks! Want to present a toolkit for writing command-line user interfaces. It provides a convenient interface for colorizing text...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
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
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

We're in Beta

About us Mission Statement