1:1match bonus

Gemini MatchUp to $500 per account

Top up Antix, we match it for Gemini.

See the offer
Skip to main content
Blog

Open-Sourcing ante-llm: What It Takes to Stream Four LLM APIs Reliably

· 6 min read
Monk Z
ante-llm: four LLM APIs, one stream

Happy holidays! Closing out the year by open-sourcing something we use every day has become a tradition at Antigma. In 2024 it was mcp-sdk, a minimal Rust implementation of the Model Context Protocol. In 2025 it was nanochat-rs, a tiny cognitive core in native Rust inspired by Karpathy's nanochat.

This year it's ante-llm, the model layer behind every call Ante makes.

A lot of what lets Ante beat other harnesses running the same model has nothing to do with prompts. It's the plumbing underneath: an agent that makes call after call on a long task has to survive every way a provider can fail, on every provider. That plumbing is now Apache-2.0, for anyone to use.

cargo add ante-llm

Not a library extracted for the occasion​

There are good multi-provider Rust clients already, such as genai and rig, and async-openai for OpenAI. The difference with ante-llm is where it comes from. It is the code Ante runs for every model call, in the released binary and in our Terminal-Bench runs, including the ones where Ante is the #1 same-model agent. It is not a second implementation kept up for the crate. A fix that lands for Ante lands in the crate, in the same release.

It speaks four wire formats through one request type and one stream of events:

Wire formatClient
Anthropic Messagesanthropic::Anthropic
OpenAI Responses, over HTTP streaming or a WebSocketopenai::OpenAi
OpenAI Chat Completions and compatible serversopenai_compatible::OpenAiCompatible
Geminigemini::Gemini

The Chat Completions client carries per-provider profiles for DeepSeek, GLM, Kimi, MiniMax, Qwen, OpenRouter and llama.cpp, because "OpenAI-compatible" servers disagree on exactly the parameters that matter, starting with how to ask for reasoning.

What it takes​

Sending a request and printing the reply is the easy part. Here is what an agent loop hits once it runs for hours.

A provider that never answers​

Most failures are loud: a status code, an error body. The expensive one is quiet. The provider accepts the request and then sends nothing, and a client that only times out whole requests either waits forever or kills long, healthy generations.

ante-llm uses one idle timeout that covers opening the stream and every gap between reads. A reply can stream for as long as it keeps streaming. Silence fails.

Errors that say what to do​

Each provider reports failures differently. An agent doesn't care whether it got a 429, a 529 or an error event in the middle of a stream. It needs to know what to do next.

LlmErrorKind classifies every failure by remedy, in the same terms for every provider: rate limited, overloaded, context window exceeded, authentication error, quota exceeded, blocked by policy. The provider's own status, code and message stay on the error for logs. Two quick retries absorb connection blips inside the crate. A longer wait the provider asks for goes back to the caller on the error, so the caller decides whether to wait it out or cancel.

Reasoning you have to send back​

Reasoning models return more than text. Some providers sign their reasoning, or return it encrypted, and expect it back unchanged on the next call. Drop it and the next turn fails or loses its reasoning.

The model's message comes back with that content attached, and sending the message back as you got it is enough. One effort setting maps onto each provider's own reasoning levels.

Tool calls that break​

Models sometimes send tool arguments that aren't valid JSON. If that fails the stream, the agent loses the whole turn. In ante-llm the call arrives anyway, with the raw text on malformed_args, so the agent can tell the model what went wrong and let it try again.

Tool schemas have the opposite problem: each provider accepts a different subset of JSON Schema. normalize_tool_schema rewrites one schema into the subset all of them accept.

Big requests, every turn​

An agent resends the whole conversation on every call, so requests get large. Requests of 16 KiB or more go gzip-compressed to Anthropic Messages and zstd-compressed to OpenAI Responses. Every other endpoint gets plain JSON.

Credentials that expire​

OAuth tokens expire mid-session. A TokenSource supplies the token and gets one chance to recover when the server rejects it, such as by refreshing it. The request is then sent once more, and the agent never sees the failure.

An agent in one file​

Here is the whole loop: call the model, run the tools it asks for, send the results back, and repeat until it stops asking.

for _ in 0..MAX_STEPS {
let stream = client.stream_chat(request.clone()).await?;
let response = streaming::collect(stream, |event| {
if let StreamEvent::TextDelta(text) = event {
print!("{text}");
}
})
.await
.into_result()?;

let calls: Vec<ToolUse> = response.message.content.tool_uses().cloned().collect();
request = request.with_message(response.message);
if calls.is_empty() {
return Ok(());
}

let mut results = Vec::new();
for call in &calls {
results.push(ContentPart::ToolResult(run_tool(call).await));
}
request = request.with_message(Message::user(Content::Parts(results)));
}

The full program is mini-ante, a coding agent in about 200 lines that runs on Anthropic, OpenAI, Gemini, or a local llama.cpp server. The walkthrough goes through it step by step.

Build on any layer​

ante-llm is the bottom layer of a stack we're opening up piece by piece:

  • Profiles and skills shape the whole agent without writing code.
  • ante-sdk drives Ante's runtime from your own interface: a TUI, a bot, an editor.
  • ante-llm gives you the model layer and leaves the loop to you.

Pick the layer that fits and leave the rest to us. If you build something, show us in Show and tell. Issues and PRs against crates/llm are welcome: a maintainer ports them, and they ship in the next release of both the crate and Ante.

GitHub · crates.io · docs.rs

Happy holidays, and happy hacking.