> ## Documentation Index
> Fetch the complete documentation index at: https://docs.laozhang.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# LangChain setup with LaoZhang API

> Use LaoZhang API from LangChain with ChatOpenAI and OpenAIEmbeddings: models, tool calls, streaming, the Responses API, and embeddings.

| Item | Details |
| - | - |
| Package | `langchain-openai` |
| `base_url` | `https://api.laozhang.ai/v1` |
| Chat models | `gpt-6-sol`, `gemini-3.8-flash`, `deepseek-v4-flash`, and others |
| Embedding models | `text-embedding-3-small` and others |
| Last verified | October 5, 2026, langchain-openai 1.6.7 |

## Install and configure

```bash theme={null}
pip install langchain-openai
export LAOZHANG_API_KEY="YOUR_LAOZHANG_API_KEY"
```

All the examples below read the key from that variable:

```python theme={null}
import os
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="gpt-6-sol",
    base_url="https://api.laozhang.ai/v1",
    api_key=os.environ["LAOZHANG_API_KEY"],
)

print(llm.invoke("Describe LangChain in one sentence").content)
```

To switch models, change only `model`, for example to `gemini-3.8-flash` or `deepseek-v4-flash`. Prices are in the [model catalog](/en/models).

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

```python theme={null}
from langchain_core.tools import tool


@tool
def get_weather(city: str) -> str:
    """Get the weather for a city."""
    return f"Sunny in {city}"


ai_message = llm.bind_tools([get_weather]).invoke("What's the weather in Paris? Use the tool.")
print(ai_message.tool_calls)
```

`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

```python theme={null}
for chunk in llm.stream("Count from 1 to 5"):
    print(chunk.content, end="", flush=True)
```

## Use the Responses API

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

```python theme={null}
llm = ChatOpenAI(
    model="gpt-6-sol",
    base_url="https://api.laozhang.ai/v1",
    api_key=os.environ["LAOZHANG_API_KEY"],
    use_responses_api=True,
)
print(llm.invoke("Describe the Responses API in one sentence").text)
```

## Create embeddings

```python theme={null}
from langchain_openai import OpenAIEmbeddings

embeddings = OpenAIEmbeddings(
    model="text-embedding-3-small",
    base_url="https://api.laozhang.ai/v1",
    api_key=os.environ["LAOZHANG_API_KEY"],
)
vectors = embeddings.embed_documents(["hello", "world"])
print(len(vectors), len(vectors[0]))  # 2 1536
```

Available embedding models and dimensions are in the [Embeddings API](/en/api-capabilities/text-embedding).

## FAQ

### I get "Unsupported parameter: 'max\_tokens'"

GPT-6 models don't accept `max_tokens`. Setting the output limit through `ChatOpenAI`'s own argument usually works; if you added that field by hand in extra request parameters, rename it to `max_completion_tokens`. See [max\_tokens](/en/faq/max-tokens).

### I get a 401 or 404

Make sure `base_url` is `https://api.laozhang.ai/v1` and isn't overridden by an environment variable such as `OPENAI_BASE_URL`. See [Invalid API key or 404](/en/faq/invalid-api-key).

## Related pages

* [Integrations overview](/en/scenarios)
* [Text generation API: protocols and models](/en/api-capabilities/text-generation)
* [LangChain OpenAI integration docs](https://python.langchain.com/docs/integrations/chat/openai/)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.