Skip to main content

Crate ante_llm

Crate ante_llm 

Source
Expand description

§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 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, so each gets its own reasoning parameters.

§Example

use ante_llm::auth::{AuthedClient, Placement};
use ante_llm::client::{ChatClient, Client};
use ante_llm::error::LlmError;
use ante_llm::openai::{self, OpenAi};
use ante_llm::types::{ChatRequest, StreamEvent};
use futures_util::StreamExt;

#[tokio::main]
async fn main() -> Result<(), LlmError> {
    let key = std::env::var("OPENAI_API_KEY").expect("OPENAI_API_KEY");
    let http = AuthedClient::static_key(reqwest::Client::new(), Placement::Bearer, key);
    let client = OpenAi::new(Client::new(openai::BASE_URL, http));

    let request = ChatRequest::new("gpt-6-luna")
        .with_system("Answer in one line.")
        .with_user_text("Say hello in five words.");

    let mut stream = client.stream_chat(request).await?;
    while let Some(event) = stream.next().await {
        match event? {
            StreamEvent::TextDelta(text) => print!("{text}"),
            StreamEvent::MessageStop { usage, .. } => {
                println!("\n{} output tokens", usage.output_tokens)
            }
            _ => {}
        }
    }
    Ok(())
}

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. LlmErrorKind says 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 TokenSource supplies 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_schema rewrites a JSON Schema into the subset every provider accepts. Arguments that are not valid JSON arrive on the call as malformed_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 effort setting 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_ttl on 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:

curl -fsSL https://ante.run/install.sh | bash

§License

Apache-2.0.

Part of Ante, a self-contained agent runtime by Antigma Labs.

Modules§

anthropic
The Anthropic Messages API.
auth
The auth layer: places a connector’s credential on its requests and recovers once when the server rejects it.
client
The ChatClient trait every provider implements, and the Client that sends a provider’s HTTP requests.
effort
Effort ladder resolution shared by provider profiles. Every resolver here rounds a requested effort down to the nearest level at or below it, and up to the lowest level when every level is above it.
error
Provider-agnostic, typed LLM errors.
gemini
The Gemini API.
openai
The OpenAI Responses API, over HTTP streaming or a WebSocket.
openai_compatible
OpenAI Chat Completions and the servers that speak it, with per-provider profiles for reasoning parameters.
search
Web search through a provider’s own API, apart from its chat client.
streaming
Consumer side of streaming: assemble a ChatResponse from the shared StreamEvent vocabulary, either incrementally (ChatResponseBuilder) or by draining a whole stream (collect). stream_driver is the producer side (raw wire events -> StreamEvent).
types
The provider-neutral request, conversation, and stream event types.

Enums§

WireStyle
The wire dialect a provider speaks: which request converter, response mapper, and reserved request fields apply.

Constants§

DEFAULT_MAX_TOKENS
The default maximum number of tokens