Use LangChain with TokenMaster

Use ChatOpenAI from langchain-openai with TokenMaster's base URL — chains, agents and tools work as usual.

You will need

  • An API key starting with tm- (Console → API keys) — Get an API key
  • Base URL: https://tokenmaster.store/v1
  • A model ID, e.g. deepseek/deepseek-v4-pro (see the model list)

Setup

  1. Install the package: pip install -U langchain-openai.
  2. Create the model with base_url, your key and a TokenMaster model ID. Set use_responses_api=False (recommended) so LangChain stays on Chat Completions, TokenMaster's most complete protocol.
import os
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="deepseek/deepseek-v4-pro",
    base_url="https://tokenmaster.store/v1",
    api_key=os.environ["TOKENMASTER_API_KEY"],
    use_responses_api=False,
    stream_usage=True,
)
print(llm.invoke("Explain vector databases in one sentence.").content)

Good to know

  • You can also set OPENAI_BASE_URL and OPENAI_API_KEY as environment variables. For embeddings use OpenAIEmbeddings(model="baai/bge-m3", base_url=..., api_key=..., check_embedding_ctx_length=False) — the last option makes LangChain send text instead of token IDs.
  • Not available through TokenMaster: image generation, speech, rerank, the Assistants API, and OpenAI-hosted tools. Chat Completions, the Responses API (stateless), the Anthropic Messages API and embeddings are available.

Checked against LangChain langchain-openai 1.7 on 2026-10-19. Menu names can change between versions.

Troubleshooting

  • 401 / invalid API key — check the key was copied in full and has not been deleted in the console.
  • 404 — the base URL is wrong. It must end in /v1 unless the guide says otherwise.
  • Model not found / not available — use the exact ID from the model list (vendor/model, lowercase). Some vendors are not available in every region.
  • Errors mentioning /responses — the tool is using OpenAI's Responses API. TokenMaster accepts it, but statelessly (no previous_response_id) and without OpenAI-hosted tools; if the tool relies on those, switch it to Chat Completions as noted above.
  • 402 / insufficient balance — top up in the console; requests are refused rather than run up a debt.

SDKs & frameworks

All integration guides → · All model prices →