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:
- Explicit
api_key=kwarg - 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
Metadata
Release files for slimllm 1.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| slimllm-1.4.1.tar.gz | 32.4 kB | Without provenance | Details for slimllm-1.4.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| slimllm-1.4.1-py3-none-any.whl | Python 3 | none | any | Details for slimllm-1.4.1-py3-none-any.whl |
Total release size: 61.0 kB
Release files / slimllm-1.4.1.tar.gz
| Download URL | slimllm-1.4.1.tar.gz |
|---|---|
| Size | 32.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a6e28b33f9e1880c3a68e4e9c754d0260fa2fc96987aa56e5226aee43c632f09
|
|
BLAKE2b-256 checksum How to use checksums |
a29485becdf72287e44075fe84f9b691c7e087838bd4d1713666ed89518ab9a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / slimllm-1.4.1-py3-none-any.whl
| Download URL | slimllm-1.4.1-py3-none-any.whl |
|---|---|
| Size | 28.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aacb0ceb0f6e55f16f7add32ce0c01f9b92b50f766b5cdca3da309a75ad1a888
|
|
BLAKE2b-256 checksum How to use checksums |
c32da570da77adb3f8e9c665bdfa1a194b6e748a6a848c1b1abd58ad292d90bc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for slimllm 1.4.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.