ante-llm
The model layer of Ante, the coding agent by Antigma Labs: one request type and one stream of events over four provider wire formats.
This is the code Ante runs for every model call, in the released binary and in its public Terminal-Bench runs. It is not a second implementation kept for the crate.
| Wire format | Client |
|---|---|
| Anthropic Messages | anthropic::Anthropic |
| OpenAI Responses, over HTTP streaming or a WebSocket | openai::OpenAi |
| OpenAI Chat Completions and compatible servers | openai_compatible::OpenAiCompatible |
| Gemini | gemini::Gemini |
The Chat Completions client carries per-provider profiles for DeepSeek, GLM, Kimi, MiniMax, Qwen, OpenRouter and llama.cpp, so each gets its own reasoning parameters.
Example
use ;
use ;
use LlmError;
use ;
use ;
use StreamExt;
async
client.chat(request) returns the same call as one complete response. The
other providers follow the same pattern: anthropic::Anthropic with
anthropic::BASE_URL and Placement::Header("x-api-key".into()),
gemini::Gemini with gemini::BASE_URL and
Placement::Header("x-goog-api-key".into()), and openai_compatible::OpenAiCompatible with any
Chat Completions server's base URL. A local
server needs no key: build the client with AuthedClient::unauthenticated. A
credential that changes, such as an OAuth token, is a TokenSource passed to
AuthedClient::new.
What it handles
- Streaming. Every call streams, and a complete response is that stream collected. One idle timeout covers opening the stream and silence between reads, so a provider that accepts a request and never answers still fails.
- Compressed uploads. A request of 16 KiB or more is sent gzip-compressed
to Anthropic Messages and zstd-compressed to OpenAI Responses. Every other
endpoint gets plain JSON. Each answered request writes one debug record,
llm request answered, with both sizes, the status and the time taken. - Errors by remedy.
LlmErrorKindsays what a failure calls for (rate limited, overloaded, context overflow, bad credential, out of quota, blocked by policy) in the same terms for every provider. The provider's own status, code and message stay on the error. - Retries. Two quick retries absorb connection blips. A longer wait the provider asks for is handed back on the error, for the caller to wait out or cancel.
- Credentials. A
TokenSourcesupplies the token and gets one chance to recover when the server rejects it, such as an OAuth refresh. The request is then sent once more. - Tool calls.
normalize_tool_schemarewrites a JSON Schema into the subset every provider accepts. Arguments that are not valid JSON arrive on the call asmalformed_args, so the caller can tell the model instead of losing the turn. - Tool choice. Require a call, name the tool, or forbid calls, with a fallback for providers that reject the parameter.
- Reasoning. One
effortsetting is mapped onto each provider's own levels. Reasoning a provider needs back on the next call (signatures, encrypted content) is replayed. - Instructions mid-conversation. A system message inside the conversation is sent as one where the endpoint supports it and as a user reminder elsewhere, and it waits for outstanding tool results.
- Prompt caching.
cache_ttlon each request, where the wire lets the caller choose. - Attachments. Images in messages and in tool results on every wire. PDFs too, except on Chat Completions.
What it leaves to the caller
The prompt, the conversation store, the context budget and compaction, retry across a whole turn, and the choice of model and provider. Ante is one answer to all of those:
|
License
Apache-2.0.
Part of Ante, a self-contained agent runtime by Antigma Labs.