LangChain
Use OP Inference from LangChain.
Use LangChain's OpenAI chat model with our base URL.
pip install langchain-openaiimport os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="openai/gpt-oss-120b",
base_url="https://api.opinference.com/v1",
api_key=os.environ["OP_API_KEY"],
)
print(llm.invoke("Say hello.").content)
for chunk in llm.stream("Count to three."):
print(chunk.content, end="")
print()invoke, stream, bind_tools and with_structured_output work as they do with OpenAI.
Our own fields
Pass provider and op through extra_body:
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="openai/gpt-oss-120b",
base_url="https://api.opinference.com/v1",
api_key=os.environ["OP_API_KEY"],
extra_body={"provider": {"sort": "price"}, "op": {"retention": "zdr"}},
)
print(llm.invoke("Say hello.").content)Not supported
OpenAIEmbeddings does not work: there is no embeddings route. Do not set
use_responses_api=True: the Responses API is not served. See
Not supported.