Skip to main content

lexigram-ai-llm

LLM client layer for the Lexigram Framework — OpenAI, Anthropic, Ollama, Cohere, Groq, Mistral


Overview

LLM client layer for the Lexigram Framework. Provides typed, async-first clients for 15 providers, multi-provider routing, thinking/reasoning control, structured extraction, streaming, embeddings, and model management — all wired through the DI container via LLMModule. configure() with no arguments uses the defaults but boots the client eagerly, so the provider's API key (e.g. OPENAI_API_KEY) must be available; stub() is the test-safe path.

Full documentation: docs.lexigram.dev

Install

uv add lexigram-ai-llm
# Optional extras
uv add "lexigram-ai-llm[openai,anthropic,ollama]"

Quick Start

from lexigram import Application
from lexigram.di.module import Module, module

from lexigram.ai.llm import LLMModule
from lexigram.ai.llm.config import ClientConfig


@module(
    imports=[
        LLMModule.configure(
            ClientConfig(provider="anthropic", model="claude-sonnet-4-6")
        )
    ]
)
class AppModule(Module):
    pass


async with Application.boot(modules=[AppModule]) as app:
    # use app.container to resolve services
    ...

Configuration

Zero-config usage: LLMModule.configure() with no arguments uses default settings (provider openai, model gpt-4-turbo), but the client is created eagerly at boot — set the provider's API key via config or the provider SDK env var first. For tests, use LLMModule.stub().

Option 1 — YAML file

# application.yaml
ai_llm:
  provider: "anthropic"
  model: "claude-sonnet-4-6"
  api_key: "${LEX_AI_LLM__API_KEY}"
  temperature: 0.7
  max_tokens: null

Option 2 — Profiles + Environment Variables (recommended)

export LEX_AI_LLM__PROVIDER=anthropic
# Environment variables for each field

Option 3 — Python

from lexigram.ai.llm.config import ClientConfig
from lexigram.ai.llm import LLMModule

config = ClientConfig(
    provider="anthropic",
    model="claude-sonnet-4-6",
)
LLMModule.configure(config)

Config reference

Field Default Env var Description
enabled True LEX_AI_LLM__ENABLED Enable the LLM subsystem
provider openai LEX_AI_LLM__PROVIDER LLM provider
model gpt-4-turbo LEX_AI_LLM__MODEL Model name
api_key None LEX_AI_LLM__API_KEY Provider API key
api_base None LEX_AI_LLM__API_BASE Custom endpoint (Azure, local, proxy)
temperature 0.7 LEX_AI_LLM__TEMPERATURE Sampling temperature (0.0–2.0)
max_tokens None LEX_AI_LLM__MAX_TOKENS Response token limit
timeout 60.0 LEX_AI_LLM__TIMEOUT Request timeout in seconds
enable_cache False LEX_AI_LLM__ENABLE_CACHE Cache responses
cache_ttl 3600 LEX_AI_LLM__CACHE_TTL Cache TTL in seconds
thinking None Reasoning/thinking control configuration

Module Factory Methods

Method Description
LLMModule.configure(config) Single-provider client
LLMModule.configure(routing=LLMConfig()) Multi-provider routing cascade
LLMModule.stub() No-op client for tests

Key Features

  • 15 providers: OpenAI, Anthropic, Google Gemini, Azure OpenAI, AWS Bedrock, Google Vertex AI, Ollama, Groq, Mistral, Cohere, DeepSeek, Fireworks, Together, Cloudflare Workers, OpenRouter
  • Multi-provider routing: Sequential, cost-optimized, and latency-optimized strategies
  • Thinking/reasoning control: Extended thinking with token budget and suppression
  • Structured extraction: JSON schema and Pydantic model extraction
  • Streaming: Async streaming response support
  • Embeddings: Text embedding client with same provider
  • Caching: Response-level caching with configurable TTL

Testing

async with Application.boot(modules=[LLMModule.stub()]) as app:
    # your test code
    ...

Key Source Files

File What it contains
src/lexigram/ai/llm/module.py LLMModule.configure() and LLMModule.stub()
src/lexigram/ai/llm/config.py ClientConfig
src/lexigram/ai/llm/routing/config.py LLMConfig, ProviderConfig for routing
src/lexigram/ai/llm/di/provider.py LLMProvider — registers and boots the client
src/lexigram/ai/llm/clients/ Provider implementations
src/lexigram/ai/llm/thinking/ ThinkingConfig handling and suppression
src/lexigram/ai/llm/exceptions.py Full exception hierarchy

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lexigram_ai_llm-0.1.4.tar.gz (296.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lexigram_ai_llm-0.1.4-py3-none-any.whl (270.2 kB view details)

Uploaded Python 3

File details

Details for the file lexigram_ai_llm-0.1.4.tar.gz.

File metadata

  • Download URL: lexigram_ai_llm-0.1.4.tar.gz
  • Upload date:
  • Size: 296.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.14

File hashes

Hashes for lexigram_ai_llm-0.1.4.tar.gz
Algorithm Hash digest
SHA256 da0fd4f730bbba2878efa2c4c42b4613f10b7073901277c87161f363b5c4b26f
MD5 cbd6063f47df9eef2c8a56f98d2ef9c6
BLAKE2b-256 08ffa490b51ceb96c970cf6c15a2d9a83cae3564d042080a9f7b7d428fc0ebdd

See more details on using hashes here.

File details

Details for the file lexigram_ai_llm-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for lexigram_ai_llm-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 67e64abfd88a15ba6560994f0641af82d67d300732a93b5f9c558a9fade6e27f
MD5 31cc43ae9081001e0483d0dbb515ed3d
BLAKE2b-256 3d75b396227322ad3e587c56d36e90cfc09250d3e75b6825b7986a0dc55742dd

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.5008

1 file

0.1.5003

1 file

0.1.5001

2 files

0.1.3007

1 file

0.1.3006

1 file

0.1.3005

1 file

0.1.2003

1 file

0.1.2002

2 files

0.1.2001

2 files

This release

0.1.4 This release

2 files

0.1.2

1 file

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page