Skip to content
Need an API key for this client? One token for Claude, GPT-6.2, Gemini 4 & DeepSeek V4 — top up via USDT or Alipay

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.1x cache reads)
  • Environment variable: BYESU_API_KEY=sk-... (created in the default auto group)
  • Recommended models: gpt-6.2-sol, claude-opus-5-5, claude-sonnet-5-5, deepseek-v4-pro, gemini-4-argon

Prerequisites ​

  1. Generate an sk-... token in the byesu Console under the default auto group (see Choosing a Group).
  2. Install the official partner packages:
bash
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:

python
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.

python
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:

python
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 temperature on Claude 5.5 (2026-10-21) or GPT-6.2 reasoning models: Many older LangChain examples pass temperature=0 or temperature=0.7. Anthropic API version 2026-10-21 rejects temperature, top_p, and top_k with HTTP 400, and GPT-6.2 reasoning models likewise reject fixed sampling overrides. Omit temperature (or pass temperature=None if an older wrapper sets a float default) — see Claude 400 temperature/top_p fix and unsupported max_tokens.
  • Timeouts for multi-step graphs: Keep timeout=120 (or higher) on ChatOpenAI / ChatAnthropic and 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 auto group covers Claude, GPT, Gemini, DeepSeek, and Grok. Issue separate tokens in Glm (glm-5.3), Kimi (kimi-k3), or media (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 ​

Got a problem? Contact support or join our group.