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.
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 covers making one and adding credit. Model ids come from the catalogue.
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.
streamreturns 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-Keyif a retry being charged twice would matter. - Unverified models need
allow_unverifiedin 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.