Skip to main content

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 ClaudeSubscriptionProvider and CodexSubscriptionProvider classes plus 1-line register_with_litellm() for litellm.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

  1. Claude CLI (if using Claude models):

    npm install -g @anthropic-ai/claude-code
    claude setup-token
    

    Add CLAUDE_CODE_TOKEN to your app's .env:

    CLAUDE_CODE_TOKEN=sk-ant-oat01-...
    
  2. Codex CLI (if using Codex / ChatGPT models):

    npm install -g @openai/codex
    codex login
    

    Or provide CODEX_ACCESS_TOKEN in .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

claude_lite_llm-0.2.0.tar.gz (17.1 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.2.0-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

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

Hashes for claude_lite_llm-0.2.0.tar.gz
Algorithm Hash digest
SHA256 50fdd65af4fdd11a772fa1c0c2fd67d9644f20b090853fe47d225c42500adc64
MD5 0597c9fe3f09c3a7fe425186c67ea2dc
BLAKE2b-256 e9666ddb69479fb8f3f8d4734e91cff36fe96c49b607cc88a7d3f7180c4c63fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for claude_lite_llm-0.2.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.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for claude_lite_llm-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 19b137778c94fef45d0abaa62573afb581b47200a3b01db0b33ac8dd446c36a7
MD5 f26676854541a6040eb44555e4a47544
BLAKE2b-256 ef542c3bc56fbd95dcb076aa27f59e25867ec2f560d9b2677b8f239c936fbeb6

See more details on using hashes here.

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

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

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 files

0.1.0

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