langchain-keln
LangChain chat model for Keln, an inference platform for open models.
ChatKeln works like ChatOpenAI: invoke, stream, async calls, tool calling, structured output and agents. It also handles 2 Keln details for you. It reads the reasoning trace that reasoning models return, and it sends that trace back on assistant messages in a tool call loop.
Install
pip install -U langchain-keln
Get an API key
- Sign up at app.keln.ai/signup.
- Go to Keys → Create key.
- Set the key as an environment variable:
export KELN_API_KEY="your-api-key"
On Windows PowerShell:
$env:KELN_API_KEY = "your-api-key"
Chat
from langchain_keln import ChatKeln
llm = ChatKeln(model="zai-org/glm-5.3", reasoning_effort="low")
print(llm.invoke("Explain prompt caching in 1 sentence.").content)
for chunk in llm.stream("Write a haiku about open models."):
print(chunk.text, end="", flush=True)
The model list with context lengths and reasoning levels is at docs.keln.ai/models-pricing. The same list is available as JSON at GET https://api.keln.ai/v1/models, with no key needed.
Tool calling and structured output
from langchain_core.tools import tool
from pydantic import BaseModel
@tool
def get_weather(city: str) -> str:
"""Return the current weather for a city."""
return "sunny, 21 C"
llm_with_tools = llm.bind_tools([get_weather])
print(llm_with_tools.invoke("What is the weather in Paris?").tool_calls)
class Summary(BaseModel):
title: str
bullets: list[str]
print(
llm.with_structured_output(Summary).invoke(
"Summarize what an inference platform does."
)
)
Agents
With the langchain package installed (pip install -U langchain):
from langchain.agents import create_agent
agent = create_agent(ChatKeln(model="moonshotai/kimi-k3"), tools=[get_weather])
agent.invoke(
{"messages": [{"role": "user", "content": "What is the weather in Paris?"}]}
)
Reasoning
Most Keln models can think before they answer. Set the level with reasoning_effort, for example "none", "low", "high" or "max". Each model lists the levels it accepts in /v1/models. If you leave it out, each model uses the default level listed in /v1/models.
The trace is in message.additional_kwargs["reasoning_content"], in invoke and in stream. When you pass the conversation back, ChatKeln sends each assistant message's trace with it, so the model keeps its train of thought across tool calls.
Configuration
| Argument | Env var | Default |
|---|---|---|
api_key |
KELN_API_KEY |
required |
base_url |
KELN_API_BASE |
https://api.keln.ai/v1 |
model |
zai-org/glm-5.3 |
Every other ChatOpenAI argument (temperature, max_tokens, timeout, max_retries, model_kwargs and others) works the same way. max_tokens covers reasoning and answer together.
ChatKeln uses the /v1/chat/completions endpoint. It sends the system role and max_tokens, and leaves out the store field.
Docs
- Keln docs: docs.keln.ai
- Models and prices: docs.keln.ai/models-pricing
Development
pip install -e . --group test --group lint --group typing
pytest tests/unit_tests --disable-socket --allow-unix-socket
KELN_API_KEY=... pytest tests/integration_tests
ruff check . && ruff format --check . && mypy langchain_keln tests
License
MIT, Keln.
Metadata
Release files for langchain-keln 0.1.0
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 |
|---|---|---|---|---|
| langchain_keln-0.1.0.tar.gz | 10.1 kB | Without provenance | Details for langchain_keln-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| langchain_keln-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for langchain_keln-0.1.0-py3-none-any.whl |
Total release size: 17.5 kB
Release files / langchain_keln-0.1.0.tar.gz
| Download URL | langchain_keln-0.1.0.tar.gz |
|---|---|
| Size | 10.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
76764ca186dcb6685d08bf4b6d15628879ddeebcb430abc83e991ce416bc1c56
|
|
BLAKE2b-256 checksum How to use checksums |
f1a41ff24fdc73fd2ccb9ecbd487fcc14a6f4274b84aba094aa808856e7a3bef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Release files / langchain_keln-0.1.0-py3-none-any.whl
| Download URL | langchain_keln-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fbb0b0a8aa2dc9d9184f2c9ef87ee9b76fd40eb7d5332095359a175112397a60
|
|
BLAKE2b-256 checksum How to use checksums |
acea03782dc05b65232e7675c1042a59bc48970d73fc0a496de04d2308671a16
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Security for langchain-keln 0.1.0
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.