> For the complete documentation index, see [llms.txt](https://docs.robinmesh.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.robinmesh.com/integrations/langchain.md).

# LangChain

Because the RobinMesh API follows the OpenAI wire format, LangChain's stock `ChatOpenAI` class talks to it out of the box. There is no RobinMesh-specific LangChain package to install, and none is needed.

***

## Python (LangChain)

```bash
pip install langchain-openai
```

```python
import os
from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage, SystemMessage

llm = ChatOpenAI(
    model="qwen3-8b",
    openai_api_base="https://api.robinmesh.com/v1",
    openai_api_key=os.environ["ROBINMESH_API_KEY"],
    temperature=0.7,
    max_tokens=1024,
    streaming=True
)

messages = [
    SystemMessage(content="You are a helpful assistant."),
    HumanMessage(content="Explain how optimistic rollups inherit Ethereum's security.")
]

response = llm.invoke(messages)
print(response.content)
```

### Streaming with LangChain

```python
from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage

llm = ChatOpenAI(
    model="llama-3.3-70b",
    openai_api_base="https://api.robinmesh.com/v1",
    openai_api_key=os.environ["ROBINMESH_API_KEY"],
    streaming=True
)

for chunk in llm.stream([HumanMessage(content="Write a short essay on decentralization.")]):
    print(chunk.content, end="", flush=True)
```

### LangChain Expression Language (LCEL)

```python
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser

llm = ChatOpenAI(
    model="qwen3-8b",
    openai_api_base="https://api.robinmesh.com/v1",
    openai_api_key=os.environ["ROBINMESH_API_KEY"]
)

prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a blockchain expert. Be concise."),
    ("human", "{question}")
])

chain = prompt | llm | StrOutputParser()

result = chain.invoke({"question": "What is the difference between an externally owned account and a smart contract?"})
print(result)
```

### RAG pipeline

```python
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnablePassthrough
from langchain_core.output_parsers import StrOutputParser

llm = ChatOpenAI(
    model="llama-3.3-70b",
    openai_api_base="https://api.robinmesh.com/v1",
    openai_api_key=os.environ["ROBINMESH_API_KEY"]
)

template = """Answer the question based on the following context.

Context:
{context}

Question:
{question}
"""

prompt = ChatPromptTemplate.from_template(template)

def format_docs(docs):
    return "\n\n".join(doc.page_content for doc in docs)

rag_chain = (
    {"context": retriever | format_docs, "question": RunnablePassthrough()}
    | prompt
    | llm
    | StrOutputParser()
)

response = rag_chain.invoke("How does the RobinMesh settlement contract verify proofs?")
print(response)
```

***

## JavaScript / TypeScript (LangChain)

```bash
npm install @langchain/openai
```

```typescript
import { ChatOpenAI } from "@langchain/openai"
import { HumanMessage, SystemMessage } from "@langchain/core/messages"

const llm = new ChatOpenAI({
    modelName: "qwen3-8b",
    configuration: {
        baseURL: "https://api.robinmesh.com/v1",
        apiKey: process.env.ROBINMESH_API_KEY
    },
    temperature: 0.7,
    streaming: true
})

const response = await llm.invoke([
    new SystemMessage("You are a concise assistant."),
    new HumanMessage("What is an ERC-4337 smart account?")
])

console.log(response.content)
```

### Streaming in TypeScript

```typescript
const stream = await llm.stream([
    new HumanMessage("Explain WebGPU and how it enables browser-based inference.")
])

for await (const chunk of stream) {
    process.stdout.write(chunk.content as string)
}
```

***

## Model options

The \[Models reference]\(

) lists every model ID the network serves. Pass any of them as LangChain's `modelName`:

```python
# Python
llm = ChatOpenAI(model="llama-3.3-70b", ...)  # 70B, the most capable option
llm = ChatOpenAI(model="qwen3-8b", ...)         # 8B, quick and inexpensive
llm = ChatOpenAI(model="deepseek-r1", ...)      # 70B, tuned for reasoning
llm = ChatOpenAI(model="mistral-7b", ...)       # 7B, the cheapest tier
```

***

## Known limitations with LangChain

**No tool calling yet.** During the beta, `bind_tools` and `with_structured_output` fail against RobinMesh models, since tool and function calling is a Phase 2 roadmap item.

**No embeddings yet.** Pipelines built on `OpenAIEmbeddings` need a different embeddings provider for now. Native RobinMesh embeddings are also slated for Phase 2.

**Mind the context window.** Every RobinMesh model has its own `context_window`, documented in the \[Models reference]\(

). LangChain will not trim your message history to fit, so long-running chains need to manage conversation length on their own.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.robinmesh.com/integrations/langchain.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
