Skip to main content

langchain-rezunate

PyPI version Python versions License: MIT

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 — a BaseChatModel supporting invoke/ainvoke, streaming-free generation, and tool calling via bind_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 lightweight RunnableLambda wrapper around the SDK's chat_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:

  1. api_key / provider_api_key passed directly
  2. REZUNATE_API_KEY (override for any provider)
  3. {PROVIDER}_API_KEY — OPENAI_API_KEY, ANTHROPIC_API_KEY, GROK_API_KEY, LLAMA_API_KEY, DEEPSEEK_API_KEY, QWEN_API_KEY or GOOGLE_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

Release files for langchain-rezunate 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-rezunate 0.1.0
File Size Uploaded
langchain_rezunate-0.1.0.tar.gz 54.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain-rezunate 0.1.0
File Interpreter ABI Platform
langchain_rezunate-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 68.7 kB

Release files / langchain_rezunate-0.1.0.tar.gz

Download URL langchain_rezunate-0.1.0.tar.gz
Size 54.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ad9b37711964ade102a9c7ec69fd7ea4df8241a50dcfc7ceb2c3833b09ed9e45
BLAKE2b-256 checksum
How to use checksums
af66f93376bafacd8634ec7f5977371570153a8a529f9b10d95e02c9346422ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.7

Release files / langchain_rezunate-0.1.0-py3-none-any.whl

Download URL langchain_rezunate-0.1.0-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c857953738571c471b50bc4730d10c1c4561ed9bbf75880e2caf1475fa801ac7
BLAKE2b-256 checksum
How to use checksums
c9638b1e00204b633a2ce4b70a9eaf412f65bb547b82bf131f07fbcb430798cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.7

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page