Integrations
LangChain
Run LangChain chains and agents on your stack with the ChatOpenAI chat model, in Python or JavaScript.
LangChain is a framework for building chains and
agents on top of language models. Its ChatOpenAI chat model accepts a custom
base URL, so it runs on your stack without any Stac-specific package.
Prerequisites
- A key from your stack's API keys page, exported as
STAC_API_KEY. See Authentication. - The id of the model you want to call — see Models. The
examples below use
qwen/qwen3.5-9b.
export STAC_API_KEY="your-stac-api-key"Set up the chat model
Install the OpenAI integration
langchain-openaifor Python,@langchain/openaifor JavaScript.Pythonbashpip install langchain-openaiJavaScriptbashnpm install @langchain/openai @langchain/corePoint ChatOpenAI at Stac
Pass the key and the base URL explicitly. In Python they are
api_keyandbase_url; in JavaScript the base URL goes underconfiguration.Use it like any other chat model
Chains, agents and LangGraph graphs take the
llmobject as they would take an OpenAI one.
Example
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="qwen/qwen3.5-9b",
api_key=os.environ["STAC_API_KEY"],
base_url="https://api.trystac.com/v1",
)
print(llm.invoke("Name three primary colors.").content)import { ChatOpenAI } from "@langchain/openai";
const llm = new ChatOpenAI({
model: "qwen/qwen3.5-9b",
apiKey: process.env.STAC_API_KEY,
configuration: { baseURL: "https://api.trystac.com/v1" },
});
const response = await llm.invoke("Name three primary colors.");
console.log(response.content);Expected output (the wording varies from run to run):
Red, blue, and yellow.For long answers, stream instead of waiting for the whole message:
for chunk in llm.stream("Write a short paragraph about primary colors."):
print(chunk.content, end="", flush=True)Limitations
- The model id must be on your plan. Pass the exact value from
Models as
model; a model your key's plan doesn't include returns403. - Tools depend on the model.
bind_toolsand tool-calling agents only work with a model that supports tool calling. - Non-streaming calls have a time window.
invokewaits for the whole answer in one response; a generation that runs past roughly 90 seconds fails with503. Usestreamfor long outputs. - One completion per request,
logit_biasis dropped, and rate limits are per key — give each service its own key. See Differences that matter.
Next steps
- OpenAI compatibility — what
ChatOpenAIis talking to, and what differs from OpenAI. - Streaming responses — the SSE format behind
stream. - Knowledge base — ground answers in your own documents without a retriever in the chain.