Skip to main content

Zero-dependency LiteLLM-compatible facade for OpenAI, Anthropic, and OpenRouter

Project description

slimllm

Zero-dependency Python facade for OpenAI, Anthropic, and OpenRouter — designed for AWS Lambda.

Why

  • No external dependencies — uses only Python stdlib (http.client, ssl, json, asyncio)
  • LiteLLM-compatible API — same completion() call signature, swap without rewriting callers
  • Lambda-friendly — tiny cold start, no bloat
  • Supports streaming, tool use, and JSON mode

Supported providers

Model prefix Provider Env var
gpt-*, o1-*, o3-* OpenAI OPENAI_API_KEY
claude-*, anthropic/… Anthropic ANTHROPIC_API_KEY
openrouter/… OpenRouter OPENROUTER_API_KEY

Install

pip install slimllm

Usage

import slimllm

# Non-streaming
resp = slimllm.completion(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(resp.content)

# Streaming
stream = slimllm.completion("claude-3-5-sonnet-20241022", messages, stream=True)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="", flush=True)
final = stream.get_final_response()

# Async
resp = await slimllm.acompletion("gpt-4o", messages)

# Async streaming
async for chunk in slimllm.astream("claude-3-5-sonnet-20241022", messages):
    print(chunk.choices[0].delta.content or "", end="")

# Tool use (OpenAI format — auto-converted for Anthropic)
tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Get current weather",
        "parameters": {
            "type": "object",
            "properties": {"city": {"type": "string"}},
            "required": ["city"],
        },
    },
}]
resp = slimllm.completion("claude-3-5-sonnet-20241022", messages, tools=tools)

# OpenRouter
resp = slimllm.completion("openrouter/meta-llama/llama-3.3-70b-instruct", messages)

API key resolution

Keys are looked up in this order:

  1. Explicit api_key= kwarg
  2. Environment variable (OPENAI_API_KEY, ANTHROPIC_API_KEY, OPENROUTER_API_KEY)

Response shape

All providers return the same OpenAI-shaped types:

resp.content                          # str | None
resp.tool_calls                       # list[ToolCall] | None
resp.choices[0].finish_reason         # "stop" | "length" | "tool_calls"
resp.usage.prompt_tokens
resp.usage.completion_tokens

License

MIT

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

slimllm-1.2.0.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

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

slimllm-1.2.0-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

Details for the file slimllm-1.2.0.tar.gz.

File metadata

  • Download URL: slimllm-1.2.0.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for slimllm-1.2.0.tar.gz
Algorithm Hash digest
SHA256 ea61c8cbbddf91f12612e7897d12bca05ed5ad706a8e98f7d423d74814d8835f
MD5 fc5db759686c4ec968c363a1d5d59c2e
BLAKE2b-256 c6c3258f2962df96d6c2c7b89a525524a914fe4c760432b2835d2990f341d068

See more details on using hashes here.

File details

Details for the file slimllm-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: slimllm-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 21.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for slimllm-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 81acf00515969031bc2eeb78fa7a92d1f4a5b0b0c2440854e1f070cbfc11a988
MD5 7a7ffc0181e1bf71888513cca623a402
BLAKE2b-256 15997d29b9aa0bf59caf43863ffeeea21c1a7a95f9d5193b2632bca5a5ab9064

See more details on using hashes here.

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