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)
| Class | Format | Base URL |
|---|---|---|
ChatOpenAI | OpenAI format | https://token.echohub.io/v1 |
ChatAnthropic | Anthropic format | https://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)
# Create and activate a virtual environment
python3 -m venv .venv && source .venv/bin/activate
pip install -U langchain-openaiimport 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)npm install @langchain/openai @langchain/coreimport { ChatOpenAI } from "@langchain/openai";
const llm = new ChatOpenAI({
model: "deepseek-flash",
apiKey: process.env.ECHO_API_KEY,
configuration: {
baseURL: "https://token.echohub.io/v1",
},
});
const res = await llm.invoke("日本の首都はどこですか?");
console.log(res.content);ChatAnthropic (Anthropic format)
# Create and activate a virtual environment
python3 -m venv .venv && source .venv/bin/activate
pip install -U langchain-anthropicimport 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)npm install @langchain/anthropic @langchain/coreimport { ChatAnthropic } from "@langchain/anthropic";
const llm = new ChatAnthropic({
model: "claude-sonnet-5",
apiKey: process.env.ECHO_API_KEY,
maxTokens: 1024,
clientOptions: {
baseURL: "https://token.echohub.io",
},
});
const res = await llm.invoke("日本の首都はどこですか?");
console.log(res.content);Notes
- According to LangChain's official documentation,
ChatOpenAItargets only OpenAI's official specification. Response fields that are not in the OpenAI specification are not extracted - The TypeScript version of
ChatOpenAIsends a parameter calledstream_optionswhen streaming (receiving the answer piece by piece). LangChain's documentation says to setstreamUsage: falsefor services that do not accept this parameter. Echo accepts it, so you do not need this setting
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| 404 with an HTML page instead of JSON | The base URL of ChatOpenAI has no /v1 | Change it to https://token.echohub.io/v1 |
404 and Invalid URL (POST /v1/v1/messages) | The base URL of ChatAnthropic includes /v1 | Change it to https://token.echohub.io |
401 and Invalid API key | The key is wrong, stopped or expired, or has used up its spending limit | Check the key's status in the console |
403 and Insufficient balance | Insufficient balance | Top up |
503 and The model … does not exist or is not available | The model ID is wrong, or Echo does not offer the model | Check the model ID |
The list of error bodies is in Errors and fixes.
Sources
| What | Source | Checked |
|---|---|---|
base_url and api_key of ChatOpenAI, the note that it targets only OpenAI's official specification | https://docs.langchain.com/oss/python/integrations/chat/openai | 2026-09-26 |
base_url and api_key of ChatAnthropic | https://docs.langchain.com/oss/python/integrations/chat/anthropic | 2026-09-26 |
configuration.baseURL in TypeScript, the note on stream_options | https://docs.langchain.com/oss/javascript/integrations/chat/openai | 2026-09-26 |
clientOptions.baseURL in TypeScript | https://docs.langchain.com/oss/javascript/integrations/chat/anthropic | 2026-09-26 |
The Anthropic SDK adds /v1/messages after the base URL | https://github.com/anthropics/anthropic-sdk-python | 2026-09-26 |
Calls with ChatOpenAI and ChatAnthropic, tool calls, streaming, acceptance of stream_options, HTTP statuses and error bodies on Echo's side | Measured in Echo's test environment, with the same relay settings as production and a server that returns test responses in place of the upstream API | 2026-09-27 |