Connect LangChain & LangGraph to byesu API
Connect LangChain and LangGraph (Python) to byesu via langchain-openai or langchain-anthropic to orchestrate multi-vendor tool-calling chains, structured output pipelines, and stateful ReAct agents with one pay-as-you-go API key.
Quick configuration
ChatOpenAI(langchain-openai)base_url:https://byesu.com/v1(all vendors under one class)ChatAnthropic(langchain-anthropic)anthropic_api_url:https://byesu.com(without/v1— native/v1/messages+0.1xcache reads)- Environment variable:
BYESU_API_KEY=sk-...(created in the defaultautogroup) - Recommended models:
gpt-6.2-sol,claude-opus-5-5,claude-sonnet-5-5,deepseek-v4-pro,gemini-4-argon
Prerequisites
- Generate an
sk-...token in the byesu Console under the defaultautogroup (see Choosing a Group). - Install the official partner packages:
pip install langchain-openai langchain-anthropic langgraph
export BYESU_API_KEY="sk-your-byesu-token"Option 1: langchain-openai (All Models via ChatOpenAI)
Use ChatOpenAI with base_url="https://byesu.com/v1" when you want a single interface that can hot-swap between GPT, Claude, DeepSeek, Gemini, and Grok model IDs:
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="gpt-6.2-sol", # or "claude-sonnet-5-5", "deepseek-v4-pro", "gemini-4-argon"
api_key=os.environ["BYESU_API_KEY"],
base_url="https://byesu.com/v1",
timeout=120,
)
resp = llm.invoke("Summarize three failure modes of distributed locks in bullet points.")
print(resp.content)For OpenAI /v1/responses features on gpt-6.2-sol or gpt-6.2-astra, pass use_responses_api=True on ChatOpenAI.
Option 2: langchain-anthropic (Native /v1/messages & 0.1x Caching)
For Claude-heavy agent graphs that benefit from native Anthropic tool blocks, adaptive thinking blocks, and cache_control breakpoints, use ChatAnthropic:
Root URL without /v1 in langchain-anthropic
ChatAnthropic wraps the official anthropic Python SDK, which appends /v1/messages automatically. Pass anthropic_api_url="https://byesu.com" without /v1 — adding /v1 hits /v1/v1/messages and returns 404.
import os
from langchain_anthropic import ChatAnthropic
from langchain_core.messages import HumanMessage, SystemMessage
claude = ChatAnthropic(
model="claude-opus-5-5",
api_key=os.environ["BYESU_API_KEY"],
anthropic_api_url="https://byesu.com",
timeout=120,
)
# Optional: mark a 1,024+ token static system prompt for 0.1x cache reads
messages = [
SystemMessage(
content=[
{
"type": "text",
"text": "You are a principal SRE reviewing Kubernetes manifests...",
"cache_control": {"type": "ephemeral"},
}
]
),
HumanMessage(content="Check whether PodDisruptionBudget minAvailable=1 blocks node drains on single-replica deployments."),
]
reply = claude.invoke(messages)
print(reply.content)
print("Usage metadata:", reply.usage_metadata)See Prompt Caching for prefix ordering rules that preserve 0.1x cache reads across agent iterations.
LangGraph ReAct Agent with @tool Binding
Both ChatOpenAI and ChatAnthropic plug directly into LangGraph's tool-calling workflows:
import os
from langchain_anthropic import ChatAnthropic
from langchain_core.tools import tool
from langgraph.prebuilt import create_react_agent
@tool
def get_queue_depth(queue_name: str) -> dict:
"""Return current backlog depth and oldest message age in seconds for a worker queue."""
return {"queue": queue_name, "pending_jobs": 1420, "oldest_age_sec": 94}
model = ChatAnthropic(
model="claude-sonnet-5-5",
api_key=os.environ["BYESU_API_KEY"],
anthropic_api_url="https://byesu.com",
timeout=120,
)
agent = create_react_agent(model, tools=[get_queue_depth])
result = agent.invoke(
{"messages": [("user", "Inspect the billing-webhooks queue and tell me if we should scale consumers.")]}
)
print(result["messages"][-1].content)Production Engineering Notes
- Do not hardcode
temperatureon Claude 5.5 (2026-10-21) or GPT-6.2 reasoning models: Many older LangChain examples passtemperature=0ortemperature=0.7. Anthropic API version2026-10-21rejectstemperature,top_p, andtop_kwith HTTP400, and GPT-6.2 reasoning models likewise reject fixed sampling overrides. Omittemperature(or passtemperature=Noneif an older wrapper sets a float default) — see Claude 400 temperature/top_p fix and unsupportedmax_tokens. - Timeouts for multi-step graphs: Keep
timeout=120(or higher) onChatOpenAI/ChatAnthropicand stream graph updates (agent.stream(..., stream_mode="values")) when invoking deep-reasoning models (gpt-6.2-sol,claude-opus-5-5,deepseek-v4-pro). - Token groups & billing: The default
autogroup covers Claude, GPT, Gemini, DeepSeek, and Grok. Issue separate tokens inGlm(glm-5.3),Kimi(kimi-k3), ormedia(gpt-image-2,gemini-3.1-flash-image-ultra) when needed. Usage is pay-as-you-go per token with live rates shown in the byesu Console after sign-in.
Troubleshooting & Benchmarks
401 authentication_error/invalid_api_key: verifybase_url="https://byesu.com/v1"onChatOpenAIvsanthropic_api_url="https://byesu.com"onChatAnthropic(OpenAI 401 fix, Claude 401 fix).404/no available channel: ensure themodelstring matches the console ID character for character and matches your token group (no available channel).- Timeouts or dropped streams: increase client
timeoutto>= 120s (Anthropic timeout, streaming connection dropped). 429& latency metrics: see OpenAI 429 rate limit vs quota and weekly production benchmarks.