Skip to content
AZRouter.dev

Guides

LangChain

Use AZRouter with LangChain's ChatOpenAI.

Tested: langchain-openai with langchain-core 1.6.11 (Python 3.13), 2026-10-16

LangChain's ChatOpenAI takes a base URL, so AZRouter works without a separate integration.

Shell
pip install langchain-openai
Python
import os
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="qwen/qwen3.8-flash",
    base_url="https://api.azrouter.dev/v1",
    api_key=os.environ["AZROUTER_API_KEY"],
    max_tokens=200,
)

reply = llm.invoke("Reply with exactly: Hello from AZRouter")
print(reply.content)
print(reply.usage_metadata)

Streaming

Python
for chunk in llm.stream("Reply with exactly: Hello from AZRouter"):
    print(chunk.content, end="", flush=True)
print()