{"id":48647790,"url":"https://github.com/maximerivest/lm15","last_synced_at":"2026-04-13T10:01:24.243Z","repository":{"id":350294096,"uuid":"1205141534","full_name":"MaximeRivest/lm15","owner":"MaximeRivest","description":"Universal LM core with pluggable provider adapters for OpenAI, Anthropic, and Gemini.","archived":false,"fork":false,"pushed_at":"2026-04-10T16:52:20.000Z","size":1107,"stargazers_count":8,"open_issues_count":4,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-11T08:02:15.943Z","etag":null,"topics":["adapters","anthropic","gemini","llm","openai","python"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/lm15/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MaximeRivest.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-08T17:14:38.000Z","updated_at":"2026-04-10T16:52:25.000Z","dependencies_parsed_at":"2026-04-13T10:01:22.445Z","dependency_job_id":null,"html_url":"https://github.com/MaximeRivest/lm15","commit_stats":null,"previous_names":["maximerivest/lm15"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/MaximeRivest/lm15","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaximeRivest%2Flm15","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaximeRivest%2Flm15/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaximeRivest%2Flm15/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaximeRivest%2Flm15/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MaximeRivest","download_url":"https://codeload.github.com/MaximeRivest/lm15/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaximeRivest%2Flm15/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31747172,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-13T09:16:15.125Z","status":"ssl_error","status_checked_at":"2026-04-13T09:16:05.023Z","response_time":93,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["adapters","anthropic","gemini","llm","openai","python"],"created_at":"2026-04-10T07:27:49.258Z","updated_at":"2026-04-13T10:01:24.223Z","avatar_url":"https://github.com/MaximeRivest.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lm15\n\n[![PyPI version](https://img.shields.io/pypi/v/lm15.svg)](https://pypi.org/project/lm15/)\n[![Python 3.10+](https://img.shields.io/pypi/pyversions/lm15.svg)](https://pypi.org/project/lm15/)\n[![MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)\n\nOne interface for OpenAI, Anthropic, and Gemini. Zero dependencies.\n\n| | lm15 | google-genai | litellm |\n|---|---:|---:|---:|\n| **install** | 72ms | 137ms | 184ms |\n| **import** | 95ms | 2,656ms | 4,534ms |\n| **total (install → response)** | **1,090ms** | **3,992ms** | **5,840ms** |\n| dependencies | 0 | 25 | 55 |\n| disk footprint | 408K | 41M | 155M |\n\n\u003csub\u003eMedian of 10 cold-start runs. Fresh venv, single completion against `gemini-3.1-flash-lite-preview`. [Benchmark source.](benchmarks/cold_start.sh)\u003c/sub\u003e\n\n```python\nimport lm15\n\nresp = lm15.complete(\"claude-sonnet-4-5\", \"Hello.\")\nprint(resp.text)\n```\n\nSwitch models by changing the string. Same types, same streaming, same tool calling. That's it.\n\n\u003e Yes, [we know](https://xkcd.com/927/).\n\n## Install\n\n```bash\npip install lm15\n```\n\nSet at least one provider key:\n\n```bash\nexport OPENAI_API_KEY=sk-...\nexport ANTHROPIC_API_KEY=sk-ant-...\nexport GEMINI_API_KEY=...         # or GOOGLE_API_KEY\n```\n\nDiscover what is available:\n\n```python\nimport lm15\n\nprint(lm15.providers_info())\nfor m in lm15.models(provider=\"openai\")[:5]:\n    print(m.id)\n```\n\n## Usage\n\n### Streaming\n\n```python\nfor text in lm15.stream(\"gpt-4.1-mini\", \"Write a haiku.\").text:\n    print(text, end=\"\")\n```\n\nFull event access:\n\n```python\nfor event in lm15.stream(\"gpt-4.1-mini\", \"Write a haiku.\"):\n    match event.type:\n        case \"text\":     print(event.text, end=\"\")\n        case \"thinking\": print(f\"💭 {event.text}\", end=\"\")\n        case \"finished\": print(f\"\\n📊 {event.response.usage}\")\n```\n\n### Tools (auto-execute)\n\nPass Python functions — schema is inferred, execution is automatic:\n\n```python\ndef get_weather(city: str) -\u003e str:\n    \"\"\"Get weather by city.\"\"\"\n    return f\"22°C in {city}\"\n\nresp = lm15.complete(\"gpt-4.1-mini\", \"Weather in Montreal?\", tools=[get_weather])\nprint(resp.text)  # \"It's 22°C in Montreal.\"\n```\n\n### Tools (manual)\n\n```python\nfrom lm15 import Tool\n\nweather = Tool(name=\"get_weather\", description=\"Get weather\", parameters={...})\ngpt = lm15.model(\"gpt-4.1-mini\")\n\nresp = gpt(\"Weather in Montreal?\", tools=[weather])\nresults = {tc.id: \"22°C, sunny\" for tc in resp.tool_calls}\nresp = gpt.submit_tools(results)\nprint(resp.text)\n```\n\n### Images, audio, video, documents\n\n```python\nfrom lm15 import Part\n\n# Image from URL\nresp = lm15.complete(\"gemini-2.5-flash\", [\"Describe this.\", Part.image(url=\"https://example.com/cat.jpg\")])\n\n# Image generation → vision (cross-model)\nresp = lm15.complete(\"gpt-4.1-mini\", \"Draw a cat.\", output=\"image\")\nresp2 = lm15.complete(\"claude-sonnet-4-5\", [\"What's this?\", resp.image])\n\n# Document\nresp = lm15.complete(\"claude-sonnet-4-5\", [\"Summarize.\", Part.document(url=\"https://example.com/paper.pdf\")])\n\n# Upload via provider file API\ndoc = lm15.upload(\"claude-sonnet-4-5\", \"contract.pdf\")\nresp = lm15.complete(\"claude-sonnet-4-5\", [\"Find liability clauses.\", doc])\n```\n\n### Reasoning\n\n```python\nresp = lm15.complete(\"claude-sonnet-4-5\", \"Prove √2 is irrational.\", reasoning=True)\nprint(resp.thinking)  # chain of thought\nprint(resp.text)      # final answer\n```\n\n### Conversation\n\n```python\ngpt = lm15.model(\"gpt-4.1-mini\", system=\"You remember everything.\")\n\ngpt(\"My name is Max.\")\ngpt(\"I like chess.\")\nresp = gpt(\"What do you know about me?\")\nprint(resp.text)  # knows both\n```\n\n### Prompt caching\n\nReduces cost and latency for repeated prefixes — system prompts, long documents, agent loops:\n\n```python\nagent = lm15.model(\"claude-sonnet-4-5\",\n    system=\"\u003clong system prompt\u003e\",\n    tools=[read_file, write_file],\n    prompt_caching=True,\n)\n\nresp = agent(\"Add tests for auth.\")\nwhile resp.finish_reason == \"tool_call\":\n    results = execute(resp.tool_calls)\n    resp = agent.submit_tools(results)\n    print(f\"Cache hit: {resp.usage.cache_read_tokens} tokens\")\n```\n\n### Prefill\n\n```python\nresp = lm15.complete(\"claude-sonnet-4-5\", \"Output JSON for a person.\", prefill=\"{\")\n```\n\n### Reusable model with config\n\n```python\ngpt = lm15.model(\"gpt-4.1-mini\", system=\"You are terse.\", retries=3, cache=True, temperature=0)\nresp = gpt(\"Hello.\")\n\n# Override per call\nresp = gpt(\"Be creative.\", temperature=1.5)\n\n# Derive new models\nclaude = gpt.with_model(\"claude-sonnet-4-5\")\n```\n\n### Config from dicts\n\n```python\nconfig = {\"model\": \"gpt-4.1-mini\", \"system\": \"You are terse.\", \"temperature\": 0}\nresp = lm15.complete(prompt=\"Summarize DNA.\", **config)\n```\n\n### Built-in tools\n\n```python\nresp = lm15.complete(\"gpt-4.1-mini\", \"Latest AI news\", tools=[\"web_search\"])\nfor c in resp.citations:\n    print(c.title, c.url)\n```\n\n## Provider support\n\n| Capability | OpenAI | Anthropic | Gemini |\n|---|:---:|:---:|:---:|\n| complete | ✅ | ✅ | ✅ |\n| stream | ✅ | ✅ | ✅ |\n| embeddings | ✅ | — | ✅ |\n| files | ✅ | ✅ | ✅ |\n| batches | ✅ | ✅ | ✅ |\n| images | ✅ | — | ✅ |\n| audio | ✅ | — | ✅ |\n| prompt caching | auto | ✅ | ✅ |\n\n## Architecture\n\n```\nlm15.complete / lm15.model       ← v2 surface (sugar)\n        │\n        ▼\nLMRequest ──▶ UniversalLM ──▶ MiddlewarePipeline ──▶ ProviderAdapter ──▶ Transport\n                  │                                        │\n                  │ resolve_provider(model)                 │ build_request / parse_response\n                  ▼                                        ▼\n            capabilities.py                         providers/{openai,anthropic,gemini}.py\n```\n\nThe v2 surface (`lm15.complete`, `lm15.model`, `Model`, `Stream`) is a thin layer that constructs `LMRequest` objects and calls `UniversalLM`. The universal provider contract is unchanged — third parties can build their own surface on top of the same internals.\n\n## Why this exists\n\n- **Stdlib only.** No `requests`, no `httpx`, no `aiohttp`. Transport is `urllib` or optional `pycurl`.\n- **Frozen dataclasses all the way down.** `LMRequest` in, `LMResponse` out. No mutable builder chains.\n- **Nothing is hidden.** Every internal type is importable. Provider escape hatches are always there.\n- **Plugin discovery via entry points.** Third-party providers install and register without touching lm15 core.\n\n## Docs\n\n| Topic | Path |\n|---|---|\n| **API v2 spec** | [`docs/API_SPEC_V2.md`](docs/API_SPEC_V2.md) |\n| Getting started | [`docs/GETTING_STARTED.md`](docs/GETTING_STARTED.md) |\n| Core concepts | [`docs/CONCEPTS.md`](docs/CONCEPTS.md) |\n| Architecture | [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md) |\n| Provider contract | [`docs/CONTRACT.md`](docs/CONTRACT.md) |\n| Error handling | [`docs/ERRORS.md`](docs/ERRORS.md) |\n| Streaming | [`docs/STREAMING.md`](docs/STREAMING.md) |\n| Writing an adapter | [`docs/ADAPTER_GUIDE.md`](docs/ADAPTER_GUIDE.md) |\n| Adding a provider | [`docs/ADD_PROVIDER_GUIDE.md`](docs/ADD_PROVIDER_GUIDE.md) |\n| Completeness testing | [`docs/COMPLETENESS.md`](docs/COMPLETENESS.md) |\n| Production checklist | [`docs/PRODUCTION_CHECKLIST.md`](docs/PRODUCTION_CHECKLIST.md) |\n\n**Cookbooks v2:** [`docs/COOKBOOKS_V2/`](docs/COOKBOOKS_V2/) — practical examples + references:\n\n1. [Hello World](docs/COOKBOOKS_V2/01-hello-world.md)\n2. [Streaming](docs/COOKBOOKS_V2/02-streaming.md)\n3. [Tools (auto-execute)](docs/COOKBOOKS_V2/03-tools-auto.md)\n4. [Tools (manual loop)](docs/COOKBOOKS_V2/04-tools-manual.md)\n5. [Multimodal](docs/COOKBOOKS_V2/05-multimodal.md)\n6. [Reasoning](docs/COOKBOOKS_V2/06-reasoning.md)\n7. [Conversation](docs/COOKBOOKS_V2/07-conversation.md)\n8. [Prompt caching](docs/COOKBOOKS_V2/08-prompt-caching.md)\n9. [Model config](docs/COOKBOOKS_V2/09-model-config.md)\n10. [Building an agent](docs/COOKBOOKS_V2/10-agent.md)\n11. [complete()/stream() reference](docs/COOKBOOKS_V2/11-complete-reference.md)\n12. [Model discovery and provider status](docs/COOKBOOKS_V2/12-model-discovery.md)\n\n**Cookbooks v1 (low-level):** [`docs/COOKBOOKS/`](docs/COOKBOOKS/) — 8 examples using the internal `LMRequest`/`UniversalLM` API directly.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaximerivest%2Flm15","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaximerivest%2Flm15","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaximerivest%2Flm15/lists"}