SmolLLM
A minimal Python library for interacting with various LLM providers, featuring automatic API key load balancing and streaming responses.
Installation
pip install smolllm
uv add "smolllm @ ../smolllm"
Quick Start
import asyncio
from smolllm import ask_llm
async def main():
response = await ask_llm(
"Say hello world",
model="gemini/gemini-2.0-flash"
)
print(response)
if __name__ == "__main__":
asyncio.run(main())
Reasoning Effort
For reasoning-capable models, pass reasoning_effort through to the provider.
Useful for Ollama reasoning models where omitting it can make replies much slower.
response = await ask_llm(
"Reply with one word.",
model="ollama/qwen3.5:0.8b",
base_url="http://rocry-ubuntu.local:11434/v1",
reasoning_effort="none",
)
Provider Configuration
Format: provider/model_name (e.g., openai/gpt-4, gemini/gemini-2.0-flash)
A bare model name (no /) targets an endpoint directly — pass base_url and api_key explicitly (no env fallback):
response = await ask_llm(
"hi",
model="gpt-4",
base_url="https://my-proxy.example/v1",
api_key="sk-xxx",
)
API Keys
The library looks for API keys in environment variables following the pattern: {PROVIDER}_API_KEY
Example:
# .env
OPENAI_API_KEY=sk-xxx
GEMINI_API_KEY=key1,key2 # Multiple keys supported
Key/endpoint pairs rejected with a permanent credential status (for example
CONSUMER_SUSPENDED or API_KEY_INVALID) are removed from the active pool for
the rest of the process lifetime. Error logs redact credential-shaped content;
eviction is identified only by a one-way key fingerprint.
Custom Base URLs
Override default API endpoints using: {PROVIDER}_BASE_URL
Example:
OPENAI_BASE_URL=https://custom.openai.com/v1
OLLAMA_BASE_URL=http://localhost:11434/v1
Advanced Configuration
You can combine multiple keys and base URLs in several ways:
- One key with multiple base URLs:
OLLAMA_API_KEY=ollama
OLLAMA_BASE_URL=http://localhost:11434/v1,http://other-server:11434/v1
- Multiple keys with one base URL:
GEMINI_API_KEY=key1,key2
GEMINI_BASE_URL=https://api.gemini.com/v1
- Paired keys and base URLs:
# Must have equal number of keys and URLs
# The library will randomly select matching pairs
GEMINI_API_KEY=key1,key2
GEMINI_BASE_URL=https://api.gemini.com/v1,https://api.gemini.com/v2
Environment Setup Best Practices
When using SmolLLM in your project, you should handle environment variables at your application level:
- Create a
.envfile:
# .env
OPENAI_API_KEY=sk-xxx
GEMINI_API_KEY=xxx,xxx2
ANTHROPIC_API_KEY=sk-xxx
- Load the file at the application/process boundary:
uv run --env-file .env app.py
Tips
- Keep sensitive API keys in
.env(add to .gitignore) - Create
.env.examplefor documentation - For production, consider using your platform's secret management system
- When using multiple keys, separate with commas (no spaces)
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 smolllm-0.10.0.tar.gz.
File metadata
- Download URL: smolllm-0.10.0.tar.gz
- Upload date:
- Size: 78.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8cd2b9dd29a23416bf5c5fc7c2fa21d9d78be13ef3bad60c26a848963163f376
|
|
| MD5 |
61c4f7e4103a61c636ea4eb10d5c9a57
|
|
| BLAKE2b-256 |
c549f7f98011f9f92a4b3263805e10991a077c1612e7ff30133f9df3c286d49e
|
Provenance
The following attestation bundles were made for smolllm-0.10.0.tar.gz:
Publisher:
release.yml on RoCry/smolllm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
smolllm-0.10.0.tar.gz -
Subject digest:
8cd2b9dd29a23416bf5c5fc7c2fa21d9d78be13ef3bad60c26a848963163f376 - Sigstore transparency entry: 2526593855
- Sigstore integration time:
-
Permalink:
RoCry/smolllm@16c44277034cd407755e052076cd3ee99a4946d4 -
Branch / Tag:
refs/tags/v0.10.0 - Owner: https://github.com/RoCry
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@16c44277034cd407755e052076cd3ee99a4946d4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file smolllm-0.10.0-py3-none-any.whl.
File metadata
- Download URL: smolllm-0.10.0-py3-none-any.whl
- Upload date:
- Size: 30.9 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 |
42386746c84ec45bd15710ae0a86ff686b52c916b307de11bf7f8dab90f7ce5e
|
|
| MD5 |
c01522e64097a511645b1c48f722c55a
|
|
| BLAKE2b-256 |
b28078db561545dfddd224961ec010da0ff7b015213122a45ae4b75ee542606d
|
Provenance
The following attestation bundles were made for smolllm-0.10.0-py3-none-any.whl:
Publisher:
release.yml on RoCry/smolllm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
smolllm-0.10.0-py3-none-any.whl -
Subject digest:
42386746c84ec45bd15710ae0a86ff686b52c916b307de11bf7f8dab90f7ce5e - Sigstore transparency entry: 2526593877
- Sigstore integration time:
-
Permalink:
RoCry/smolllm@16c44277034cd407755e052076cd3ee99a4946d4 -
Branch / Tag:
refs/tags/v0.10.0 - Owner: https://github.com/RoCry
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@16c44277034cd407755e052076cd3ee99a4946d4 -
Trigger Event:
push
-
Statement type: