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.
bash
export STAC_API_KEY="your-stac-api-key"

Set up the chat model

  1. Install the OpenAI integration

    langchain-openai for Python, @langchain/openai for JavaScript.

    Pythonbash
    pip install langchain-openai
    JavaScriptbash
    npm install @langchain/openai @langchain/core
  2. Point ChatOpenAI at Stac

    Pass the key and the base URL explicitly. In Python they are api_key and base_url; in JavaScript the base URL goes under configuration.

  3. Use it like any other chat model

    Chains, agents and LangGraph graphs take the llm object as they would take an OpenAI one.

Example

main.pypython
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)

Expected output (the wording varies from run to run):

Red, blue, and yellow.

For long answers, stream instead of waiting for the whole message:

python
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 returns 403.
  • Tools depend on the model. bind_tools and tool-calling agents only work with a model that supports tool calling.
  • Non-streaming calls have a time window. invoke waits for the whole answer in one response; a generation that runs past roughly 90 seconds fails with 503. Use stream for long outputs.
  • One completion per request, logit_bias is dropped, and rate limits are per key — give each service its own key. See Differences that matter.

Next steps