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

# LangChain

LangChain's stock `ChatOpenAI` class talks to RobinCompute out of the box, because the API follows the OpenAI wire format. There is no RobinCompute LangChain package to install. There doesn't need to be. Change one line, keep your chains.

***

## 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.robincompute.org/v1",
    openai_api_key=os.environ["ROBINCOMPUTE_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.robincompute.org/v1",
    openai_api_key=os.environ["ROBINCOMPUTE_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.robincompute.org/v1",
    openai_api_key=os.environ["ROBINCOMPUTE_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.robincompute.org/v1",
    openai_api_key=os.environ["ROBINCOMPUTE_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 RobinCompute 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.robincompute.org/v1",
        apiKey: process.env.ROBINCOMPUTE_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

Every model ID the network serves is listed in the \[Models reference]\(

). Any of them works 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.** `bind_tools` and `with_structured_output` fail against RobinCompute models during the beta. Tool and function calling is a Phase 2 roadmap item; beta means early, not unfinished.

**No embeddings yet.** Pipelines built on `OpenAIEmbeddings` need another embeddings provider for now. Native RobinCompute embeddings land in Phase 2 as well.

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

). LangChain will not trim message history to fit. Long-running chains manage conversation length themselves.


---

# 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.robincompute.org/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.
