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, stored as CLAUDECH_API_KEY. API access unlocks after your first purchase.

Chat model#

# 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)

Streaming#

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

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.

See all integrations for other frameworks. Claudech is an independent service and is not affiliated with the makers of LangChain.