Skip to main content

Crate lm15

Crate lm15 

Source
Expand description

lm15 — the Rust port of lm15: one canonical request/response model over the providers declared by lm15-contract. CONTRACT_PIN names the implementation target, not proof of conformance; see docs/catchup.md.

The map, in playbooks/port.md module order:

  1. canonical types + serde — types, serde (Canonical).
  2. errors and provider error normalization — errors, registry.
  3. auth — auth (AUTH-1..10: credentials, the policy table, the doctor, stored logins with refresh, the login door) and cloud (the cloud chains, AUTH-11, SigV4, RS256, host settings).
  4. dialects, request side — wire (the emit path), compat (the preset tables), the four dialects, adapter (ProviderLM, the named constructors), registry::adapter_for.
  5. response side and stream assembly — sse, stream; the network — transport, response_stream; the router — router (LMRouter); the blocking feature mirrors the names.
  6. model listing, the files / batch / cache surfaces (surfaces), image / speech / video generation, and live sessions (live) — all methods on ProviderLM.

Re-exports§

pub use adaptation::Adaptation;
pub use adaptation::AdaptationAction;
pub use adaptation::AdaptationPolicy;
pub use adapter::AnthropicLM;
pub use adapter::ClaudeCodeLM;
pub use adapter::EventStream;
pub use adapter::GeminiLM;
pub use adapter::LmBuilder;
pub use adapter::OpenAIChatLM;
pub use adapter::OpenAICodexLM;
pub use adapter::OpenAILM;
pub use adapter::ProviderLM;
pub use adapter::TypeSafeLM;
pub use adapter::XaiLM;
pub use auth::default_credentials_path;
pub use auth::AccessPolicy;
pub use auth::Credential;
pub use auth::CredentialFileStore;
pub use auth::CredentialProvider;
pub use auth::CredentialSource;
pub use auth::HostSpec;
pub use auth::SourcedCredential;
pub use cloud::hosts::HostSettings;
pub use compat::AnthropicCompat;
pub use compat::OpenAIChatCompat;
pub use compat::OpenAIResponsesCompat;
pub use dialects::openai_chat::ingest::request_from_openai_chat;
pub use dialects::openai_chat::response_from_openai_chat;
pub use errors::normalize_error;
pub use errors::CollectionLimit;
pub use errors::DiagnosticHeaders;
pub use errors::ErrorClass;
pub use errors::ErrorCode;
pub use errors::ErrorMeta;
pub use errors::Lm15Error;
pub use jobs::BatchJob;
pub use jobs::VideoJob;
pub use jobs::WaitError;
pub use jobs::WaitOptions;
pub use jobs::WaitSnapshot;
pub use judgments::choice;
pub use judgments::choice_described;
pub use judgments::judgments;
pub use judgments::judgments_named;
pub use judgments::score;
pub use judgments::score_named;
pub use judgments::yes_no;
pub use judgments::Judgment;
pub use judgments::JudgmentKind;
pub use live::LiveEventSource;
pub use live::LiveSession;
pub use live::Turn;
pub use live::TurnEnd;
pub use live::TurnLimits;
pub use live::TurnView;
pub use live::DEFAULT_TURN_MAX_BYTES;
pub use live::DEFAULT_TURN_MAX_EVENTS;
pub use response_stream::ResponseStream;
pub use router::openai_chat_model_string;
pub use router::DeclaredProvider;
pub use router::LMRouter;
pub use router::Resolution;
pub use router::RouteRule;
pub use router::RouteSource;
pub use router::RouterConfig;
pub use router::DEFAULT_RULES;
pub use router::LITELLM_PROVIDER_PREFIXES;
pub use serde::Canonical;
pub use testing::LanguageModel;
pub use transport::HttpTransport;
pub use transport::Timeouts;
pub use transport::Transport;
pub use transport::TransportResponse;
pub use transport::DEFAULT_MAX_CONNECTIONS;
pub use wire::TransportRequest;
pub use types::*;

Modules§

adaptation
MAP-13 adaptation records and synchronous, call-local preparation. A collector never spans an await: build the wire synchronously, then send it.
adapter
Provider adapters (playbooks/api-family.md § Providers, direct): one adapter value, ProviderLM, and the named constructors — AnthropicLM, OpenAILM, OpenAIChatLM, GeminiLM, XaiLM, ClaudeCodeLM, OpenAICodexLM — each a builder bound to a dialect and an access policy (spec/auth.md AUTH-10: subscription “adapters” are constructors that bind a policy, never a subclass).
auth
lm15-contract auth surface, module 3a (playbooks/port.md; spec/auth.md, ratified 2026-08-31, amendments through 2026-09-19):
cloud
Cloud doors (spec/auth.md AUTH-10 host, AUTH-11 signing).
compat
Compat values: a server’s wire quirks as data (lm15/compat.py; spec/auth.md AUTH-10 “for the chat dialect an optional compat value”; playbooks/api-family.md rule 7: a knob exists only when the wire has no other way, and never a new one here — a case that needs one is a report).
dialects
The four wire dialects (module 4). Each lives in its own directory and is selected by dialect_for; the registry maps a provider string to a DialectId, the access policy binds the door.
errors
Canonical error taxonomy (spec/vocabularies.md § ErrorCode).
jobs
Job handles: BatchJob and VideoJob (api-family § Beyond chat; contract changes/2026-09-11-job-handles-live-turns-profiles.md § 1).
judgments
Declared judgments, equivalent provider schemas, and structured answers (MAP-14). This module is pure; probability totals are deliberately not validated (INV-052).
live
Live sessions (module 9; playbooks/api-family.md, the reference’s lm15.live.AsyncWebSocketLiveSession): a websocket driven by the dialect’s LiveCodec. The codec (config → setup frames, client event → frames, frame → events) is the contract; the session mechanics here are this language’s own.
login
Managed authentication — sign in once, use everywhere (spec/auth-managed.md AUTH-12–26).
registry
The one table of named providers (mirrors lm15.registry, copied as data — port.md rule 2). A provider string names one wire dialect plus, for bound entries, the compat preset of the server it targets, and adapter_for binds the three (dialect + policy + compat) into a ProviderLM the way the reference router does.
response_stream
ResponseStream: the assembled stream (playbooks/api-family.md § The core loop; the reference’s lm15.result.ResponseStream).
router
LMRouter (playbooks/api-family.md § The core loop; the reference’s lm15.router): a lookup table you can read, not a framework. Three resolution rungs in fixed order, then the AUTH-1 credential chain, then one adapter per provider, built lazily and reused.
scoring
Candidate-sequence likelihood using the server’s chat template and token trie. MAP-14 §4: tokenize candidates with a terminator, batch all trie nodes in ONE completions request, add raw path log-probabilities, normalize only once. The pure hooks work without a transport; complete is an async driver whose callback owns authentication, HTTP errors, and reply diagnostics.
serde
Canonical JSON serde (docs/serde-rules.md, spec/invariants.md § Serde leniency).
sse
Server-Sent Events (the reference’s lm15/sse.py): bytes in, events out. The parser is incremental so a transport can feed it as chunks arrive; parse_sse is the one-shot form over a whole body.
stop
Score-preserving client-side stop with an explicit source-closure protocol. The driver must close/drop its actual source immediately on close_source.
stream
Stream materialization (the reference’s lm15/result.py): one engine every port shares, push-based because Rust has no generators.
surfaces
Shared pieces of the endpoint surfaces (modules 7–8: files, batch, cache, generation, video): the multipart encoders of lm15/providers/common.py, byte-for-byte (the harness compares multipart bodies with only the boundary normalized), the timestamp fold, and the readiness tables copied as data.
testing
Deterministic test doubles. No network, environment, or global registry.
tooling
A static public-surface snapshot, driven by canonical vocabularies and provider declarations rather than runtime language introspection.
transport
The HTTP transport under complete / stream (the reference’s lm15/transports): bytes in, bytes out, nothing of the lm15 type system.
types
Canonical types (spec/types.md) with construction-time invariants (spec/invariants.md). Every type carries public fields, a Default where the spec gives one, and a validate() that enforces the INV-* rules; factory constructors validate and return Result.
wire
The request side every dialect plugs into (module 4 W0; the fixed architecture of the module plan).