Skip to content

AI Gateway

LangChain

Connect Clipia AI Gateway to LangChain via ChatOpenAI with the Clipia base_url — chat, tool calling, agents and structured output 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-5",
    base_url="https://api.clipia.ai/v1",
    api_key=os.environ["CLIPIA_KEY"],
)

print(llm.invoke("Tell me three facts about Mars.").content)

If your code already uses ChatOpenAI

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 (pip install 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-5",
    base_url="https://api.clipia.ai/v1",
    api_key=os.environ["CLIPIA_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

For strict schema output, choose a model that supports response_format, such as GPT-6.1 Sol, and call with_structured_output with method="json_schema". Validate the result before using it:

from pydantic import BaseModel

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

structured_llm = ChatOpenAI(
    model="gpt-6.1-sol",
    base_url="https://api.clipia.ai/v1",
    api_key=os.environ["CLIPIA_KEY"],
)
structured = structured_llm.with_structured_output(Person, method="json_schema", strict=True)
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. Request long answers as a stream: a long-running non-streaming request can get a 504, and an automatic retry without an Idempotency-Key is billed again — see Timeouts and retries.