{"slug": "open-sourcing-ante-llm-what-it-takes-to-stream-four-llm-apis-reliably", "title": "Open-Sourcing ante-llm: What It Takes to Stream Four LLM APIs Reliably", "summary": "Antigma released ante-llm, an Apache-2.0 Rust crate on crates.io, as the model layer behind every call its Ante agent makes, streaming four wire formats — Anthropic Messages, OpenAI Responses (HTTP or WebSocket), OpenAI Chat Completions and compatible servers, and Gemini — through one request type and one event stream. The crate adds per-provider profiles for DeepSeek, GLM, Kimi, MiniMax, Qwen, OpenRouter and llama.cpp, and handles failure modes the company says an agent loop hits over hours: a single idle timeout covering stream opening and every gap between reads, an LlmErrorKind classification by remedy (rate limited, overloaded, context window exceeded, authentication error, quota exceeded, blocked by policy), reasoning content that must be sent back unchanged, and tool calls with invalid JSON surfaced on malformed_args rather than failing the stream. Antigma says the code is the same one Ante runs in its released binary and Terminal-Bench runs, where it claims Ante is the #1 same-model agent.", "body_md": "# Open-Sourcing ante-llm: What It Takes to Stream Four LLM APIs Reliably\n\nHappy 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`](https://github.com/AntigmaLabs/mcp-sdk), a minimal Rust implementation of the Model Context Protocol. In 2025 it was [`nanochat-rs`](https://github.com/AntigmaLabs/nanochat-rs), a tiny cognitive core in native Rust inspired by Karpathy's nanochat.\n\nThis year it's **[`ante-llm`](https://crates.io/crates/ante-llm)**, the model layer behind every call Ante makes.\n\nA lot of what lets Ante [beat other harnesses running the same model](https://antigma.ai/eval) 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.\n\n```\ncargo add ante-llm\n```\n\n## Not a library extracted for the occasion\n\nThere 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](https://antigma.ai/eval), 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.\n\nIt speaks four wire formats through one request type and one stream of events:\n\n| Wire format | Client | \n|---|---|\n| Anthropic Messages | `anthropic::Anthropic` | \n| OpenAI Responses, over HTTP streaming or a WebSocket | `openai::OpenAi` | \n| OpenAI Chat Completions and compatible servers | `openai_compatible::OpenAiCompatible` | \n| Gemini | `gemini::Gemini` | \n\nThe 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.\n\n## What it takes\n\nSending a request and printing the reply is the easy part. Here is what an agent loop hits once it runs for hours.\n\n### A provider that never answers\n\nMost 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.\n\n`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.\n\n### Errors that say what to do\n\nEach 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.\n\n`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.\n\n### Reasoning you have to send back\n\nReasoning 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.\n\nThe 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.\n\n### Tool calls that break\n\nModels 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.\n\nTool 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.\n\n### Big requests, every turn\n\nAn 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.\n\n### Credentials that expire\n\nOAuth 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.\n\n## An agent in one file\n\nHere is the whole loop: call the model, run the tools it asks for, send the results back, and repeat until it stops asking.\n\n``` js\nfor _ 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)));}\n```\n\nThe full program is [`mini-ante`](https://github.com/AntigmaLabs/ante/tree/main/examples/mini-ante), a coding agent in about 200 lines that runs on Anthropic, OpenAI, Gemini, or a local llama.cpp server. The [walkthrough](https://docs.antigma.ai/usage/build-an-agent) goes through it step by step.\n\n## Build on any layer\n\n`ante-llm` is the bottom layer of a stack we're opening up piece by piece:\n\n- **Profiles and skills** shape the whole agent without writing code.\n- **[`ante-sdk`](https://crates.io/crates/ante-sdk)** drives Ante's runtime from your own interface: a TUI, a bot, an editor.\n- **[`ante-llm`](https://crates.io/crates/ante-llm)** gives you the model layer and leaves the loop to you.\n\nPick the layer that fits and leave the rest to us. If you build something, show us in [Show and tell](https://github.com/AntigmaLabs/ante/discussions/categories/show-and-tell). Issues and PRs against [`crates/llm`](https://github.com/AntigmaLabs/ante/tree/main/crates/llm) are welcome: a maintainer ports them, and they ship in the next release of both the crate and Ante.\n\nHappy holidays, and happy hacking.", "url": "https://wpnews.pro/news/open-sourcing-ante-llm-what-it-takes-to-stream-four-llm-apis-reliably", "canonical_source": "https://antigma.ai/blog/2026/12/03/open-sourcing-ante-llm", "published_at": "2026-12-03 00:00:00+00:00", "updated_at": "2026-12-03 19:14:31.827681+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "large-language-models", "ai-infrastructure"], "entities": ["Antigma", "ante-llm", "Ante", "Anthropic", "OpenAI", "Gemini", "DeepSeek", "llama.cpp"], "also_reported_by": [], "takeaway": "ante-llm replaces whole-request timeouts with one idle timeout covering stream opening and every read gap, classifies failures into LlmErrorKind remedies (rate limited, overloaded, context window exceeded, authentication error, quota exceeded, blocked by policy), and returns invalid tool-call JSON o", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/open-sourcing-ante-llm-what-it-takes-to-stream-four-llm-apis-reliably", "markdown": "https://wpnews.pro/news/open-sourcing-ante-llm-what-it-takes-to-stream-four-llm-apis-reliably.md", "text": "https://wpnews.pro/news/open-sourcing-ante-llm-what-it-takes-to-stream-four-llm-apis-reliably.txt", "jsonld": "https://wpnews.pro/news/open-sourcing-ante-llm-what-it-takes-to-stream-four-llm-apis-reliably.jsonld"}}