Automatic model routing and deprecation handling for OpenAI, Anthropic, and Google Gemini
Project description
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-* |
| 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:
- Fork the repo
- Add the entry to
legacyllm/data/depricated.jsonwithreplacementanddeprecated_on - Run
pytestto validate - Submit a pull request
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file legacyllm-0.1.0.tar.gz.
File metadata
- Download URL: legacyllm-0.1.0.tar.gz
- Upload date:
- Size: 15.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66a12bfd2a7b4f7ade30804a4abe08ec53fde88daebbddd2081fc627adc91a9c
|
|
| MD5 |
6d12829dfb62b3bb5cf786cc603d6054
|
|
| BLAKE2b-256 |
2c864d4972bb85af975e6736fe6a441a2a92ec8f0ded344d910370db70805b4a
|
File details
Details for the file legacyllm-0.1.0-py3-none-any.whl.
File metadata
- Download URL: legacyllm-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
905beeee877e281e7fed6ed7e0d554fe6327021abc0007a4333f6af63a03db02
|
|
| MD5 |
7b2c81f52ee1d3786168b9eed89a0283
|
|
| BLAKE2b-256 |
cf46b033b9f649631936fa41c08903ab81567e30a7a7fbbd374d1e586c2ea5f6
|