DocsLangChain

LangChain

Settings for using Echo Token Station models from LangChain (Python and TypeScript).

LangChain is a library for building apps that use AI models. You replace the base URL with Echo in LangChain's OpenAI and Anthropic classes.

Tested: calls with ChatOpenAI and ChatAnthropic, tool calls and streaming in the Python (1.x) and TypeScript versions of LangChain (2026-09-27, Echo's test environment)

ClassFormatBase URL
ChatOpenAIOpenAI formathttps://token.echohub.io/v1
ChatAnthropicAnthropic formathttps://token.echohub.io (without /v1)

Use ChatAnthropic for Claude models and ChatOpenAI for the others, and each model is called in its provider's own format. Notes on calling a model in a format different from its provider's are in "Formats and models" in the API reference.

Put your API key in the environment variable ECHO_API_KEY (see the Quickstart).

ChatOpenAI (OpenAI format)

bash
# Create and activate a virtual environment
python3 -m venv .venv && source .venv/bin/activate
pip install -U langchain-openai
Python
import os
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="deepseek-flash",
    base_url="https://token.echohub.io/v1",
    api_key=os.environ["ECHO_API_KEY"],
)

print(llm.invoke("日本の首都はどこですか?").content)

ChatAnthropic (Anthropic format)

bash
# Create and activate a virtual environment
python3 -m venv .venv && source .venv/bin/activate
pip install -U langchain-anthropic
Python
import os
from langchain_anthropic import ChatAnthropic

llm = ChatAnthropic(
    model="claude-sonnet-5",
    base_url="https://token.echohub.io",
    api_key=os.environ["ECHO_API_KEY"],
    max_tokens=1024,
)

print(llm.invoke("日本の首都はどこですか?").content)

Notes

  • According to LangChain's official documentation, ChatOpenAI targets only OpenAI's official specification. Response fields that are not in the OpenAI specification are not extracted
  • The TypeScript version of ChatOpenAI sends a parameter called stream_options when streaming (receiving the answer piece by piece). LangChain's documentation says to set streamUsage: false for services that do not accept this parameter. Echo accepts it, so you do not need this setting

Troubleshooting

SymptomCauseFix
404 with an HTML page instead of JSONThe base URL of ChatOpenAI has no /v1Change it to https://token.echohub.io/v1
404 and Invalid URL (POST /v1/v1/messages)The base URL of ChatAnthropic includes /v1Change it to https://token.echohub.io
401 and Invalid API keyThe key is wrong, stopped or expired, or has used up its spending limitCheck the key's status in the console
403 and Insufficient balanceInsufficient balanceTop up
503 and The model … does not exist or is not availableThe model ID is wrong, or Echo does not offer the modelCheck the model ID

The list of error bodies is in Errors and fixes.

Sources

WhatSourceChecked
base_url and api_key of ChatOpenAI, the note that it targets only OpenAI's official specificationhttps://docs.langchain.com/oss/python/integrations/chat/openai2026-09-26
base_url and api_key of ChatAnthropichttps://docs.langchain.com/oss/python/integrations/chat/anthropic2026-09-26
configuration.baseURL in TypeScript, the note on stream_optionshttps://docs.langchain.com/oss/javascript/integrations/chat/openai2026-09-26
clientOptions.baseURL in TypeScripthttps://docs.langchain.com/oss/javascript/integrations/chat/anthropic2026-09-26
The Anthropic SDK adds /v1/messages after the base URLhttps://github.com/anthropics/anthropic-sdk-python2026-09-26
Calls with ChatOpenAI and ChatAnthropic, tool calls, streaming, acceptance of stream_options, HTTP statuses and error bodies on Echo's sideMeasured in Echo's test environment, with the same relay settings as production and a server that returns test responses in place of the upstream API2026-09-27