claude-lite-llm
A lightweight Python wrapper around Anthropic's Claude Code CLI and OpenAI's Codex CLI that allows developers to run Claude and ChatGPT LLMs programmatically using their active subscriptions (CLAUDE_CODE_TOKEN and ChatGPT account / CODEX_ACCESS_TOKEN) — bypassing pay-per-token API keys.
Also includes built-in custom providers for LiteLLM (ClaudeSubscriptionProvider, CodexSubscriptionProvider, and register_with_litellm).
Features
- Subscription-Powered: Authenticate using Claude Code (
CLAUDE_CODE_TOKEN) and OpenAI Codex CLI subscriptions. - Claude & Codex CLI Support: Unified programmatic access to Anthropic Claude (Sonnet, Opus, Haiku) and OpenAI Codex (o3-mini, o3, gpt-4o).
- LiteLLM Native Integration: Exported
ClaudeSubscriptionProviderandCodexSubscriptionProviderclasses plus 1-lineregister_with_litellm()forlitellm.completion(model="claude_sub/sonnet"). - Flexible Message Formats: Pass raw prompt strings or conversational message dicts (
[{"role": "user", "content": "..."}]). - Structured Responses: Access generated text, token usage metrics, latency, and session IDs.
- Safe Execution: Disables tool execution and runs sandboxed (
read-only) by default for pure text completions. - Granular Error Handling: Dedicated exceptions for rate limits (session quota / 429), authentication failures, and CLI execution errors.
Installation
pip install claude-lite-llm
# With LiteLLM support:
pip install "claude-lite-llm[litellm]"
Prerequisites
-
Claude CLI (if using Claude models):
npm install -g @anthropic-ai/claude-code claude setup-token
Add
CLAUDE_CODE_TOKENto your app's.env:CLAUDE_CODE_TOKEN=sk-ant-oat01-...
-
Codex CLI (if using Codex / ChatGPT models):
npm install -g @openai/codex codex login
Or provide
CODEX_ACCESS_TOKENin.env.
Usage
1. Claude Completion
from claude_lite_llm import completion
response = completion("Explain quantum computing in 2 sentences.", model="sonnet")
print(response.content)
print(f"Tokens: {response.usage.input_tokens} in / {response.usage.output_tokens} out")
2. Codex Completion (OpenAI / ChatGPT)
from claude_lite_llm import codex_completion
response = codex_completion("Write a Python function to reverse a linked list.", model="o3-mini")
print(response.content)
print(f"Tokens: {response.usage.input_tokens} in / {response.usage.output_tokens} out")
3. Native Integration with LiteLLM
Use register_with_litellm() to route any LiteLLM call through your Claude or Codex subscription:
import litellm
from claude_lite_llm import register_with_litellm
# Register 'claude_sub' and 'codex_sub' custom providers in LiteLLM
register_with_litellm()
# Call Claude via subscription in LiteLLM
claude_res = litellm.completion(
model="claude_sub/sonnet",
messages=[{"role": "user", "content": "Explain async/await in Python."}],
)
print(claude_res.choices[0].message.content)
# Call Codex via subscription in LiteLLM
codex_res = litellm.completion(
model="codex_sub/o3-mini",
messages=[{"role": "user", "content": "Write a binary search in Python."}],
)
print(codex_res.choices[0].message.content)
You can also instantiate the providers directly:
from claude_lite_llm import ClaudeSubscriptionProvider, CodexSubscriptionProvider
import litellm
litellm.custom_provider_map = [
{"provider": "my_claude", "custom_handler": ClaudeSubscriptionProvider()},
{"provider": "my_codex", "custom_handler": CodexSubscriptionProvider()},
]
4. Asynchronous Completions
import asyncio
from claude_lite_llm import acompletion, codex_acompletion
async def main():
claude_res = await acompletion("Hello from Claude async!")
print("Claude:", claude_res.content)
codex_res = await codex_acompletion("Hello from Codex async!", model="o3-mini")
print("Codex:", codex_res.content)
asyncio.run(main())
5. Handling Rate Limits & Errors
from claude_lite_llm import completion
from claude_lite_llm.exceptions import ClaudeAuthError, ClaudeRateLimitError
try:
response = completion("Hello Claude!")
print(response.content)
except ClaudeRateLimitError as e:
# Captures 429 session limits and subscription reset times
print(f"Rate limit reached: {e}")
except ClaudeAuthError as e:
print(f"Authentication failure: {e}")
Development
uv sync --all-extras --dev
uv run pytest
uv run ruff check .
uv run mypy
Install the git hooks once after cloning:
uv run pre-commit install
Make targets
| Target | Description |
|---|---|
make install |
Sync the dev environment |
make lint |
Ruff lint and format check |
make format |
Apply Ruff formatting and fixes |
make typecheck |
Run mypy in strict mode |
make test |
Run the test suite with coverage |
make build |
Build the sdist and wheel |
make clean |
Remove build and cache artifacts |
License
MIT
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 claude_lite_llm-0.2.0.tar.gz.
File metadata
- Download URL: claude_lite_llm-0.2.0.tar.gz
- Upload date:
- Size: 17.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50fdd65af4fdd11a772fa1c0c2fd67d9644f20b090853fe47d225c42500adc64
|
|
| MD5 |
0597c9fe3f09c3a7fe425186c67ea2dc
|
|
| BLAKE2b-256 |
e9666ddb69479fb8f3f8d4734e91cff36fe96c49b607cc88a7d3f7180c4c63fb
|
Provenance
The following attestation bundles were made for claude_lite_llm-0.2.0.tar.gz:
Publisher:
publish.yaml on santhoshdasari786/claude-lite-llm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
claude_lite_llm-0.2.0.tar.gz -
Subject digest:
50fdd65af4fdd11a772fa1c0c2fd67d9644f20b090853fe47d225c42500adc64 - Sigstore transparency entry: 2755681975
- Sigstore integration time:
-
Permalink:
santhoshdasari786/claude-lite-llm@47754df28f7fad9eb3c18a97b0a09edddd6fa252 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/santhoshdasari786
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@47754df28f7fad9eb3c18a97b0a09edddd6fa252 -
Trigger Event:
push
-
Statement type:
File details
Details for the file claude_lite_llm-0.2.0-py3-none-any.whl.
File metadata
- Download URL: claude_lite_llm-0.2.0-py3-none-any.whl
- Upload date:
- Size: 15.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19b137778c94fef45d0abaa62573afb581b47200a3b01db0b33ac8dd446c36a7
|
|
| MD5 |
f26676854541a6040eb44555e4a47544
|
|
| BLAKE2b-256 |
ef542c3bc56fbd95dcb076aa27f59e25867ec2f560d9b2677b8f239c936fbeb6
|
Provenance
The following attestation bundles were made for claude_lite_llm-0.2.0-py3-none-any.whl:
Publisher:
publish.yaml on santhoshdasari786/claude-lite-llm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
claude_lite_llm-0.2.0-py3-none-any.whl -
Subject digest:
19b137778c94fef45d0abaa62573afb581b47200a3b01db0b33ac8dd446c36a7 - Sigstore transparency entry: 2755682058
- Sigstore integration time:
-
Permalink:
santhoshdasari786/claude-lite-llm@47754df28f7fad9eb3c18a97b0a09edddd6fa252 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/santhoshdasari786
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@47754df28f7fad9eb3c18a97b0a09edddd6fa252 -
Trigger Event:
push
-
Statement type: