Skip to main content

LiteLLM / OpenAI-compatible gateway doctor CLI (ping, tokens, context bench)

Project description

litellm-doctor

CLI llm for OpenAI-compatible gateways (LiteLLM and similar): list models, ping, local token estimates, needle context test, stepped context bench.

Setup

git clone git@github.com:hewimetall/litellm-doctor.git
cd litellm-doctor
cp .env.example .env   # set OPENAI_API_KEY (+ optional OPENAI_BASE_URL)
uv sync

.env:

OPENAI_BASE_URL=http://localhost:4000/v1
OPENAI_API_KEY=sk-...

Default base URL if unset: http://localhost:4000/v1.
Auth: Authorization: Bearer $OPENAI_API_KEY.

Vendored tokenizer files ship in the repo under tiktoken_cache/ (no download required for --mode openai).

Commands

Command Purpose
llm list GET /models
llm info [MODEL] GET /model/info (max_in / max_out / mode / input types / key)
llm ping MODEL single chat/completions
llm pings parallel ping of all models (-j)
llm tokens TEXT local token count
llm context MODEL one needle test at a given size
llm bench MODEL size sweep: est vs usage vs OK/FAIL

Examples

uv run llm list
uv run llm info
uv run llm info --json          # includes input_types + supports_* flags
uv run llm ping gpt-4o-mini
uv run llm pings -j 8 --timeout 5

uv run llm tokens "hello world"
uv run llm tokens - --mode openai < prompt.txt

uv run llm context my-model -n 32000
uv run llm context my-model -n 32000 --mode openai --no-random

uv run llm bench my-model
uv run llm bench my-model --start 1000 --stop 64000 --step 8000
uv run llm bench my-model --no-random --json

Common flags: --timeout, --max-tokens, --json (where supported).

Tokenizer (--mode)

Mode How it counts Network
opencode (default) chars / 4 (OpenCode-style) none
openai local tiktoken + chatml overhead none (vendored files only)

Model → encoding for --mode openai: see MODEL_ENCODING in src/helpers/tokenize.py
(default cl100k_base; o200k_base for gpt-4o / o3 / …). Unknown model names fall back to cl100k_base.

Vendored encodings

Committed in-repo (safe to git push):

  • tiktoken_cache/cl100k_base.tiktoken
  • tiktoken_cache/o200k_base.tiktoken

Source of the pin script (optional refresh): GitHub niieani/gpt-tokenizer raw data — not openaipublic.blob.core.windows.net.

bash scripts/pin_tiktoken.sh   # refresh from GitHub if needed

Runtime loads BPE from disk (load_tiktoken_bpe(path)). tiktoken.get_encoding() is not used, so OpenAI CDN is never contacted.

context / bench: prompt shape

Single user message:

[bust=<hex>]          # only when --random (default)
SECRET=NEEDLE-42
<padding>
Find SECRET= in this message. Reply with the SECRET value only.
Flag Behavior
--random (default) bust= + random pad — avoids KV / prefix-cache hits
--no-random no bust=, stable lorem ipsum — prefix may cache

Step success: HTTP 200 and reply contains NEEDLE-42.

bench defaults

  • sizes: 1000 … 128000, step 8000
  • max_tokens=16, timeout=30
  • columns: target, est, usage (prompt_tokens), ms, status, recall
  • summary: max_ok_target, first_fail_target, meta max_input_tokens

Releases

Push a tag v* (e.g. v0.1.0) to run .github/workflows/release.yml:

Artifact Platforms
llm binary (PyInstaller one-file) linux-x86_64, windows-x86_64, macos-x86_64, macos-aarch64
Docker image ghcr.io/hewimetall/litellm-doctor (Python runtime — not a packaged binary)
PyPI package pip install lite-llm-doctor (sdist + wheel; version = tag without v)

Manual workflow_dispatch builds artifacts / validates the image without publishing a GitHub Release, pushing to GHCR, or uploading to PyPI.

PyPI uses Trusted Publishing (OIDC) from this workflow — no API token in repo secrets. Register the publisher on PyPI with workflow release.yml and Environment name left empty (Any).

docker pull ghcr.io/hewimetall/litellm-doctor:latest
docker run --rm -e OPENAI_API_KEY -e OPENAI_BASE_URL ghcr.io/hewimetall/litellm-doctor:latest list

Layout

src/helpers/llm.py          # CLI
src/helpers/tokenize.py     # token estimates + needle_prompt
src/helpers/paths.py        # data/.env roots (dev, wheel, frozen)
scripts/pin_tiktoken.sh     # optional refresh from GitHub
tiktoken_cache/*.tiktoken   # vendored encodings (in git)
.github/workflows/release.yml
Dockerfile                  # GHCR runtime image
.env                        # secrets — gitignored
.env.example                # template

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lite_llm_doctor-0.1.2.tar.gz (2.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lite_llm_doctor-0.1.2-py3-none-any.whl (2.5 MB view details)

Uploaded Python 3

File details

Details for the file lite_llm_doctor-0.1.2.tar.gz.

File metadata

  • Download URL: lite_llm_doctor-0.1.2.tar.gz
  • Upload date:
  • Size: 2.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lite_llm_doctor-0.1.2.tar.gz
Algorithm Hash digest
SHA256 24f71607a916b0492d9fd87c5967791b9630b5dda5a3b0b64b3c5cd11a19f8f8
MD5 3d546fdebc6e6b224b010bee3d8f0094
BLAKE2b-256 5fc0e48db77745604a755cec441f4da28bbc0f4afdcd11528e91dfd357e99176

See more details on using hashes here.

Provenance

The following attestation bundles were made for lite_llm_doctor-0.1.2.tar.gz:

Publisher: release.yml on hewimetall/litellm-doctor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lite_llm_doctor-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for lite_llm_doctor-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3fbe292618128b44b72637962d8d8287326a1e68d2ab49bb142f29da4cddf75f
MD5 11525405bf14aab58401894696b07350
BLAKE2b-256 c99d1c329e203a40a0335b61f1de97fc8d03df77d553f9b7f42d38137d1ce615

See more details on using hashes here.

Provenance

The following attestation bundles were made for lite_llm_doctor-0.1.2-py3-none-any.whl:

Publisher: release.yml on hewimetall/litellm-doctor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page