Skip to main content
LangChain calls LaoZhang API through langchain-openai: set the base URL to https://api.laozhang.ai/v1 and use your LaoZhang API key for both chat and embedding models.

Install and configure

All the examples below read the key from that variable:
To switch models, change only model, for example to gemini-3.8-flash or deepseek-v4-flash. Prices are in the model catalog. You can also set the OPENAI_API_KEY and OPENAI_BASE_URL environment variables and leave api_key and base_url out of your code.

Call tools

tool_calls returns the tool name and arguments, such as {'name': 'get_weather', 'args': {'city': 'Paris'}}. After running the tool, send the result back as a ToolMessage, or let a LangGraph agent handle the loop.

Stream the output

Use the Responses API

When you need features of OpenAI’s Responses API, add use_responses_api=True:

Create embeddings

Available embedding models and dimensions are in the Embeddings API.

FAQ

I get “Unsupported parameter: ‘max_tokens’”

Before November 4, 2026, GPT-6 models rejected max_tokens in Chat Completions; LaoZhang API now accepts it. If another model still returns this error, rename a hand-written max_tokens in extra request parameters to max_completion_tokens, or set the output limit through ChatOpenAI’s own argument. See max_tokens.

I get a 401 or 404

Make sure base_url is https://api.laozhang.ai/v1:
  • A base_url passed in code isn’t overridden by environment variables.
  • If you don’t pass one, OPENAI_API_BASE takes precedence over OPENAI_BASE_URL, so check both variables. See Invalid API key or 404.