LangChain integration for rezunate-llm-sdk
Project description
langchain-rezunate
LangChain integration for rezunate-llm-sdk.
Use any provider supported by Rezunate (OpenAI, Anthropic, Google) through the standard LangChain interfaces — chat models, tool calling, prompt templates, runnables, and guardrails — backed by a single unified gateway.
Features
ChatRezunate— aBaseChatModelsupportinginvoke/ainvoke, streaming-free generation, and tool calling viabind_tools().RezunateGuardrailsMiddleware— wrap any chat-model runnable to scan input and output messages against Rezunate guardrails.RezunatePromptTemplate— fetch a prompt from the Rezunate LLM-Router by slug and render it with mustache ({{var}}) variables.chat_complete_runnable— a lightweightRunnableLambdawrapper around the SDK'schat_complete, for composing into LCEL chains.RezunateConfig— shared configuration with environment-variable key resolution.RezunateAPIError— a typed exception for provider/SDK errors.
Installation
pip install langchain-rezunate
From source (development)
pip install -e ".[test]"
Requires Python 3.10+.
Quickstart
from langchain_rezunate import ChatRezunate
llm = ChatRezunate(
provider="anthropic", # or "openai", "google"
model="claude-sonnet-4-20250514",
api_key="your-provider-api-key",
max_tokens=100,
)
response = llm.invoke("Hello!")
print(response.content)
Async is supported out of the box:
response = await llm.ainvoke("Hello!")
Configuration & API keys
You can pass api_key= directly, or let it resolve from the environment. The provider
key is resolved in this order:
api_key/provider_api_keypassed directlyREZUNATE_API_KEY(override for any provider){PROVIDER}_API_KEY—OPENAI_API_KEY,ANTHROPIC_API_KEY,GROK_API_KEY,LLAMA_API_KEY,DEEPSEEK_API_KEY,QWEN_API_KEYorGOOGLE_API_KEY
The control-plane (LLM-Router) key, used by RezunatePromptTemplate and server-side
guardrails, resolves from control_plane_api_key or the REZUNATE_LLM_API_KEY env var.
from langchain_rezunate import ChatRezunate, RezunateConfig
config = RezunateConfig(provider="openai", provider_api_key="sk-...")
llm = ChatRezunate(provider="openai", model="gpt-4o-mini", config=config)
Tool calling
Bind Pydantic models, functions, or LangChain tools and the model will return
structured tool_calls:
from pydantic import BaseModel, Field
from langchain_rezunate import ChatRezunate
class GetWeather(BaseModel):
"""Look up the current weather for a city."""
city: str = Field(description="City name, e.g. 'Tokyo'")
llm = ChatRezunate(provider="openai", model="gpt-4o-mini", api_key="sk-...")
llm_with_tools = llm.bind_tools([GetWeather])
response = llm_with_tools.invoke("What's the weather in Tokyo?")
print(response.tool_calls)
# [{'name': 'GetWeather', 'args': {'city': 'Tokyo'}, 'id': '...', 'type': 'tool_call'}]
tool_choice accepts "auto", "required", "none", "any", or a specific tool name.
Remote prompt templates
Fetch and render a prompt managed in the Rezunate LLM-Router:
from langchain_rezunate import RezunatePromptTemplate
tmpl = RezunatePromptTemplate(slug_id="welcome", input_variables=["name"])
print(tmpl.format(name="Sam"))
# Or let input_variables be discovered from the remote prompt:
tmpl = RezunatePromptTemplate.from_slug("welcome")
Guardrails
Wrap a chat model to scan both input and output against your guardrails config:
from langchain_rezunate import ChatRezunate, RezunateGuardrailsMiddleware
from rezunate_llm_sdk import load_guardrails
model = ChatRezunate(provider="openai", model="gpt-4o-mini", api_key="sk-...")
guarded = RezunateGuardrailsMiddleware(
model,
guardrails_config=load_guardrails("guardrails.yaml"),
# or: guardrails_path="guardrails.yaml"
)
guarded.invoke("Hello!")
Guardrails can also be applied directly on the model via the guardrails_config argument
of ChatRezunate, which forwards to the SDK's chat_complete.
Composing with LCEL
chat_complete_runnable returns a RunnableLambda you can pipe into LCEL chains:
from langchain_core.prompts import ChatPromptTemplate
from langchain_rezunate import chat_complete_runnable
prompt = ChatPromptTemplate.from_template("Translate to French: {text}")
chain = prompt | chat_complete_runnable(
provider="openai", model="gpt-4o-mini", api_key="sk-..."
)
print(chain.invoke({"text": "Good morning"}).content)
Development
Run the test suite:
pip install -e ".[test]"
pytest
License
MIT © Deeptechs.ai
Project details
Release history Release notifications | RSS feed
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 langchain_rezunate-0.1.0.tar.gz.
File metadata
- Download URL: langchain_rezunate-0.1.0.tar.gz
- Upload date:
- Size: 54.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad9b37711964ade102a9c7ec69fd7ea4df8241a50dcfc7ceb2c3833b09ed9e45
|
|
| MD5 |
4f8cff7362513e020ea8b7e03e4d297d
|
|
| BLAKE2b-256 |
af66f93376bafacd8634ec7f5977371570153a8a529f9b10d95e02c9346422ee
|
File details
Details for the file langchain_rezunate-0.1.0-py3-none-any.whl.
File metadata
- Download URL: langchain_rezunate-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c857953738571c471b50bc4730d10c1c4561ed9bbf75880e2caf1475fa801ac7
|
|
| MD5 |
3825167d872f86b93c496259ba3c9079
|
|
| BLAKE2b-256 |
c9638b1e00204b633a2ce4b70a9eaf412f65bb547b82bf131f07fbcb430798cd
|