This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Consider using release 2026.10.21.1 instead.
ctxlen
How many tokens a model takes in, and how many it can write back, for any model id you would
pass to litellm.completion. No dependencies, no network: the numbers ship inside the package.
uv add ctxlen
>>> import ctxlen
>>> ctxlen.max_input("gpt-4o"), ctxlen.max_output("gpt-4o")
(128000, 16384)
>>> ctxlen.max_input("openai/gpt-4o")
128000
>>> ctxlen.max_input("GPT-4o")
128000
>>> ctxlen.max_input("text-embedding-3-small"), ctxlen.max_output("text-embedding-3-small")
(8191, None)
>>> print(ctxlen.max_input("not-a-model"))
None
That is the whole API: max_input(model) and max_output(model), each an int or None.
What the numbers mean
The numbers are litellm's, from its model_prices_and_context_window.json. Where litellm's
row has no number, ctxlen uses models.dev's for the same provider's model.
litellm wins every conflict.
The sources store what each provider publishes. For some models that is the input cap (gpt-5: 272,000 tokens of a 400,000-token window); for others it is the whole window, the reply included (Claude). ctxlen passes the numbers through and does not reconcile them, so leave room for the reply.
The ids it takes
Any id litellm takes, resolved the way litellm's get_model_info resolves it:
- bare names, such as
gpt-4oandclaude-sonnet-4-5; - provider prefixes, such as
openai/gpt-4o,anthropic/claude-sonnet-4-5,vertex_ai/gemini-2.5-pro,bedrock/us.anthropic.claude-sonnet-4-5-20250929-v1:0andazure/gpt-4.1; - the forms litellm strips back to a known model: a date suffix such as
-2024-08-06, a-001version on Vertex and Gemini, a fine-tune such asft:gpt-4o-2024-08-06:acme::AbC123, Bedrock regions and routes, and any letter case.
A test in CI runs the same ids through litellm itself and fails if any answer differs.
ctxlen reads the id string only. litellm's custom_llm_provider=, api_base= and
register_model have no counterpart.
When the answer is None
None means no source has a number. ctxlen never guesses.
- The id is unknown, or empty. Nothing is trimmed:
" gpt-4o"is unknown. - The id names a deployment, such as
azure/my-prod-gpt4. Ask by model:azure/gpt-4.1. - The id is an
openrouter/id. OpenRouter's terms forbid scripted copying, so v1 leaves it out. - The model is too new for litellm, and models.dev has no entry for that provider either. litellm's pattern rule would guess 200,000 tokens for an unknown Claude; ctxlen does not.
max_outputof an embedding model, which writes no tokens.- models.dev's output limit equals the whole window, which is padding rather than a limit, so it is dropped.
A model that is not a str raises TypeError.
How fresh the data is
A job rebuilds the data from litellm and models.dev every 6 hours, and publishes a release when
the data has changed. The version is the date of that snapshot: 2026.10.11.3 is the third
release built from data fetched on 2026-10-11 (UTC).
Your lock file decides what you get: uv lock --upgrade-package ctxlen. If a release most days
is too much for Dependabot, group the updates or check weekly:
version: 2
updates:
- package-ecosystem: pip
directory: /
schedule:
interval: weekly
groups:
ctxlen:
patterns: [ctxlen]
Credits
- litellm (BerriAI, MIT): the model map, and the lookup ctxlen ports from it.
- models.dev (MIT): the numbers where litellm has none. Its entries for OpenRouter, Vercel and Venice are not used, because their terms forbid copying, and neither are Hugging Face's, whose router serves one model on hosts with different windows.
Both MIT notices are in LICENSE, after ctxlen's own.
Metadata
Release files for ctxlen 2026.10.11.dev2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| ctxlen-2026.10.11.dev2.tar.gz | 54.9 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ctxlen-2026.10.11.dev2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 110.2 kB
Release files / ctxlen-2026.10.11.dev2.tar.gz
| Download URL | ctxlen-2026.10.11.dev2.tar.gz |
|---|---|
| Size | 54.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fe7e518cda2a86677db4c7faabb11154e533be176af6e2c53a273cc5421b92e4
|
|
BLAKE2b-256 checksum How to use checksums |
96411d82894ae5cec543f81f68ed3b25e9f93b40e7f83a7a2e1b9b7a57580c67
|
| 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 11, 2026.
Transparency logRelease files / ctxlen-2026.10.11.dev2-py3-none-any.whl
| Download URL | ctxlen-2026.10.11.dev2-py3-none-any.whl |
|---|---|
| Size | 55.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
765307005f3bfafd527817ecf3f28c3540f9befd0a8b18a7b8a9bff1ecf609ad
|
|
BLAKE2b-256 checksum How to use checksums |
6df72ba724ed08d6f2083d10eadfb36556e2f44cede17ce9e4e62a92991ea6ec
|
| 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 11, 2026.
Transparency logSecurity for ctxlen 2026.10.11.dev2
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.
Attestation for ctxlen-2026.10.11.dev2.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 11, 2026.
Transparency logA 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.