claude-lite-llm
A lightweight Python wrapper around Anthropic's claude (Claude Code) CLI that allows developers to run Claude LLMs programmatically using their active Claude Pro/Max subscription via CLAUDE_CODE_TOKEN — bypassing pay-per-token API keys.
Features
- Subscription-Powered: Authenticate using your Claude Code subscription token (
CLAUDE_CODE_TOKEN) instead of standard Anthropic API keys. - LiteLLM / OpenAI Style API: Simple
completion(...)and asyncacompletion(...)functions. - 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 built-in CLI tool execution (file editing / bash execution) 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
Prerequisites
Ensure the Claude Code CLI is installed on your system:
npm install -g @anthropic-ai/claude-code
# or native install:
# curl -fsSL https://claude.ai/install.sh | bash
Generate your subscription token (or retrieve your existing session token):
claude setup-token
Add the token to your .env file or export it:
CLAUDE_CODE_TOKEN=sk-ant-oat01-...
Usage
1. Basic Completion
from claude_lite_llm import completion
response = completion("Explain quantum computing in 2 sentences.")
print(response.content)
print(f"Tokens: {response.usage.input_tokens} in / {response.usage.output_tokens} out")
2. Multi-Message Conversation
from claude_lite_llm import completion
messages = [
{"role": "system", "content": "You are an expert Python architect."},
{"role": "user", "content": "What is the best way to structure an async CLI wrapper?"},
]
response = completion(messages, model="sonnet")
print(response.content)
3. Using ClaudeClient
from claude_lite_llm import ClaudeClient
client = ClaudeClient(
token="sk-ant-...", # Optional: loads from CLAUDE_CODE_TOKEN by default
default_model="sonnet", # 'sonnet', 'opus', or 'haiku'
)
response = client.completion("Draft a quick haiku about coding.")
print(response.content)
4. Asynchronous Completion
import asyncio
from claude_lite_llm import acompletion
async def main():
response = await acompletion("Write a unit test with pytest for a palindrome function.")
print(response.content)
asyncio.run(main())
5. Handling Rate Limits & Errors
When session limits or quota thresholds are reached on your Claude subscription, claude-lite-llm raises typed exceptions:
from claude_lite_llm import completion
from claude_lite_llm.exceptions import ClaudeRateLimitError, ClaudeAuthError
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.1.0.tar.gz.
File metadata
- Download URL: claude_lite_llm-0.1.0.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5bed3606b25dbb8af0069cfac891a0fb8ccd695192d6a1f0c68d7d7440c3e15
|
|
| MD5 |
591b6aa0a6dd6ab7bda1c77664820c9d
|
|
| BLAKE2b-256 |
e7b3e3d03f0b30450d9ac2d136dd859b81a1e06be8383cbd019112528813a36b
|
Provenance
The following attestation bundles were made for claude_lite_llm-0.1.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.1.0.tar.gz -
Subject digest:
c5bed3606b25dbb8af0069cfac891a0fb8ccd695192d6a1f0c68d7d7440c3e15 - Sigstore transparency entry: 2729200629
- Sigstore integration time:
-
Permalink:
santhoshdasari786/claude-lite-llm@29327ff8eee5c73284822363cfb0cfb957dd8daf -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/santhoshdasari786
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@29327ff8eee5c73284822363cfb0cfb957dd8daf -
Trigger Event:
push
-
Statement type:
File details
Details for the file claude_lite_llm-0.1.0-py3-none-any.whl.
File metadata
- Download URL: claude_lite_llm-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.4 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 |
0779ce0cb76919d21a21b3b734f63b2f9da88c142f84e4dc543ba321254cc4d5
|
|
| MD5 |
ab7ef6b3b4c85d2f1400966ceb57653f
|
|
| BLAKE2b-256 |
615321c660c364ed833957d2709664e29865df690812a8f2056308c0834b2a7b
|
Provenance
The following attestation bundles were made for claude_lite_llm-0.1.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.1.0-py3-none-any.whl -
Subject digest:
0779ce0cb76919d21a21b3b734f63b2f9da88c142f84e4dc543ba321254cc4d5 - Sigstore transparency entry: 2729201382
- Sigstore integration time:
-
Permalink:
santhoshdasari786/claude-lite-llm@29327ff8eee5c73284822363cfb0cfb957dd8daf -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/santhoshdasari786
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@29327ff8eee5c73284822363cfb0cfb957dd8daf -
Trigger Event:
push
-
Statement type: