Skip to content

LangGraph

LangGraph has no model settings of its own: the graph calls whatever LangChain chat model you give it. Point that chat model at the gateway and every model call in the graph, each turn and each tool round trip, is checked against your policies, charged to the agent's team and recorded in Request logs.

What it is

The langgraph package for Python, with LangChain's create_agent for the common tool-calling agent. The model calls are made by a LangChain chat model (ChatOpenAI, ChatAnthropic or ChatGoogleGenerativeAI), so the settings are the ones on LangChain.

The two settings

Setting Environment variable (for ChatOpenAI) Constructor argument Value
Base address OPENAI_BASE_URL base_url https://<your-gateway>/v1
Key OPENAI_API_KEY api_key The agent's Vidai key (starts vk_), never a provider's key

For ChatAnthropic and ChatGoogleGenerativeAI, see the table on LangChain. Issue the key to the agent under Applications & agents (the agent's Keys section, Issue a key); its secret is shown once. The gateway's address is under Connect your app on the Keys page and in System › Settings › Gateway.

A minimal call

from langchain.agents import create_agent
from langchain_openai import ChatOpenAI

model = ChatOpenAI(model="claude-sonnet-4.5", base_url="https://<your-gateway>/v1", api_key="vk_…")
agent = create_agent(model=model, tools=[])
result = agent.invoke({"messages": [{"role": "user", "content": "Say hello in Dutch."}]})
print(result["messages"][-1].content)

create_agent replaces langgraph.prebuilt.create_react_agent from LangGraph 1.0. In your own graphs, call the same chat model inside a node. Any model name your key may call works, whichever chat model class you use: the gateway translates between the formats.

Streaming

for step in agent.stream({"messages": [{"role": "user", "content": "Count to five."}]}, stream_mode="updates"):
    print(step)

Use stream_mode="messages" for the model's tokens as they arrive. A stream from another provider reaches the chat model in its own format.

Tool calls

from langchain_core.tools import tool

@tool
def get_weather(city: str) -> str:
    """Weather for a city."""
    return f"Sunny in {city}"

agent = create_agent(model=model, tools=[get_weather])

Tool calling works on every provider the gateway translates to. Each loop of the agent is its own call, so one question can show as several calls in Request logs (filter Tool to see the ones that offered or called a tool).

Reading what the gateway did

The graph's state doesn't carry the response headers. Build the chat model with include_response_headers=True (ChatOpenAI only) and read them from an AI message's response_metadata["headers"], or find the calls in Request logs (filter Agent, Key or Model). See LangChain.

Errors

Errors come from the chat model, as described on LangChain: match on the x-vidai-error-code header. When the agent is suspended or its key is switched off, its calls get api_key_disabled with a short reason (for example agent_suspended); treat the list of reasons as open-ended.

Model names

Use the names your organisation approved under Models in the Control room, within the agent's own list of models. GET /v1/models on the gateway lists exactly the models the key may call.

What goes through the gateway

Feature Through the gateway
Every model call the graph makes, streaming, tools, structured output Yes, as for the chat model you use: see LangChain
Checkpoints, memory stores, LangSmith tracing No: they're your own storage or LangSmith, not model calls

Check it works in a minute

Run the minimal call above. A short answer means the address and key are right; the call shows under the agent in Request logs within seconds.

Good to know

  • Set the chat model's retries low (max_retries=0 on ChatOpenAI): a fallback chain may already have tried another model first, and a node's retry policy would add more on top.
  • The gateway's own 429 has no Retry-After header; back off on your side.