Standalone LLM Modules
Model catalogue, endpoint resolver, credentials gate, and AutoGen config-list — usable with pip install praisonai-code alone
After the C7 milestone, the LLM helpers live in praisonai-code — no wrapper import required.
from praisonaiagents import Agent
from praisonai_code.llm.catalogue import ModelCatalogue
from praisonai_code.llm.credentials import is_configured
catalogue = ModelCatalogue()
models = catalogue.list_models(provider="openai")
if is_configured():
agent = Agent(
name="LLM Info Agent",
instructions=f"You have access to {len(models)} OpenAI models.",
)
agent.start("Which OpenAI model supports vision and tool calling?")The user asks about models; catalogue and credential helpers from praisonai-code answer without wrapper imports.
How It Works
Module Map
Quick Start
- Simple Usage
python from praisonaiagents import Agent from praisonai_code.llm.catalogue import ModelCatalogue catalogue = ModelCatalogue() models = catalogue.list_models(provider="openai") agent = Agent( name="LLM Info Agent", instructions=f"You have access to {len(models)} OpenAI models.", ) agent.start("Which OpenAI model supports vision and tool calling?") - With Credential Gate
python from praisonaiagents import Agent from praisonai_code.llm.credentials import is_configured, inject_credentials_into_env if not is_configured(): raise SystemExit("Run: praisonai setup (or set OPENAI_API_KEY)") inject_credentials_into_env() agent = Agent( name="Secure Agent", instructions="You are a helpful assistant.", ) agent.start("What models are available for my account?") - Discover Available Models
python from praisonai_code.llm.catalogue import ModelCatalogue catalogue = ModelCatalogue() models = catalogue.list_models(provider="openai") print(f"{len(models)} OpenAI models available") - Check Credentials and Resolve Endpoint
python from praisonai_code.llm.credentials import is_configured, inject_credentials_into_env from praisonai_code.llm.env import resolve_llm_endpoint if is_configured(): inject_credentials_into_env() ep = resolve_llm_endpoint() print(f"Using: {ep.model} at {ep.base_url}")
How It Works
The user asks about models; the agent queries the catalogue and credential helpers, then answers.
The Four Modules
| Module | Public exports | Purpose |
|---|---|---|
praisonai_code.llm.catalogue | ModelCatalogue, ModelInfo | Discover and validate LLM models |
praisonai_code.llm.config | build_config_list | AutoGen-style [{model, base_url, api_key, api_type}] |
praisonai_code.llm.env | LLMEndpoint, resolve_llm_endpoint, default_model_for_available_provider | Resolve which model/endpoint to hit |
praisonai_code.llm.credentials | is_configured, inject_credentials_into_env, resolve_llm_endpoint_with_credentials | Credential gate for CLI startup |
How It Works
The user asks about models; the catalogue and credential gate resolve an endpoint, then the agent answers.
Which Import Path Should I Use?
Backward Compatibility Guarantee
Standalone Smoke Test
This example runs in a venv with only praisonai-agents + praisonai-code installed (no wrapper):
from praisonai_code.cli.configuration.resolver import ConfigResolver
from praisonai_code._version import get_package_version
from praisonai_code.llm.credentials import is_configured
from praisonai_code.llm.catalogue import ModelCatalogue
assert ModelCatalogue().list_models(provider="openai") # 132 modelsModule Reference
praisonai_code.llm.catalogue
from praisonai_code.llm.catalogue import ModelCatalogue, ModelInfo
catalogue = ModelCatalogue(
cache_dir=None, # defaults to ~/.praisonai/cache
cache_ttl=3600, # 1 hour
)
# List all models, optionally filter
models = catalogue.list_models(provider="openai", search="gpt-4")
# Get full metadata for one model
info = catalogue.describe_model("gpt-4o")
# Validate a model ID — raises ValueError with suggestions on mismatch
try:
valid_id = catalogue.validate_model("gpt-4o-mni")
except ValueError as e:
print(e) # "Unknown model 'gpt-4o-mni'. Did you mean: gpt-4o-mini, gpt-4o"
# Quick boolean check
ok = catalogue.is_valid_model("gpt-4o") # True
# Fuzzy suggestions
suggestions = catalogue.get_suggestions("gpt4o") # ['gpt-4o', 'gpt-4o-mini']Cache file: ~/.praisonai/cache/models.json (TTL 3600s, honours PRAISONAI_HOME). Falls back to 14 curated models (OpenAI 5, Anthropic 3, Google 3, Groq 2, Ollama 1) when litellm is unavailable.
praisonai_code.llm.config
from praisonai_code.llm.config import build_config_list
config = build_config_list(include_api_type=True)
# → [{'model': 'gpt-4o-mini', 'base_url': 'https://api.openai.com/v1',
# 'api_key': 'sk-...', 'api_type': 'openai'}]praisonai_code.llm.env
from praisonai_code.llm.env import (
LLMEndpoint,
resolve_llm_endpoint,
default_model_for_available_provider,
)
ep = resolve_llm_endpoint()
print(ep.model, ep.base_url, ep.api_key)
model = default_model_for_available_provider()praisonai_code.llm.credentials
from praisonai_code.llm.credentials import (
is_configured,
inject_credentials_into_env,
resolve_llm_endpoint_with_credentials,
)
if is_configured():
inject_credentials_into_env()
ep = resolve_llm_endpoint_with_credentials()Best Practices
Use praisonai_code.llm.* for new standalone scripts
New scripts that target the praisonai-code package should import from praisonai_code.llm.* to avoid taking a dependency on the wrapper:
from praisonai_code.llm.catalogue import ModelCatalogue
from praisonai_code.llm.env import resolve_llm_endpointDo not migrate existing praisonai.llm.* imports
Existing code using from praisonai.llm.catalogue import ModelCatalogue works without change — the shim guarantees module identity. Migration has no functional benefit.
Check is_configured() before calling agents in CLI scripts
Use is_configured() as a fast gate before running an agent — it checks env vars and the credential store without making any network calls:
from praisonai_code.llm.credentials import is_configured, inject_credentials_into_env
if not is_configured():
print("Run: praisonai setup (or set OPENAI_API_KEY)")
raise SystemExit(1)
inject_credentials_into_env()Configuration Options
ModelCatalogue Python ReferencePython configuration options for ModelCatalogue
LLMEndpoint Python ReferencePython configuration options for LLMEndpoint
Related
CLI commands for models list, describe, validate
AutoGen Config ListBuild AutoGen config_list from the resolved endpoint
LLM Endpoint ConfigEndpoint precedence and provider routing
PraisonAI Code CLIThe standalone CLI runtime these modules power
Package Boundaries (C7.1)Three-tier ownership and the _wrapper_bridge pattern