# LangChain setup

LangChain's `ChatOpenAI` class works with any OpenAI-compatible API. Set the base URL to Claudech and use a Claudech model id.

## Before you start

- **A Claudech API key** from [API keys](https://claudech.com/api-keys), stored as `CLAUDECH_API_KEY`. API access unlocks after your first purchase.

## Chat model

**Python**

```python
# pip install langchain-openai
import os
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="claude-opus-5-5",
    api_key=os.environ["CLAUDECH_API_KEY"],
    base_url="https://api.claudech.com/v1",
)
print(llm.invoke("Give me three names for a bakery.").content)
```

**JavaScript**

```javascript
// npm install @langchain/openai
import { ChatOpenAI } from '@langchain/openai';

const llm = new ChatOpenAI({
  model: 'claude-opus-5-5',
  apiKey: process.env.CLAUDECH_API_KEY,
  configuration: { baseURL: 'https://api.claudech.com/v1' },
});
const res = await llm.invoke('Give me three names for a bakery.');
console.log(res.content);
```

## Streaming

**Python**

```python
for chunk in llm.stream("Write a haiku about rivers."):
    print(chunk.content, end="", flush=True)
```

**JavaScript**

```javascript
for await (const chunk of await llm.stream('Write a haiku about rivers.')) {
  process.stdout.write(String(chunk.content));
}
```

## Tool calling

Every Claudech model supports tool calling, so `bind_tools` and LangChain agents work as they do with OpenAI:

```python
from langchain_core.tools import tool

@tool
def get_weather(city: str) -> str:
    """Return the current weather for a city."""
    return f"Sunny in {city}"

result = llm.bind_tools([get_weather]).invoke("What's the weather in Lisbon?")
print(result.tool_calls)
```

## Things to know

- **Embeddings.** Claudech does not offer an embeddings endpoint. For retrieval, use another provider's embeddings with a Claudech chat model.
- **Structured output.** `with_structured_output` works in JSON mode; validate the result, since `json_schema` is treated as `json_object`. See [compatibility notes](https://claudech.com/docs/sdks#compatibility-notes).

See [all integrations](https://claudech.com/docs/integrations) for other frameworks. Claudech is an independent service and is not affiliated with the makers of LangChain.

---

Source: https://claudech.com/docs/integrations/langchain
