LangChain’s ChatOpenAI is OpenAI-compatible — point it at the Orbitrage
gateway and every call is routed and traced. Tools, managed tools, and streaming
all work unchanged.
Install
pip install -U orbitrage langchain langchain-openai
Basic chat
Wrapper clients build their own HTTP client, so set the base URL and key
explicitly, and pass your end-user id via default_headers.
import os, orbitrage
orbitrage.init(os.environ["ORBITRAGE_API_KEY"], user_id="customer_42")
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="claude-sonnet-4-6", # direct model — or "grok-4-fast"; "auto" to route
base_url="https://api.orbitrage.ai/v1",
api_key=os.environ["ORBITRAGE_API_KEY"],
default_headers={"x-orbitrage-end-user-id": "customer_42"},
max_tokens=512,
)
print(llm.invoke("Explain routing in one line.").content)
Reference a managed tool by name and Orbitrage runs it
server-side, then loops the result back to the model.
# bind passes the managed tool straight through to the API
out = llm.bind(tools=["calculator_orbitrage"]).invoke(
"Use the calculator to compute 1234*5678. Only the number."
)
print(out.content) # 7006652
Your own LangChain tools (@tool / bind_tools) keep working alongside managed
tools in the same call.
Streaming
for chunk in llm.stream("Count from 1 to 5."):
print(chunk.content, end="", flush=True)
Pin a direct model (claude-sonnet-4-6, grok-4-fast) for predictable
behavior. Use model="auto" to let Orbitrage pick the cheapest capable model —
and keep max_tokens ≥ 512 so reasoning models aren’t truncated.