simple_module_ai
AI base module for SimpleModule apps: one provider-configurable service layer (chat + embeddings) that every other module shares, with DB-backed settings, encrypted keys and an admin page.
The module owns connection configuration — provider, endpoint, key, model name. Consuming modules own behaviour — agents, prompts, temperature, retries, streaming.
Full documentation lives in docs/:
user guide (the AI settings page),
API reference (the sm_ai.contracts API and the HTTP
routes), operations (install, settings, key rotation,
troubleshooting) and
architecture.
Install
pip install simple_module_ai
Add simple_module_ai to your host's dependencies; it is discovered at boot
via the simple_module entry point. There are no tables and no migrations.
Usage (consuming from another module)
Declare the dependency in your module's ModuleMeta:
meta = ModuleMeta(name="MyModule", depends_on=["Ai"], ...)
Then resolve connections wherever you need them:
from pydantic_ai import Agent
from sm_ai.contracts import AiNotConfiguredError, resolve_model, resolve_embedder
agent = Agent(instructions="...", output_type=MySchema)
result = await agent.run(text, model=resolve_model())
embedder = resolve_embedder() # raises AiNotConfiguredError until the
result = await embedder.embed_documents(chunks) # embedding slot is set up
resolve_model(model_name=...) overrides the configured model name for
same-endpoint multi-model setups. embedding_dim() returns the configured
vector width. All errors subclass AiError.
The import package is
sm_ai, notai— the bare name belongs to another PyPI project and would collide in hosts that install it.
Usage metering
With the billing module installed, every AI request a consumer serves can
count against the organisation's plan as the ai.requests meter, a counter
that resets each billing period. Without billing nothing is metered or
limited, and nothing is imported: ai has no dependency on billing.
On startup the module registers ai.requests with billing's meter registry,
so the plan editor suggests it (absent is unlimited, 0 forbids). The
module serves no chat of its own, so the consumer guards the route that
calls the model:
from sm_ai.contracts import RequiresAiRequest, resolve_model
@router.post("/summarise", dependencies=[RequiresAiRequest()])
async def summarise(...):
result = await agent.run(text, model=resolve_model())
It is billing's RequiresQuota("ai.requests"): past the limit the route
answers 402 quota_exceeded, and the charge is refunded only when the
handler raises, so let a provider error propagate rather than return an
error response. A streaming response is charged when the handler returns it;
a failure mid-stream refunds nothing. utils/quotaError.ts turns the 402
into a translated message, and this module's API client uses it. See
the API reference.
Settings
Two slots — chat and embeddings — each with provider (anthropic, openai,
google, openai_compatible), model, base URL and API key. The
openai_compatible provider covers vLLM, Ollama and LM Studio (base URL
required; a blank key is replaced by a protocol-satisfying placeholder).
Configure at /ai/ (permission ai.manage) or headlessly with
scripts/set_setting.py sm_ai <field> <value>. The generic Settings screen
links to /ai/ rather than editing these fields itself, so the page's
validation and key encryption apply to every save. The module
reads no SM_AI_* environment variables: settings live in the database at
SYSTEM scope, so every tenant shares one provider configuration and one API
key per slot. API keys are encrypted at
rest with a key derived from SM_SECRET_KEY. Rotating that secret keeps them
readable while the old key is in SM_SECRET_KEY_PREVIOUS
(docs/secret-key-rotation.md); without it they surface as unreadable and
must be re-entered. A
settings save hot-reloads the worker that handled it; other workers pick
the change up on restart. Celery workers and scripts that never run the web
host read the same settings themselves, re-reading at most once a minute.
Routes
| Route | Purpose |
|---|---|
GET /ai/ |
admin settings page |
GET/PUT /api/ai/settings |
read (secrets masked) / update |
POST /api/ai/test |
probe the chat or embedding slot |
POST /api/ai/models |
list the model ids the slot's saved endpoint serves (first 500, sorted) |
Writes require the framework's X-CSRF-Token header bound to the session (the
admin page sends it automatically; it is the framework's csrfToken shared prop).
The package follows the module layout; see its code map for the feature areas and test folders.
Metadata
Release files for simple-module-ai 0.0.16
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| simple_module_ai-0.0.16.tar.gz | 106.8 kB | With provenance | Details for simple_module_ai-0.0.16.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| simple_module_ai-0.0.16-py3-none-any.whl | Python 3 | none | any | Details for simple_module_ai-0.0.16-py3-none-any.whl |
Total release size: 178.5 kB
Release files / simple_module_ai-0.0.16.tar.gz
| Download URL | simple_module_ai-0.0.16.tar.gz |
|---|---|
| Size | 106.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d48863e237045b1f1f6eebf6fa8b960e6375977d5fc263efcba1a6803d7c6b52
|
|
BLAKE2b-256 checksum How to use checksums |
7f2490e9ebc3f0fb85e891ff746560ae84f7c4d7c8eeee43a4f9a0268587c35d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.
Transparency logRelease files / simple_module_ai-0.0.16-py3-none-any.whl
| Download URL | simple_module_ai-0.0.16-py3-none-any.whl |
|---|---|
| Size | 71.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b79182f8e88aece8b84f79e178d2eaa7e0afac980a4d0bf3030ab31e99730777
|
|
BLAKE2b-256 checksum How to use checksums |
07863a3438df9268efa02a1aa33280bb238c814ae14a3df5efe6c41aebdceb8e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.
Transparency logSecurity for simple-module-ai 0.0.16
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for simple_module_ai-0.0.16.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.