Skip to content
AI Gateway

LangChain

Connect Clipia AI Gateway to LangChain via ChatOpenAI with the Clipia base_url — chat, tools and tool agents on Claude, GPT and Gemini.

Clipia AI Gateway is OpenAI-contract compatible, so it plugs into LangChain through the standard ChatOpenAI class — just point it at our base_url with a Clipia key. From there, all the usual LangChain features work: chat, tools, agents and structured output.

Initialization

pip install langchain-openai
import os
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="claude-opus-5",
    base_url="https://api.clipia.ai/v1",
    api_key=os.environ["CLIPIA_API_KEY"],
    temperature=0.7,
)

print(llm.invoke("Tell me three facts about Mars.").content)
npm install @langchain/openai @langchain/core
import { ChatOpenAI } from "@langchain/openai";

const llm = new ChatOpenAI({
  model: "claude-opus-5",
  apiKey: process.env.CLIPIA_API_KEY,
  configuration: { baseURL: "https://api.clipia.ai/v1" },
  temperature: 0.7,
});

const res = await llm.invoke("Tell me three facts about Mars.");
console.log(res.content);

One parameter to switch provider

If you already have ChatOpenAI code, switching over just means setting base_url (configuration.baseURL in Node.js) and a Clipia key. The model field is a string from the catalog.

Tool agent

Bind tools via bind_tools, or assemble a ready-made ReAct agent with langgraph. Example with a single function tool:

import os
from langchain_openai import ChatOpenAI
from langchain_core.tools import tool
from langgraph.prebuilt import create_react_agent

@tool
def get_weather(city: str) -> str:
    """Return the current weather in a city."""
    return f"In {city}: 14°C, cloudy"

llm = ChatOpenAI(
    model="claude-opus-5",
    base_url="https://api.clipia.ai/v1",
    api_key=os.environ["CLIPIA_API_KEY"],
)

agent = create_react_agent(llm, tools=[get_weather])

result = agent.invoke(
    {"messages": [{"role": "user", "content": "What's the weather in Moscow?"}]}
)
print(result["messages"][-1].content)

The agent runs the full loop on its own: requests a tool call, gets the result and produces the final answer.

Structured output

with_structured_output uses response_format under the hood — the model returns data strictly matching the schema (a Pydantic model or a JSON schema):

from pydantic import BaseModel

class Person(BaseModel):
    name: str
    age: int

structured = llm.with_structured_output(Person)
person = structured.invoke("Extract name and age: Anna is 30.")
print(person.name, person.age)  # Anna 30

Streaming

Streaming is available via llm.stream(...) (Python) and await llm.stream(...) (Node.js) — the gateway emits SSE chunks in OpenAI format. More on streaming and tools on the Chat Completions page.