Metadata-Version: 2.5
Name: endofmodel
Version: 0.1.1
Summary: Know before your LLM model dies: warnings, CI checks and silent-redirect detection for deprecated OpenAI, Anthropic and Gemini models.
Project-URL: Homepage, https://github.com/Agentdrops/endofmodel
Project-URL: Issues, https://github.com/Agentdrops/endofmodel/issues
Project-URL: Changelog, https://github.com/Agentdrops/endofmodel/blob/main/CHANGELOG.md
Author: endofmodel contributors
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: anthropic,claude,deprecation,gemini,llm,llmops,mlops,model-retirement,openai
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries
Classifier: Typing :: Typed
Requires-Python: >=3.10
Provides-Extra: dev
Requires-Dist: anthropic>=0.30; extra == 'dev'
Requires-Dist: httpx>=0.23; extra == 'dev'
Requires-Dist: jsonschema>=4; extra == 'dev'
Requires-Dist: openai>=1.0; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.21; extra == 'dev'
Requires-Dist: pytest>=7; extra == 'dev'
Requires-Dist: ruff>=0.5; extra == 'dev'
Provides-Extra: guard
Requires-Dist: httpx>=0.23; extra == 'guard'
Description-Content-Type: text/markdown

# endofmodel

**Know before your LLM model dies.**

LLM providers retire models all the time. When it happens, your app either starts
failing with a confusing `404 model_not_found`, or worse, keeps "working" while the
provider silently routes your requests to a different model. `endofmodel` tells you
**before** that happens, and explains it clearly when it does.

- ⚠️ **Runtime warnings**: every API call to a deprecated model logs a warning with the
  retirement date, days left, and the recommended replacement.
- 🔀 **Silent-redirect detection**: flags when the model that answered is not the model you asked for.
- 💥 **Clear errors**: turns an opaque 404 from a retired model into `ModelRetiredError`.
- 🔍 **CI gate**: `endofmodel scan` finds model IDs in your code and fails the build
  if any are retired or retiring soon.
- 📦 **Offline and free**: the registry ships inside the package. No API key, no network
  calls, and no dependencies for the core.

Covers **OpenAI**, **Anthropic (Claude)** and **Google Gemini API** today.

## Install

```bash
pip install endofmodel            # check / scan / CLI (zero dependencies)
pip install "endofmodel[guard]"   # + runtime guard (httpx)
```

## 30-second tour

> Complete scripts for everything below (install line, imports, usage with the OpenAI,
> Anthropic and OpenRouter SDKs) are in [`examples/`](examples/).

```bash
$ endofmodel check gpt-4o-2024-05-13 claude-opus-4-5-20251101
gpt-4o-2024-05-13 (openai) was retired on 2026-10-23 and no longer works -> use gpt-5.6-sol [...]
claude-opus-4-5-20251101 (anthropic) is deprecated and retires on 2027-01-22 (51 days left) -> use claude-opus-5-5 [...]
```

### Warn on live API calls

```python
from openai import OpenAI
import endofmodel

client = OpenAI(http_client=endofmodel.http_client())
client.chat.completions.create(model="gpt-4o-2024-08-06", messages=[...])
# DeprecatedModelWarning: endofmodel: gpt-4o-2024-08-06 (openai) is deprecated and
# retires on 2027-01-14 (43 days left) -> use gpt-6-luna [https://developers.openai.com/...]
```

The same works for Anthropic, and for async clients:

```python
from anthropic import Anthropic, AsyncAnthropic

client = Anthropic(http_client=endofmodel.http_client())
aclient = AsyncAnthropic(http_client=endofmodel.async_http_client())

# or attach to a client you already have:
endofmodel.wrap(existing_client)
```

Each model is reported **once per process**, so your logs don't flood.

### Get alerts where you'll see them

```python
@endofmodel.on_event
def alert(event):
    # event.kind: "deprecated" | "retired" | "redirected"
    send_to_slack(event.message)
```

### Clear errors for retired models

```python
with endofmodel.translate_errors():
    client.chat.completions.create(model="gpt-4-0613", messages=[...])
# endofmodel.ModelRetiredError: gpt-4-0613 (openai) was retired on 2026-10-23
# and no longer works -> use gpt-5.6-sol
```

### Startup check

Models often live in `.env` files, databases or feature flags where no code scan can see them.
Check them when your service boots:

```python
endofmodel.assert_models_ok(
    [os.environ["CHAT_MODEL"], os.environ["EMBED_MODEL"]],
    fail_under_days=14,
)  # raises ModelExpiringError if any are retired or retire within 14 days
```

### CI gate

```bash
endofmodel scan ./src --fail-under-days 30
```

```
✖ app/llm.py:12:15  gpt-4o-2024-05-13  retired 2026-10-23 -> gpt-5.6-sol
! app/summarize.py:8:20  gpt-5-mini  retires 2026-12-11 (9d) -> gpt-6.1-terra
· README.md:40:3  gpt-4  retired 2026-10-23 -> gpt-5.6-sol [docs]

3 finding(s): 1 retired, 1 critical, 1 info
FAILED: retired models or models retiring within 30 days.
```

Exit code is `1` when the gate fails, so CI blocks the merge. Mentions in `.md`/`.txt` files are
reported but never fail the build. GitHub Actions:

```yaml
- run: pipx run endofmodel scan . --fail-under-days 30
```

### List what's retiring soon

```bash
endofmodel list --upcoming 60
endofmodel list --provider anthropic --json
```

## How it works

```
registry (JSON, shipped in the package)
        │
   check(model) ──► ModelStatus(status, retires_on, days_left, replacement, ...)
        │
 ┌──────┼───────────────┬──────────────────┐
 runtime guard      scan (CI)         assert_models_ok
 (httpx hooks)     static search       (startup)
        │
 warnings · logging · on_event callbacks
```

The runtime guard hooks into **httpx**, the HTTP library the OpenAI and Anthropic SDKs use,
instead of patching SDK methods. That way it keeps working when the SDKs change. Hooks never
raise exceptions inside the SDK; they only warn, log and emit events.

**Silent redirects.** After a successful non-streaming call, the guard compares the model you
requested with the model reported in the response (`model` for OpenAI/Anthropic, `modelVersion`
for Gemini). Dated snapshots (`gpt-4o` → `gpt-4o-2024-08-06`) and `*-latest` aliases are not
treated as redirects.

## The registry

Data lives in [`src/endofmodel/data/`](src/endofmodel/data), one JSON file per provider,
validated against [`schema.json`](src/endofmodel/data/schema.json). Each entry records the
model IDs, deprecation date, retirement date, replacement, and (when the provider says so) the
model requests get redirected to.

OpenAI, Anthropic and Gemini are curated by hand from the official deprecation pages. Other
providers (Mistral, Z.ai, Moonshot, Microsoft, Upstage, …) are generated from the
[OpenRouter models API](https://openrouter.ai/api/v1/models): a weekly GitHub Action
([`sync-models.yml`](.github/workflows/sync-models.yml)) runs
[`scripts/sync_openrouter.py`](scripts/sync_openrouter.py) and opens a PR with new or changed
retirement dates. It never edits the hand-curated files; it lists where they disagree with
OpenRouter in the PR description instead. Generated entries accept both the bare ID
(`glm-4.5`) and the OpenRouter ID (`z-ai/glm-4.5`).

### Calling models through OpenRouter

OpenRouter can stop serving a model on a different day than its author, and some variants
(like `openai/gpt-5-image`) only exist there. `openrouter.json` tracks OpenRouter's own
schedule. You get it when:

- the runtime guard sees a request to `openrouter.ai` (point the OpenAI SDK's `base_url` at
  OpenRouter and pass `http_client=endofmodel.http_client()` as usual);
- you pass `provider="openrouter"` (`check("openai/gpt-5", provider="openrouter")`, or
  `endofmodel check openai/gpt-5 --provider openrouter`);
- the model uses the LiteLLM form `openrouter/openai/gpt-5`.

```text
$ endofmodel check openai/gpt-5 --provider openrouter
openai/gpt-5 (via OpenRouter) is deprecated and retires on 2026-12-11 (9 days left) -> use gpt-6.2-sol [https://openrouter.ai/openai/gpt-5]
```

If OpenRouter has no date for a model, the author's schedule applies. OpenRouter's IDs don't
always match the author's: Anthropic IDs are matched through derived aliases
(`claude-opus-4-5-20251101` also answers to `claude-opus-4-5` and OpenRouter's
`claude-opus-4.5`), and OpenAI and Gemini IDs match after removing the prefix. Other
OpenRouter-sourced providers (`mistral.json`, `zai.json`, …) use OpenRouter's spelling for the
bare ID, which may not equal the provider's native API ID. Replacements come from
the author's entry, because OpenRouter doesn't publish them. Without a provider hint,
`openai/gpt-5` means OpenAI's own schedule; IDs only OpenRouter knows are still found.

To use fresher or private data without waiting for a release, point `ENDOFMODEL_REGISTRY_DIR`
at a folder of JSON files in the same format. Entries there override the bundled ones.

> **Disclaimer:** dates come from the providers' public deprecation pages and can change.
> Always confirm against the linked notice before migrating. Dates for OpenRouter-sourced
> providers are when OpenRouter stops serving the model, which can differ from the provider's
> own API. Platforms like Azure OpenAI,
> Amazon Bedrock and Vertex AI run their own retirement schedules, which this release does not
> cover yet.

## Roadmap

- [x] v0.1: registry (OpenAI, Anthropic, Gemini), `check`, runtime guard, redirect detection, `scan`, CLI
- [x] v0.2: weekly GitHub Action that syncs expiry dates from OpenRouter and opens registry PRs
- [ ] v0.2: scrape official provider deprecation pages for OpenAI / Anthropic / Gemini
- [ ] v0.3: Azure OpenAI, Amazon Bedrock, Vertex AI, Groq
- [ ] v0.4: google-genai SDK adapter, LangChain / LiteLLM callbacks, Slack & OpenTelemetry notifiers
- [ ] v0.5: optional `endofmodel update` to fetch the latest registry (cached)

## Contributing

Updating a date or adding a model is the most valuable contribution, and it only takes a
JSON edit. See [CONTRIBUTING.md](CONTRIBUTING.md).

## License

[Apache-2.0](LICENSE). Free for personal and commercial use.
