LangChain
LangChain’s OpenAI integration works with TOKEN once the base URL points to
https://api.thetoken.dev/v1.
Chat models
Section titled “Chat models”pip install langchain-openaiimport osfrom langchain_openai import ChatOpenAI
llm = ChatOpenAI( model="zai-org/glm-5.3", base_url="https://api.thetoken.dev/v1", api_key=os.environ["TOKEN_API_KEY"], max_tokens=4096,)
print(llm.invoke("Explain retries with backoff in two sentences.").content)npm install @langchain/openai @langchain/coreimport { ChatOpenAI } from '@langchain/openai'
const llm = new ChatOpenAI({ model: 'zai-org/glm-5.3', apiKey: process.env.TOKEN_API_KEY, configuration: { baseURL: 'https://api.thetoken.dev/v1' }, maxTokens: 4096,})
const reply = await llm.invoke('Explain retries with backoff in two sentences.')console.log(reply.content)Streaming (llm.stream(...)), tool binding (llm.bind_tools(...) /
llm.bindTools(...)) and structured output (with_structured_output /
withStructuredOutput) work on models that support them; check the
models page before choosing one. meta-llama/llama-4-maverick
has no tool calling.
Embeddings
Section titled “Embeddings”import osfrom langchain_openai import OpenAIEmbeddings
embeddings = OpenAIEmbeddings( model="baai/bge-m3", base_url="https://api.thetoken.dev/v1", api_key=os.environ["TOKEN_API_KEY"], check_embedding_ctx_length=False,)
vector = embeddings.embed_query("Where is my order?")print(len(vector)) # 1024import { OpenAIEmbeddings } from '@langchain/openai'
const embeddings = new OpenAIEmbeddings({ model: 'baai/bge-m3', apiKey: process.env.TOKEN_API_KEY, configuration: { baseURL: 'https://api.thetoken.dev/v1' },})
const vector = await embeddings.embedQuery('Where is my order?')console.log(vector.length) // 1024In Python, check_embedding_ctx_length=False makes LangChain send the text
itself. Without it, LangChain splits the text with OpenAI’s tokenizer and
sends token numbers, which only OpenAI’s own embedding models understand.