BLACK FRIDAYUntil Dec 8 (Tue) 23:59 JSTUntil Dec 8

DocsLangChain

LangChain settings (ChatOpenAI, ChatAnthropic)

Settings for pointing ChatOpenAI and ChatAnthropic in LangChain (Python and TypeScript) to Echo Token Station.

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="claude-fable-5-1",
    base_url="https://token.echohub.io/v1",
    api_key=os.environ["ECHO_API_KEY"],
)

print(llm.invoke("What is the capital of Japan?").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-fable-5-1",
    base_url="https://token.echohub.io",
    api_key=os.environ["ECHO_API_KEY"],
    max_tokens=1024,
)

print(llm.invoke("What is the capital of Japan?").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 temporarily unavailableThe model ID is wrong, or Echo does not offer the modelCheck the model ID

The list of error bodies is in Errors and fixes.