Use Nivana in LangChain

LangChain’s ChatOpenAI works with any OpenAI-compatible API. Give it Nivana’s base URL and key and every call is routed.

What you need

  • A Nivana API key: sign in, open the account menu and choose API keys. New accounts get 2,000 free credits.
  • The base URL https://nivana.one/v1 and the model name nivana/auto (or nivana/quality, nivana/speed, nivana/cost to lean the router one way).

Set up LangChain

from langchain_openai import ChatOpenAI
import os

llm = ChatOpenAI(model="nivana/auto", base_url="https://nivana.one/v1", api_key=os.environ["NIVANA_API_KEY"])
print(llm.invoke("Name three uses for a router.").content)

Chains, bind_tools and agents work as they are: tool calls come back in the standard OpenAI shape.

Limits

Tool calling works: the client’s tools are passed to the routed model, which can call them, and each step is routed on its own. JSON mode and sampling parameters (temperature, max tokens) are ignored, Nivana’s own web search is off when the client sends tools, and very long tool histories are not summarised, so a request larger than every model’s context window fails.

Every response’s model field names the model that actually answered. See the OpenAI-compatible endpoint and how routing works.