> ## Documentation Index
> Fetch the complete documentation index at: https://runcrate.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# LangChain

> Use Runcrate's open models in LangChain and LangGraph with the langchain-runcrate package: chat, streaming, tool calling, structured output and agents

The [`langchain-runcrate`](https://pypi.org/project/langchain-runcrate/) package gives LangChain a `ChatRuncrate` chat model. It works with every chat model in Runcrate's [model catalog](https://runcrate.ai/docs/models/model-catalog.md) through the same OpenAI-compatible API, so chains, tools, structured output and LangGraph agents work as they do with any other LangChain chat model.

## Installation

```bash theme={"theme":{"light":"github-light","dark":"catppuccin-mocha"}}
pip install -U langchain-runcrate
```

Requires Python 3.10+ and LangChain 1.x (`langchain-core` and `langchain-openai` 1.x are installed with it).

Create an API key in the [Dashboard](https://www.runcrate.ai/dashboard/api-keys) ([how](https://runcrate.ai/docs/account/api-keys.md)) and export it:

```bash theme={"theme":{"light":"github-light","dark":"catppuccin-mocha"}}
export RUNCRATE_API_KEY="rc_live_..."
```

## Quick Start

```python theme={"theme":{"light":"github-light","dark":"catppuccin-mocha"}}
from langchain_runcrate import ChatRuncrate

llm = ChatRuncrate(model="deepseek-ai/DeepSeek-V3.2", temperature=0)

print(llm.invoke("Explain LoRA fine-tuning in one sentence.").content)
```

Any chat model id from [`GET /v1/models`](https://runcrate.ai/docs/models/model-catalog) works as `model`.

## Configuration

```python theme={"theme":{"light":"github-light","dark":"catppuccin-mocha"}}
from langchain_runcrate import ChatRuncrate

llm = ChatRuncrate(
    model="deepseek-ai/DeepSeek-V3.2",
    api_key="rc_live_...",                  # or the RUNCRATE_API_KEY env var
    base_url="https://api.runcrate.ai/v1",  # default; or the RUNCRATE_API_BASE env var
    temperature=0.2,
    max_tokens=1024,
)
```

`ChatRuncrate` extends LangChain's OpenAI chat model, so the usual settings (`temperature`, `max_tokens`, `timeout`, `max_retries`, `model_kwargs`) are available.

***

## Streaming

```python theme={"theme":{"light":"github-light","dark":"catppuccin-mocha"}}
for chunk in llm.stream("Write a haiku about GPUs."):
    print(chunk.text, end="", flush=True)
```

Async works the same way with `ainvoke` and `astream`.

## Tool calling

```python theme={"theme":{"light":"github-light","dark":"catppuccin-mocha"}}
from langchain_core.tools import tool


@tool
def gpu_price(gpu: str) -> str:
    """Return the hourly price of a GPU."""
    return "see https://www.runcrate.ai/api/gpu-pricing"


llm_with_tools = llm.bind_tools([gpu_price])
message = llm_with_tools.invoke("What does an H100 cost per hour?")
print(message.tool_calls)
```

Use a model that supports tool calling: in [`GET /v1/models`](https://api.runcrate.ai/v1/models), its `supported_features` includes `tools` (both models on this page do).

## Structured output

```python theme={"theme":{"light":"github-light","dark":"catppuccin-mocha"}}
from pydantic import BaseModel


class Summary(BaseModel):
    title: str
    bullets: list[str]


summary = llm.with_structured_output(Summary).invoke("Summarize what a GPU cloud is.")
print(summary.title, summary.bullets)
```

## Agents

`ChatRuncrate` drops into LangChain's `create_agent` and LangGraph like any other chat model:

```python theme={"theme":{"light":"github-light","dark":"catppuccin-mocha"}}
from langchain.agents import create_agent

agent = create_agent(
    ChatRuncrate(model="Qwen/Qwen3-235B-A22B-Instruct-2507"),
    tools=[gpu_price],
)
agent.invoke({"messages": [{"role": "user", "content": "Price an H100 for 10 hours."}]})
```

## Pricing

Requests are billed per token from your workspace balance, at the prices on [Inference pricing](https://www.runcrate.ai/inference/pricing). There is no separate LangChain plan.

## Links

* Package: [langchain-runcrate on PyPI](https://pypi.org/project/langchain-runcrate/)
* [Chat completions](https://runcrate.ai/docs/models/chat-completions.md): the API `ChatRuncrate` calls
* [Model catalog](https://runcrate.ai/docs/models/model-catalog.md): every model id you can pass


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.