[Works with](https://autarcho.com/works-with/)

# Use LangChain with Autarcho

The OpenAI chat model in `langchain-openai` accepts a base URL, so every chain, tool and callback built on it works against this endpoint.

[Open the chat](https://chat.autarcho.com) [Make a key first](https://autarcho.com/start/)

## The change

Pass `base_url` to the chat model and use a model id from the catalogue.

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

model = ChatOpenAI(
    model="lfm2-1.2b-extract@1.0",
    base_url="https://api.autarcho.com/v1",
    api_key="ak_...",
    temperature=0.7,
)

for chunk in model.stream("Name three uses for a small model."):
    print(chunk.content, end="")
```

A key is `ak_` followed by 64 hex characters, made on your own machine; the [start page](https://autarcho.com/start/) covers making one and adding credit. Model ids come from [the catalogue](https://autarcho.com/models/).

## What works

- Chains, prompt templates, structured output and callbacks: they sit above the client and never see the address.
- Tool calling works, including on models that were not trained for it, because the call is constrained by a grammar built from your tool schema.
- `stream` returns token by token, so the first token arrives before the answer is finished.

## What to watch

- A model id is an alias or a 64-hex hash. A model nobody has loaded has to be fetched on the first request, which can take minutes for a multi-gigabyte file.
- LangChain retries some errors by default. Send `Idempotency-Key` if a retry being charged twice would matter.
- Unverified models need `allow_unverified` in the request; the listing shows which ones those are.

The full list of what is refused, what is charged and what a retry costs is on [the API reference](https://autarcho.com/docs/api/).

[What a request costs](https://autarcho.com/pricing/) [Other clients](https://autarcho.com/works-with/)
