Skip to main content
Yanked

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-4o and claude-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:0 and azure/gpt-4.1;
  • the forms litellm strips back to a known model: a date suffix such as -2024-08-06, a -001 version on Vertex and Gemini, a fine-tune such as ft: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_output of 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.dev1

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

Source distribution (sdist)

Source distribution for ctxlen 2026.10.11.dev1
File Size Uploaded Provenance
ctxlen-2026.10.11.dev1.tar.gz 54.9 kB With provenance Details

Built distribution (wheel)

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

Total release size: 110.2 kB

Release files / ctxlen-2026.10.11.dev1.tar.gz

Download URL ctxlen-2026.10.11.dev1.tar.gz
Size 54.9 kB
Tags Source
SHA-256 checksum
How to use checksums
758db6f86369debf6b972aa64d049e533f0f17ae47ff46b432b6e864fb0d710a
BLAKE2b-256 checksum
How to use checksums
58d48a38f7b707f588bd7d65f25963189382eae93406976971ffcc2ba8703e9a
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 log

Release files / ctxlen-2026.10.11.dev1-py3-none-any.whl

Download URL ctxlen-2026.10.11.dev1-py3-none-any.whl
Size 55.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
364b3c8220e3a76b05ea4c00759f3f8d1cbac00272d157f9afb96375e61bc46f
BLAKE2b-256 checksum
How to use checksums
c2dab1b4a317b2c6df48ab5b615e65a3bee80a3d369a8001742cd2ca0c0009ab
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 log

Security for ctxlen 2026.10.11.dev1

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.

Select from 2 files

Attestation for ctxlen-2026.10.11.dev1.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 log

A 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.

Release history Release notifications | RSS feed

This release
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