LLM — Typed async LLM access.
Provider string in, typed results out. Streaming-native.
TheLLMclass wraps provider-specific HTTP calls behind a unified
interface. Bothgenerate() and stream()support text and
structured (dataclass) output modes.
Free-threading safety:
- LLM instances are effectively immutable after construction
- httpx.AsyncClient is created per-request (no shared mutable state)
- ProviderConfig is a frozen dataclass
ai.llm
| Name | Type | Default | Description |
|---|---|---|---|
type
|
|
— | |
qualified_name
|
|
— | |
element_type
|
|
— | |
description
|
|
— | |
source_file
|
|
— | |
line_number
|
|
— | |
is_autodoc
|
|
— | |
autodoc_element
|
|
— | |
_autodoc_template
|
|
— | |
_autodoc_url_path
|
|
— | |
_autodoc_page_type
|
|
— | |
title
|
|
— | |
doc_content_hash
|
|
— |
Symbols on this page
LLM
class
Typed async LLM access.
Usage::
llm = LLM("anthropic:claude-sonnet-4-20250514")
# Text generation
text = await llm.generate("Explain quantum computing")
# Text streaming
async for token in llm.stream("Analyze this:"):
print(token, end="")
# Structured output (frozen dataclass or Pydantic model)
@dataclass(frozen=True, slots=True)
class Summary:
title: str
key_points: list[str]
sentiment: str
summary = await llm.generate(Summary, prompt="Summarize: ...")
Provider string format:provider:model
- **
anthropic**: claude-sonnet-4-20250514 - **
openai**: gpt-4o
View source · /home/runner/work/chirp/chirp/site/../src/chirp/ai/llm.py:1