Skip to main content

A zen, simple, and unified API to prompt LLMs from Anthropic, Google, OpenAI, and more, using only the requests library.

Project description

🧘‍♂️ ZenLLM

PyPI version License: MIT Python 3.8+

The zen, simple, and unified API to prompt LLMs from different providers using a single function call.

Our Goal: No fancy dependencies, no SDK bloat. Just requests and your API keys. Easily switch between models and providers without changing your code.

✨ Key Features

  • Unified API: A single prompt() function for Anthropic, Google, and OpenAI.
  • Easy Model Switching: Change models and providers with a single model argument.
  • Lightweight: Built with only the requests library. No heavy SDKs to install.
  • Simple Authentication: Just set your provider's API key as an environment variable.

🚀 Installation

pip install zenllm

💡 Usage

First, make sure you've set your API key as an environment variable (e.g., export OPENAI_API_KEY="your-key").

Basic Prompt

The default model is gpt-4.1. You can change this by setting the ZENLLM_DEFAULT_MODEL environment variable.

from zenllm import prompt

# Uses the default model (either the fallback or ZENLLM_DEFAULT_MODEL)
response = prompt("Why is the sky blue?")
print(response)

Using another Provider (Google's Gemini)

Simply change the model name to use a different provider.

from zenllm import prompt

response = prompt(
    "Why is the sky blue?",
    model="gemini-2.5-pro",
    system_prompt="Reply only in French."
)
print(response)

Using Anthropic

from zenllm import prompt

response = prompt(
    "Tell me a three sentence bedtime story about a unicorn.",
    model="claude-sonnet-4-20250514"
)
print(response)

Using TogetherAI

To use models from TogetherAI, prefix the model name with together/.

from zenllm import prompt

response = prompt(
    "What are the top 3 things to do in New York?",
    model="together/meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo"
)
print(response)

Streaming Responses

Set stream=True to get a generator of response chunks.

from zenllm import prompt

response_stream = prompt(
    "Tell me a story about a robot.", 
    model="claude-sonnet-4-20250514", 
    stream=True
)
for chunk in response_stream:
    print(chunk, end="", flush=True)

Using OpenAI-Compatible APIs

You can use zenllm with any OpenAI-compatible API endpoint, such as local models (e.g., via Ollama, LM Studio) or other custom services. This is done by providing a base_url. zenllm will automatically append /chat/completions to this URL.

By providing the base_url parameter, zenllm will automatically use the OpenAI provider, allowing you to use any model name served by that endpoint. You can also provide a custom api_key if required.

from zenllm import prompt

# Example with a local model endpoint (no API key needed)
# The model name 'qwen3:30b' does not need a 'gpt-' prefix.
response = prompt(
    "Why is the sky blue?",
    model="qwen3:30b", 
    base_url="http://localhost:11434/v1"
)
print(response)

# Example with a custom API that requires its own key
response = prompt(
    "Why is the sky blue?",
    model="custom-model-name",
    base_url="https://api.custom-provider.com/v1",
    api_key="your-custom-api-key"
)
print(response)

# Streaming also works with compatible APIs
stream = prompt(
    "Tell me a story.",
    model="qwen3:30b", 
    base_url="http://localhost:11434/v1",
    stream=True
)
for chunk in stream:
    print(chunk, end="", flush=True)

✅ Supported Providers

Provider Environment Variable Model Prefix Example Models
Anthropic ANTHROPIC_API_KEY claude claude-sonnet-4-20250514, claude-opus-4-20250514
Deepseek DEEPSEEK_API_KEY deepseek deepseek-chat, deepseek-reasoner
Google GEMINI_API_KEY gemini gemini-2.5-pro, gemini-2.5-flash
OpenAI OPENAI_API_KEY gpt gpt-4.1
TogetherAI TOGETHER_API_KEY together together/meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo

Note: For OpenAI-compatible endpoints (like local models), provide the base_url parameter. This will route the request correctly, regardless of the model name's prefix.

📜 License

MIT License - Copyright (c) 2025 Koen van Eijk

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

zenllm-0.1.6.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

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

zenllm-0.1.6-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file zenllm-0.1.6.tar.gz.

File metadata

  • Download URL: zenllm-0.1.6.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for zenllm-0.1.6.tar.gz
Algorithm Hash digest
SHA256 89bee8a91456d3364ff68b71024158b4f8a88f84f215085b2e9ff7fffbda4df5
MD5 76f2171c0d5f255a642fa53d5e712028
BLAKE2b-256 52510baebc0506c9d6e4ef1e21a56ec7296f87308598ca123c9b38f6c82f452c

See more details on using hashes here.

Provenance

The following attestation bundles were made for zenllm-0.1.6.tar.gz:

Publisher: publish_to_pypi.yml on koenvaneijk/zenllm

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

File details

Details for the file zenllm-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: zenllm-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for zenllm-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 76c70df1b7bc11a04b1d0a924df28b172ed380e0999c37248eca035289783d55
MD5 e7abdc9b5801f05408434a3b43046cf2
BLAKE2b-256 d1ea833864609bc6338987e883d1b8ccc0e60087c97e37ce2e71f4fc3ddace96

See more details on using hashes here.

Provenance

The following attestation bundles were made for zenllm-0.1.6-py3-none-any.whl:

Publisher: publish_to_pypi.yml on koenvaneijk/zenllm

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

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