Skip to main content

ol-llm

The library every LLM call site at MIT Open Learning goes through. It owns the Opik integration (tracing, prompt management, evaluation), a single timeout and retry policy, and the attribution fields that let cost, quality, and traffic join across applications.

Importing ol_llm sets OPIK_SENTRY_ENABLE=false before anything imports the Opik SDK, which otherwise replaces the host application's Sentry client with its own, so import it first.

The design is in mitodl/ol-infrastructure docs/plans/shared-llm-library-spec.md. The rules the code follows are in docs/: the error contract and the attribution schema.

Usage

Declare each call site once, as a module-level constant, and build its agent from it:

from pydantic import BaseModel

import ol_llm

SUMMARY = ol_llm.UseCase(
    app="mit-learn",
    name="content-summary",
    profile="batch",
    model="openai:gpt-4o-mini",
    fallback_models=("bedrock:global.anthropic.claude-haiku-4-5-20251001-v1:0",),
)


class Summary(BaseModel):
    text: str


summarizer = ol_llm.build_agent(SUMMARY, output_type=Summary, instructions="Summarize.")

The agent's model has a timeout on every request, retries rate limits and outages and nothing else, falls back once the primary has spent its retries, and raises LLMError subclasses (LLMRateLimited, LLMUnavailable, LLMRejected, ...) with the provider's exception as the cause. Build agents once, not per request: each build creates new provider clients.

Set OL_LLM_ENVIRONMENT, or call ol_llm.configure(ol_llm.Settings(environment=...)) at startup. Provider credentials are each SDK's own (OPENAI_API_KEY, ANTHROPIC_API_KEY, the AWS and Google default credential chains, and so on). Operators can change a use case's limits without a release, e.g. OL_LLM_CONTENT_SUMMARY_TIMEOUT_SECONDS=120.

Call sites not built on PydanticAI (LangGraph, a plain SDK) apply the same numbers with ol_llm.resolve_policy(use_case), which needs no extra.

The entry points that wrap a run in an Opik trace (run, run_stream, complete) are not released yet; until they are, build_agent gives the policy and errors without the tracing.

Testing

ol_llm.testing.override_models makes build_model and build_agent use PydanticAI's TestModel or FunctionModel in place of a provider, still under the library's retry and error handling, and tracing_disabled turns Opik off. Script responses and failures with FunctionModel; do not commit recorded provider responses.

Extras

The base install is the Opik SDK and OpenTelemetry, which every call site needs. Everything else is opt-in:

Extra Installs For
pydantic-ai pydantic-ai-slim The default construction path for agents and single calls
openai, anthropic, bedrock, google, mistral the matching pydantic-ai-slim extra A provider SDK; each also installs PydanticAI
harness pydantic-ai-harness In-session memory, compaction, and conversation search. Each harness release pins PydanticAI exactly
memory hindsight-client The shared memory service's client. Provisional: the backend is still being evaluated

For example, ol-llm[bedrock,harness].

Installing without the Opik SDK's heavy dependencies

The opik package hard-requires litellm, openai, pytest, and several other packages the tracing and prompt paths never import. uv consumers can drop them:

[tool.uv]
override-dependencies = [
    "boto3-stubs; sys_platform == 'never'",
    "click; sys_platform == 'never'",
    "litellm; sys_platform == 'never'",
    "openai; sys_platform == 'never'",
    "pytest; sys_platform == 'never'",
    "rapidfuzz; sys_platform == 'never'",
    "tree-sitter; sys_platform == 'never'",
    "tree-sitter-javascript; sys_platform == 'never'",
    "tree-sitter-typescript; sys_platform == 'never'",
    "watchfiles; sys_platform == 'never'",
]

Drop openai from that list if the application uses the openai extra. Opik's evaluation metrics need litellm, so the overrides belong in runtime images, not in an environment that runs evaluations. CI checks this exact list on every change (python/smoke/).

Applications that cap how new a dependency may be (exclude-newer in uv) should exempt this package so releases are usable the day they ship:

[tool.uv.exclude-newer-package]
ol-llm = "0d"

Metadata

Release files for ol-llm 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ol-llm 0.0.1
File Size Uploaded Provenance
ol_llm-0.0.1.tar.gz 77.6 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ol-llm 0.0.1
File Interpreter ABI Platform
ol_llm-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 101.1 kB

Release files / ol_llm-0.0.1.tar.gz

Download URL ol_llm-0.0.1.tar.gz
Size 77.6 kB
Tags Source
SHA-256 checksum
How to use checksums
640ae378819a6279c0e24145ff420dd0cabab181d39c0802d96c712030a1bad8
BLAKE2b-256 checksum
How to use checksums
c54264fdfcbe7ae019815fa177b361260202e7b5118fe0732cf572d55b697b07
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 16, 2026.

Transparency log

Release files / ol_llm-0.0.1-py3-none-any.whl

Download URL ol_llm-0.0.1-py3-none-any.whl
Size 23.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f68404f4af1ab0161a80470189676ee5f13c117b5062a44d32016e682e4a17ce
BLAKE2b-256 checksum
How to use checksums
3c724ca4c16f20c6d69151f07b2076a2bce9ce9683c01d9b008af1a01e5d3c90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 16, 2026.

Transparency log

Security for ol-llm 0.0.1

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

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ol_llm-0.0.1.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 Oct 16, 2026.

Transparency log

A 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.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files Full provenance

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