Skip to main content

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 async acompletion(...) 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

claude_lite_llm-0.1.0.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

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

claude_lite_llm-0.1.0-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

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

Hashes for claude_lite_llm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c5bed3606b25dbb8af0069cfac891a0fb8ccd695192d6a1f0c68d7d7440c3e15
MD5 591b6aa0a6dd6ab7bda1c77664820c9d
BLAKE2b-256 e7b3e3d03f0b30450d9ac2d136dd859b81a1e06be8383cbd019112528813a36b

See more details on using hashes here.

Provenance

The following attestation bundles were made for claude_lite_llm-0.1.0.tar.gz:

Publisher: publish.yaml on santhoshdasari786/claude-lite-llm

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

File details

Details for the file claude_lite_llm-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for claude_lite_llm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0779ce0cb76919d21a21b3b734f63b2f9da88c142f84e4dc543ba321254cc4d5
MD5 ab7ef6b3b4c85d2f1400966ceb57653f
BLAKE2b-256 615321c660c364ed833957d2709664e29865df690812a8f2056308c0834b2a7b

See more details on using hashes here.

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

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

Release history Release notifications | RSS feed

0.2.0

2 files

This release

0.1.0 This release

2 files

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