Use with LangChain
LangChain chains and agents run through Otari with langchain-otari, whose ChatOtari is LangChain's ChatOpenAI pointed at Otari's OpenAI-compatible API (POST /api/v1/chat/completions). Every call then gets Otari's budgets, usage tracking, fallback routing and guardrails. For graphs, see Use with LangGraph.
Quick start
Install the package:
pip install langchain-otariCreate an API key at otari.ai and export it:
export OTARI_API_KEY=<your-otari-key>That is all the configuration otari.ai's gateway needs, once your organization there has credit or provider keys of its own; without either, it answers 402. For a gateway you run yourself, use a key it issued and also export its API root:
export OTARI_BASE_URL=http://localhost:8000/api/v1 # your gateway's URL plus /api/v1Then create the chat model:
from langchain_otari import ChatOtari
llm = ChatOtari(model="openai:gpt-4o")
print(llm.invoke("Say hello in one sentence.").content)Without OTARI_BASE_URL, requests go to otari.ai's gateway, https://api.otari.ai/api/v1. Accounts in otari.ai's EU region use https://eu.api.otari.ai/api/v1 instead: api.otari.ai answers an EU key with 421 Misdirected Request, naming the host to use. Set OTARI_BASE_URL to the EU host in that case. base_url and api_key arguments override both variables. ChatOtari never falls back to OPENAI_API_KEY, so an OpenAI key in your environment is not sent to the gateway by mistake, and it asks Otari for token usage on streams too.
ChatOtari takes every ChatOpenAI argument and works for every provider Otari routes to: Otari translates the Chat Completions request for Anthropic, Mistral, Gemini and the rest, so the same chain switches provider by changing only model. The names it accepts are listed under Choosing a model.
Agents and tools
create_agent runs the tool loop; every model call in it goes through Otari:
Structured output
Streaming
One key per project
Give each project (or each client) its own Otari key. Its usage and spend are then reported apart, a budget ceiling on the key caps that project alone, and revoking the key stops only that project. See Access control and Budgets and API keys in config.
Without the package
ChatOtari is a thin layer over ChatOpenAI, so the same thing works with langchain-openai alone:
See also
Use with LangGraph: the same model inside your own graph.
Last updated
Was this helpful?
