Integrations · Verified · langchain-openai 1.8.5
LangChain with Unbound
LangChain is a Python library for building things on top of language models. This one is for people writing code, but the first run is short: install one package, save one file, run it.
Step by step
Every step below was run with VS Code 1.147 with langchain-openai 1.8.5 on 24 November 2026: the script, a streamed answer and the spend on Unbound.
- Open my API keys
Step 1: Create your Unbound key
Open your API keys page. Type a name such as LangChain, add a spending limit if you want one, and click Create key.
Real screenshotUnbound AI, local development buildClick to enlarge Step 2: Copy the key
Click Copy. The key is shown only this once, so keep the page open until you have pasted it in the next steps.
Real screenshotUnbound AI, local development buildClick to enlarge Treat the key like a password. Anyone who has it can spend your credits.
Step 3: Install the package
Open a terminal in your project folder (in VS Code: Terminal → New Terminal) and run this.
Nothing different on Windows: follow the step as written.
pip install langchain-openaiReal screenshotVS Code 1.147 with langchain-openai 1.8.5Click to enlarge Step 4: Create hello.py
Make a new file named
hello.py, paste this in, and replaceub_paste-your-key-herewith your key.hello.pyfrom langchain_openai import ChatOpenAI llm = ChatOpenAI( model="<model-id>", base_url="https://api.useunbound.ai/v1", api_key="ub_paste-your-key-here", ) for chunk in llm.stream("Say hello in five words"): print(chunk.content, end="", flush=True)Real screenshotVS Code 1.147 with langchain-openai 1.8.5Click to enlarge AdvancedKeep the key out of the file
For anything you will share or commit, read the key from the environment instead.
pythonimport os llm = ChatOpenAI( model="<model-id>", base_url="https://api.useunbound.ai/v1", api_key=os.environ["UNBOUND_API_KEY"], )Step 5: Run it
In the terminal, run the file. The answer prints piece by piece as it arrives.
Nothing different on Windows: follow the step as written.
python hello.pyReal screenshotVS Code 1.147 with langchain-openai 1.8.5Click to enlarge - Open my API keys
Step 6: Check it on Unbound
Go back to your API keys page. Spent and Last used change after every request, so you can see the connection working and what it costs.
Real screenshotUnbound AI, local development buildClick to enlarge
Advanced
Terminal commands and file details. You do not need any of this to follow the steps above.
OpenChains, token usage and non-streaming calls
The same llm object works everywhere LangChain accepts a chat model. llm.invoke(...) returns the whole answer at once, and response.usage_metadata carries the token counts Unbound billed.
from langchain_core.prompts import ChatPromptTemplate
prompt = ChatPromptTemplate.from_messages([("system", "Answer in one sentence."), ("user", "{question}")])
chain = prompt | llm
response = chain.invoke({"question": "What is a vector database?"})
print(response.content)
print(response.usage_metadata)OpenLangChain.js
In JavaScript the class is ChatOpenAI from @langchain/openai, and the address goes under configuration.baseURL. We have not run the JavaScript package ourselves.
import { ChatOpenAI } from "@langchain/openai";
const llm = new ChatOpenAI({
model: "<model-id>",
apiKey: process.env.UNBOUND_API_KEY,
configuration: { baseURL: "https://api.useunbound.ai/v1" },
});If something goes wrong
ModuleNotFoundError: No module named langchain_openai
The package went into a different Python than the one running the file. Install and run with the same command family: pip with python, or pip3 with python3.
The model was not found
The model value must be an id from the models page, written exactly.
It says the API key is invalid or unauthorized
The key was pasted incompletely or has been revoked. Create a new one on your API keys page and paste it again. Keys start with ub_.
It stops with a message about credits or a spending limit
Your balance is empty or the key reached its own limit. The API keys page shows what each key has spent next to its limit.
What we tested
Checked on November 24, 2026. “Verified” covers what is listed here and nothing more.
Worked
- langchain-openai 1.8.5 on Python, Windows 11: invoke, streaming, token usage and a prompt chain.
- The script in this guide, run in the VS Code terminal.
- Usage billing: the requests appeared under the key on Unbound with their cost.
Not tested
- LangChain.js.
- Tool calling and agents through LangChain.
- A live model. The checks ran against Unbound’s simulated development model.