Quickstart
Install
Section titled “Install”uv add lexigram-ai-llm# Or with pippip install lexigram-ai-llmInstall a provider extra (at least one is required):
uv add "lexigram-ai-llm[openai]"# or: uv add "lexigram-ai-llm[anthropic]"# or: uv add "lexigram-ai-llm[ollama]"Minimal LLM call
Section titled “Minimal LLM call”import asynciofrom lexigram import Applicationfrom lexigram.ai.llm import LLMModule, ClientConfig
async def main() -> None: config = ClientConfig( provider="openai", model="gpt-4o", api_key="sk-...", )
async with Application.boot( name="llm-demo", modules=[LLMModule.configure(config)], ) as app: from lexigram.contracts.ai import LLMClientProtocol
llm = await app.container.resolve(LLMClientProtocol) result = await llm.complete([ {"role": "user", "content": "What is the capital of France?"}, ])
if result.is_ok(): print(result.unwrap().content) # "Paris" else: print(f"Error: {result.unwrap_err()}")
asyncio.run(main())How it works
Section titled “How it works”LLMModule.configure(config)creates aDynamicModulewith anLLMProvider- The provider creates a client via
create_llm_client()using theProviderRegistry LLMClientProtocolis registered in the container — resolve it anywherellm.complete()returnsResult[CompletionProtocol, LLMError]
Next steps
Section titled “Next steps”- Guide — mental model, conversations, streaming, structured output
- Architecture — client layers, cache, model management
- Configuration — every config key
- How-tos — common recipes