Skip to main content

legacyllm

Stop updating model names manually. legacyllm automatically detects deprecated AI models and routes them to their current replacements — across OpenAI, Anthropic, and Google Gemini.

import legacyllm

# claude-3-opus is retired — legacyllm swaps it automatically
response = legacyllm.chat(
    model="claude-3-opus-20240229",
    messages=[{"role": "user", "content": "Say hi"}]
)

# [legacyllm] 'claude-3-opus-20240229' is deprecated, switching to 'claude-opus-4-8'
print(response["text"])        # Hi!
print(response["model_used"])  # claude-opus-4-8
print(response["was_swapped"]) # True
print(response["usage"])       # {"input_tokens": 10, "output_tokens": 4, "total_tokens": 14}

Install

pip install legacyllm

Set your API keys in a .env file:

OPENAI_API_KEY=...
ANTHROPIC_API_KEY=...
GEMINI_API_KEY=...

Usage

Basic

import legacyllm

response = legacyllm.chat(
    model="claude-opus-4-6",
    messages=[{"role": "user", "content": "Hello"}]
)

print(response["text"])

With parameters

response = legacyllm.chat(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello"}],
    max_tokens=512,
    temperature=0.7,
    system="You are a helpful assistant."
)

Conversation history

response = legacyllm.chat(
    model="claude-opus-4-6",
    messages=[
        {"role": "user", "content": "My name is John"},
        {"role": "assistant", "content": "Hi John!"},
        {"role": "user", "content": "What's my name?"}
    ]
)

Streaming

for chunk in legacyllm.chat(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Tell me a story"}],
    stream=True
):
    print(chunk, end="", flush=True)

Async

import asyncio
import legacyllm

async def main():
    response = await legacyllm.async_chat(
        model="gemini-2.5-flash",
        messages=[{"role": "user", "content": "Hello"}]
    )
    print(response["text"])

asyncio.run(main())

Tools / function calling

response = legacyllm.chat(
    model="gpt-4o",
    messages=[{"role": "user", "content": "What's the weather in NYC?"}],
    tools=[{
        "type": "function",
        "name": "get_weather",
        "description": "Get weather for a location",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {"type": "string"}
            },
            "required": ["location"]
        }
    }]
)

Response

Every response returns the same shape regardless of provider:

{
    "text":           str,   # the response text
    "model_used":     str,   # actual model used (may differ if swapped)
    "was_swapped":    bool,  # True if model was deprecated and swapped
    "original_model": str,   # the model name you passed in
    "usage": {
        "input_tokens":  int,
        "output_tokens": int,
        "total_tokens":  int
    }
}

Supported providers

Provider Models
OpenAI gpt-*, o1, o3, o4
Anthropic claude-*
Google gemini-*

Helper commands

# see available parameters for a provider
legacyllm.params("openai")
legacyllm.params("anthropic")
legacyllm.params("google")

# list all current models
legacyllm.models()
legacyllm.models("openai")
# from the terminal
python -m legacyllm params openai
python -m legacyllm models
python -m legacyllm update

Keeping models up to date

legacyllm ships with a built-in deprecation index. To refresh it:

python -m legacyllm update

This fetches the latest models from all 3 providers, updates legacyllm/data/current_models.json, and flags any models that have disappeared so you can update the deprecation index.


Contributing

The deprecation index (legacyllm/data/depricated.json) needs ongoing maintenance as providers release and retire models. If you notice a missing deprecation:

  1. Fork the repo
  2. Add the entry to legacyllm/data/depricated.json with replacement and deprecated_on
  3. Run pytest to validate
  4. Submit a pull request

License

MIT

Metadata

Release files for legacyllm 0.1.0

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

Source distribution (sdist)

Source distribution for legacyllm 0.1.0
File Size Uploaded
legacyllm-0.1.0.tar.gz 15.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for legacyllm 0.1.0
File Interpreter ABI Platform
legacyllm-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 30.0 kB

Release files / legacyllm-0.1.0.tar.gz

Download URL legacyllm-0.1.0.tar.gz
Size 15.0 kB
Tags Source
SHA-256 checksum
How to use checksums
66a12bfd2a7b4f7ade30804a4abe08ec53fde88daebbddd2081fc627adc91a9c
BLAKE2b-256 checksum
How to use checksums
2c864d4972bb85af975e6736fe6a441a2a92ec8f0ded344d910370db70805b4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.16

Release files / legacyllm-0.1.0-py3-none-any.whl

Download URL legacyllm-0.1.0-py3-none-any.whl
Size 15.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
905beeee877e281e7fed6ed7e0d554fe6327021abc0007a4333f6af63a03db02
BLAKE2b-256 checksum
How to use checksums
cf46b033b9f649631936fa41c08903ab81567e30a7a7fbbd374d1e586c2ea5f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.16

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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