Skip to content

keelgate.llm

Stability of each symbol (stable or provisional) is listed in the API contract. Narrative and semantics are in the integration contract.

Model-agnostic LLM client boundary. Provider logic stays inside keelgate.llm.

FinishReason

Bases: StrEnum

Why a model stopped: a natural stop, tool calls, the length limit, or something else.

LLMAuthError

Bases: LLMError

Credentials are missing or rejected. Never retryable.

LLMClient

Bases: Protocol

A model-agnostic chat client. Implementations must be safe to share between tasks.

LLMError

Bases: Exception

A provider call failed. retryable says whether trying again can help.

LLMRateLimitError

Bases: LLMError

The provider asked the caller to slow down. Retryable.

LLMRequest

Bases: BaseModel

A provider-neutral request: model, messages, the tools offered, a token limit.

metadata is for correlation only and is never sent to a provider.

LLMResponse

Bases: BaseModel

A provider-neutral reply: one assistant message, usage with cost if known, and why it stopped.

Nothing in it is trusted.

Message

Bases: BaseModel

One message in a conversation: a role, text, any tool calls the assistant made, and for a tool result which call it answers.

ModelPrice dataclass

USD per million tokens.

PricingTable

Looks a model up by exact name, then by the longest matching prefix.

The prefix rule lets claude-sonnet-5 cover dated variants of that model.

usage

usage(
    model: str, input_tokens: int, output_tokens: int
) -> Usage

A :class:Usage with cost_usd filled in when the model is priced.

Role

Bases: StrEnum

Who said a message: system, user, assistant or tool.

ToolCall

Bases: BaseModel

A tool invocation the model proposes. arguments is untrusted JSON.

ToolSchema

Bases: BaseModel

A tool offered to the model.

Usage

Bases: BaseModel

Tokens and money for one call. cost_usd is None when the price is unknown.