Skip to main content

Minimal LLM client getter for OpenAI Responses + OpenAI-compatible Chat Completions.

Project description

kantan-llm 😺✨

A tiny Python library that removes the boring boilerplate (keys/URLs/provider selection) so you can call LLMs with a single get_llm() 💨

Install 📦

pip install kantan-llm

Quickstart 🚀

OpenAI (Responses API is the source of truth)

export OPENAI_API_KEY="sk-..."
from kantan_llm import get_llm

llm = get_llm("gpt-4.1-mini")
res = llm.responses.create(input="Say hi in one short line.")
print(res.output_text)

OpenAI-compatible (Chat Completions is the source of truth)

LMStudio (example: openai/gpt-oss-20b)

export LMSTUDIO_BASE_URL="http://192.168.11.16:1234"  # `/v1` is optional
from kantan_llm import get_llm

llm = get_llm("openai/gpt-oss-20b", provider="lmstudio")
cc = llm.chat.completions.create(messages=[{"role": "user", "content": "Return exactly: OK"}], max_tokens=16)
print(cc.choices[0].message.content)

Ollama (example)

export OLLAMA_BASE_URL="http://localhost:11434"  # `/v1` is optional
from kantan_llm import get_llm

llm = get_llm("llama3.2", provider="ollama")
cc = llm.chat.completions.create(messages=[{"role": "user", "content": "Return exactly: OK"}], max_tokens=16)
print(cc.choices[0].message.content)

OpenRouter (includes Claude, etc.)

export OPENROUTER_API_KEY="..."
# Or alias (for convenience): `CLAUDE_API_KEY` is treated as an OpenRouter key too
# export CLAUDE_API_KEY="..."
from kantan_llm import get_llm

llm = get_llm("claude-3-5-sonnet-latest")  # if key exists -> provider=openrouter (inferred)
cc = llm.chat.completions.create(messages=[{"role": "user", "content": "Return exactly: OK"}], max_tokens=16)
print(cc.choices[0].message.content)

Google (Gemini via an OpenAI-compatible endpoint)

export GOOGLE_API_KEY="..."
from kantan_llm import get_llm

llm = get_llm("gemini-2.0-flash")
cc = llm.chat.completions.create(messages=[{"role": "user", "content": "Return exactly: OK"}], max_tokens=16)
print(cc.choices[0].message.content)

Provider rules 🧭

  • gpt-*openai
  • gemini-*google
  • claude-*openrouter (if OPENROUTER_API_KEY or CLAUDE_API_KEY is set), otherwise compat (some names are normalized for OpenRouter)
  • If the model name is not recognizable, it picks the first available provider by env vars: lmstudioollamaopenroutergoogle

Explicit provider 🎯

from kantan_llm import get_llm

llm = get_llm("gpt-4.1-mini", provider="openai")

Fallback (order = priority) 🧯

from kantan_llm import get_llm

llm = get_llm("gpt-4.1-mini", providers=["openai", "lmstudio", "openrouter"])

Environment variables 🔐

  • OpenAI
    • OPENAI_API_KEY (required)
    • OPENAI_BASE_URL (optional)
  • Generic compatible (compat)
    • KANTAN_LLM_BASE_URL (required)
    • KANTAN_LLM_API_KEY (optional; falls back to a dummy value)
  • LMStudio
    • LMSTUDIO_BASE_URL (required)
  • Ollama
    • OLLAMA_BASE_URL (required)
  • OpenRouter
    • OPENROUTER_API_KEY (required)
    • CLAUDE_API_KEY (optional; alias for OPENROUTER_API_KEY)
  • Google
    • GOOGLE_API_KEY (required)
    • GOOGLE_BASE_URL (optional)

Error example 💥

  • Missing OpenAI key: python -c 'from kantan_llm import get_llm; get_llm(\"gpt-4.1-mini\")'[kantan-llm][E2] Missing OPENAI_API_KEY for provider: openai

Tests 🧪

Live integration tests (real APIs) are opt-in:

KANTAN_LLM_RUN_LIVE_TESTS=1 pytest -q -m integration

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

kantan_llm-0.1.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

kantan_llm-0.1.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file kantan_llm-0.1.0.tar.gz.

File metadata

  • Download URL: kantan_llm-0.1.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for kantan_llm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cbfccb01e865e0aedf8a5601ec86830c121d490e502dea3422a4216a9f6d75b5
MD5 00b729fb26081f26c2ff41335792c6df
BLAKE2b-256 e7c1163a0cfd0009159662b4fd7bf819072bdccf01d09d3088e404f3d147dfa5

See more details on using hashes here.

File details

Details for the file kantan_llm-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: kantan_llm-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for kantan_llm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 85803ab1ba2ce2f0142140b8d04c66cffe1229425f4b1322947ee275044ee5f5
MD5 d6264acf010aa4bc6ee34123e1fc1639
BLAKE2b-256 458fcdf5b2a75638901781bc03228163c2270c1c6c450c55586f007626e62e6d

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